Skip to content

Instantly share code, notes, and snippets.

@SocalNick
SocalNick / di.create-definitions.php
Created June 26, 2012 16:13
ZF2 Di definition compiler
<?php
// in ZF2 project, place this in ./bin directory
chdir(dirname(__DIR__));
$zf2Path = (getenv('ZF2_PATH') ?: 'vendor/ZendFramework/library');
require_once $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
require_once $zf2Path . '/Zend/Loader/StandardAutoloader.php';
use Zend\Loader\AutoloaderFactory;
use Zend\Loader\StandardAutoloader;
@SocalNick
SocalNick / example-21.php
Created April 24, 2012 23:55
Bug in Zend\Cache or Zend\EventManager
<?php
namespace {
require_once 'ZendFramework/library/Zend/Loader/StandardAutoloader.php';
$autoloader = new \Zend\Loader\StandardAutoloader;
spl_autoload_register(array($autoloader, 'autoload'));
$di = new Zend\Di\Di;
$di->configure(
new Zend\Di\Configuration(
array(
@SocalNick
SocalNick / Action.php
Created April 12, 2012 22:35
Action View Helper
<?php
/**
* IGN Application Module
*
* @category Application
* @package Application_View
* @copyright Copyright (c) 2006-2011 IGN Entertainment, Inc. (http://corp.ign.com/)
*/
namespace Application\View\Helper;
@SocalNick
SocalNick / AcceptRoutingStrategy.php
Created April 11, 2012 21:27
Ign Custom View Strategy
<?php
namespace Ign\View\Strategy;
use Zend\EventManager\EventCollection,
Zend\EventManager\ListenerAggregate,
Zend\Feed\Writer\Feed,
Zend\Mvc\MvcEvent,
Zend\View\Renderer\FeedRenderer,
Zend\View\Renderer\JsonRenderer,
Zend\View\Renderer\PhpRenderer,
@SocalNick
SocalNick / application.config.php
Created April 5, 2012 21:18
ZF2 App Config with Composer
<?php
return
array(
'modules' => array(
'Application',
),
'module_listener_options' => array(
'config_cache_enabled' => true,
'cache_dir' => 'data/cache',
'config_cache_key' => 'app-cache-key',
@SocalNick
SocalNick / CacheControlParser-symfony.php
Created March 27, 2012 16:50
Symfony's Cache-Control header parser
<?php
function parseCacheControl($header)
{
$cacheControl = array();
preg_match_all('#([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?#', $header, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$cacheControl[strtolower($match[1])] = isset($match[2]) && $match[2] ? $match[2] : (isset($match[3]) ? $match[3] : true);
}
return $cacheControl;
@SocalNick
SocalNick / parser.php
Created March 27, 2012 16:35 — forked from jtai/parser.php
Nick's Cache-Control header parser
<?php
function parse($string)
{
$string = trim($string);
$directives = array();
// handle empty string early so we don't need a separate start state
if ($string == '') {
return $directives;
@SocalNick
SocalNick / CacheControlParser.php
Created March 27, 2012 03:21
Jon's Cache-Control header parser
<?php
function parseValue($value)
{
$directives = array();
$lastPosition = 0;
$array = str_split($value);
while (false !== ($token = tokenizer($value, $array, ', ', $lastPosition))) {
$directive = explode('=', trim($token));
if (false === $directive) {
throw new Exception('Invalid header line for Cache-Control string: "' . $value . '"');
@SocalNick
SocalNick / example-20.php
Created March 19, 2012 16:38
Can't declare injection method in base class
<?php
namespace Application {
abstract class Page {
public $blocks;
public function addBlock(Block $block){
$this->blocks[] = $block;
}
}
class FancyPage extends Page{
@SocalNick
SocalNick / module.config.php
Created March 16, 2012 21:39
Instantiating Zend Cache Adapter using Factory through Di
<?php
return array(
'di' => array(
'definition' => array(
'class' => array(
'Zend\Cache\StorageFactory' => array(
'methods' => array(
'factory' => array(
'cfg' => array(
'required' => true,