Skip to content

Instantly share code, notes, and snippets.

View Saeven's full-sized avatar

Alexandre Lemaire Saeven

View GitHub Profile
@Saeven
Saeven / gist:da7a1a085da381589401
Created October 24, 2014 14:28
Dynamically Substitute template in ZF2
$eventManager->attach( MvcEvent::EVENT_DISPATCH, function( MvcEvent $e ){
$route_name = 'something';
$new_template = 'something-else';
if( $e->getRouteMatch() && $e->getRouteMatch()->getMatchedRouteName() == $route_name )
$e->getViewModel()->setTemplate( $new_template );
});
@Saeven
Saeven / ZF 2.4 PHPUnit Bootstrap
Created April 6, 2015 21:27
Lets you use your application config as though you were in-app.
<?php
namespace ApplicationTest;
use Zend\Loader\AutoloaderFactory;
use Zend\Mvc\Service\ServiceManagerConfig;
use Zend\ServiceManager\ServiceManager;
use RuntimeException;
error_reporting(E_ALL | E_STRICT);
/**
* Class UserFormFactory
* @package CirclicalUser\Factory\Form
*/
class UserFormFactory implements FactoryInterface, MutableCreationOptionsInterface
{
/**
* @var array
*/
@Saeven
Saeven / Bootstrap.php
Last active August 29, 2015 14:24
Adjusted Bootstrap for ZF 2.5 that goes straight to zend-loader rather than the old autoloader factory path.
protected static function initAutoloader()
{
$vendorPath = static::findParentPath('vendor');
if (file_exists($vendorPath . '/autoload.php')) {
include $vendorPath . '/autoload.php';
}
include $vendorPath . '/zendframework/zend-loader/src/AutoloaderFactory.php';
AutoloaderFactory::factory(array(
@Saeven
Saeven / PHP Mcrypt AES-256
Created January 11, 2016 18:14
AES-256 should not be confused with Rijndael-256.
<?php
class Foo
{
const COOKIE_KEY = '839914B48AE583605F004C784FEF155B39A2C142AD7A747582160E6C14E7EF16';
const COOKIE_IV = '864C9BB8032792391B88C76CF73276F2';
public function encrypt( $what )
{
@Saeven
Saeven / AbstractControllerFactory.php
Created March 9, 2016 20:28
Abstract controller factory test, to help the migration to zend-mvc 2.7.1 that removes the service locator entirely.
namespace Application\Factory\Controller;
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class AbstractControllerFactory implements AbstractFactoryInterface
{
/**
* Determine if we can create a service with name
@Saeven
Saeven / LazyControllerFactory.php
Last active April 11, 2016 20:45
Lazy controller factory that auto-injects dependencies based on controller params.
<?php
class LazyControllerFactory implements AbstractFactoryInterface
{
/**
* Determine if we can create a service with name
*
* @param ServiceLocatorInterface $serviceLocator
* @param $name
@Saeven
Saeven / saeven.lua
Last active June 16, 2022 14:50
Hammerspoon script to launch and tile apps
local workApplications = { 'Mail','HipChat','PhpStorm','Safari','Charles'}
local workApplicationWatcher;
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "H", function()
hs.notify.new({title="Hammerspoon", informativeText="Setting home layout"}):send()
local homeMonitor = "LG ULTRAWIDE"
local windowLayout = {
{"PhpStorm", nil, homeMonitor, {x=0, y=0, w=0.6, h=1}, nil, nil},
{"Charles", nil, homeMonitor, {x=0.6, y=0.6, w=0.4, h=0.4}, nil, nil},
@Saeven
Saeven / # php70 - 2016-09-26_21-45-45.txt
Created September 27, 2016 01:53
php70 (josegonzalez/php/php70) on macOS 10.11.6 - Homebrew build logs
Homebrew build logs for josegonzalez/php/php70 on macOS 10.11.6
Build date: 2016-09-26 21:45:45
@Saeven
Saeven / doctrine_memcached.php
Last active February 25, 2017 05:09
Doctrine & Memcached
<?php
/*
* Typical database config
*/
// ....
'doctrine' => [