Skip to content

Instantly share code, notes, and snippets.

View weierophinney's full-sized avatar
⏯️

Matthew Weier O'Phinney weierophinney

⏯️
View GitHub Profile
<?php
namespace Custom\View\Strategy;
use Zend\EventManager\EventCollection,
Zend\EventManager\ListenerAggregate,
Zend\Http\Request as HttpRequest,
Zend\Http\Response as HttpResponse,
Zend\View\Model,
Zend\View\Renderer\JsonRenderer,
Zend\View\ViewEvent;
@weierophinney
weierophinney / Listener.php
Created March 16, 2012 19:40
A way to mark a view model as terminal, and thus skip the layout
<?php
/**
* A listener attached as such:
* $app->events()->attach('route', $listener, -100);
*/
public function onRouteComplete($e)
{
$routeMatch = $e->getRouteMatch();
if (!$routeMatch) {
@weierophinney
weierophinney / application.config.php
Created March 29, 2012 21:10
Proposed bootstrap for ZF2
<?php
return array(
'modules' => array(
'Application',
/* ... */
),
'module_listeners' => array(
'use_defaults' => true, /* false to disable them */
/* list additional module listeners to use here */
@weierophinney
weierophinney / instance-manager-ideas.php
Created April 9, 2012 21:27
Ideas for the zf2 instance manager
<?php
// Use case 1:
// Providing additional constructor arguments
$im->composeService('foo', $myservice);
class MyService extends ComposedServiceFactory
{
public function __invoke($im, $name)
@weierophinney
weierophinney / ArrayTranslator.php
Created July 3, 2012 21:39
Test code for i18n-aware validators
<?php
namespace ZendTest\Validator\TestAsset;
use Zend\I18n\Translator;
class ArrayTranslator implements Translator\Loader\LoaderInterface
{
public $translations;
@weierophinney
weierophinney / replace-uses.php
Created July 9, 2012 21:49
Script used to do mass import statement fixes in ZF2
<?php
echo "Analyzing {$argv[1]}\n";
$file = file_get_contents($argv[1]);
$matches = null;
preg_match('/\n(use .*?)(?:\r?\n(?:\/\*|interface|abstract|class|trait))/s', $file, $matches);
if (!$matches || !$matches[1]) {
echo " Did not match initial pattern\n";
exit(0);
}
// echo " Matches: " . var_export($matches, 1) . "\n";
@weierophinney
weierophinney / test.php
Created July 11, 2012 19:34 — forked from prolic/test.php
performance test on different isSubclassOf implementations
<?php
// our test cases
interface A {}
class B implements A {}
class C extends B {}
class D {}
@weierophinney
weierophinney / composer.json
Created August 3, 2012 14:24
ZF2 RC2 composer demonstration
{
"minimum-stability": "dev",
"repositories": [
{
"type": "composer",
"url": "http://packages.zendframework.com/"
}
],
"require": {
"zendframework/zend-permissions-acl": "*",
@weierophinney
weierophinney / factory.php
Created August 29, 2012 14:04
Example factory
<?php
$factory = function ($controllers) {
$services = $controllers->getServiceLocator();
$config = $services->get('Config');
$moduleConfig = $config['my_module_key'];
$controller = new Controller\SomeController();
$controller->setSomeConfigInfo($moduleConfig['some_config_info']);
return $controller;
};
@weierophinney
weierophinney / listener.php
Created August 29, 2012 19:54
Example of triggering another dispatch event in ZF2
<?php
use Zend\Mvc\Router\RouteMatch;
// Listener on dispatch.error event
$listener = function ($e) {
$app = $e->getTarget();
$events = $app->getEventManager();
$event = clone $e;
$matches = new RouteMatch(array('controller' => 'Some\Controller\Alias'));
$event->setRouteMatch($matches);