Skip to content

Instantly share code, notes, and snippets.

View weierophinney's full-sized avatar
⏯️

Matthew Weier O'Phinney weierophinney

⏯️
View GitHub Profile
@weierophinney
weierophinney / listener.php
Created August 29, 2012 19:59
Another way to re-trigger a dispatch cycle
<?php
use Zend\Mvc\Router\RouteMatch;
// A listener on dispatch.error, for instance.
$listener = function ($e) {
$app = $e->getTarget();
$sm = $app->getServiceManager();
$dispatch = $sm->get('DispatchListener');
$event = clone $e;
$routeMatch = new RouteMatch(array('controller' => 'Some\Controller\Alias'));
@weierophinney
weierophinney / composer.json
Created August 31, 2012 19:42
autoload a module via composer
{
"autoload": {
"psr-0": {
"Application": "module/Application/src"
}
}
}
@weierophinney
weierophinney / annotation.php
Created September 6, 2012 18:11
annotation for radio element
<?php
use Zend\Form\Annotation;
class Foo
{
/**
* @Annotation\Type("Zend\Form\Element\Radio")
* @Annotation\Options({"label": "Your Choice:", "value_options":{"foo":"bar", "bar":"baz"}})
*/
@weierophinney
weierophinney / zf2-workflow.txt
Created September 14, 2012 20:01
proposed workflow
We rename "master" to "develop"
We rename "release" to "master"
Thus "master" stays the default branch, which means most PRs will be made
against it.
Bugfixes are merged to:
- master
- develop
Features are merged to:
- develop
When develop looks like the next minor or major version:
@weierophinney
weierophinney / AbstractControllerFactory.php
Created September 25, 2012 18:45
Abstract controller factory
namespace My\Api\V1;
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class AbstractControllerFactory implements AbstractFactoryInterface
{
protected $allowedControllers = array(
'user',
'group',
@weierophinney
weierophinney / module.config.php
Created September 25, 2012 18:52
Alternate config
<?php
return array(
'router' => array('routes' => array(
'api' => array(
'type' => 'Segment',
'options' => array(
'route' => '/api/v1/:controller[/:id]',
'defaults' => array(
'__NAMESPACE__' => 'Api\V1\Controller',
'controller' => 'User', // just an example
@weierophinney
weierophinney / Module.php
Created September 25, 2012 19:00
Change controller name via listener
<?php
namespace My;
class Module
{
public function onBootstrap($e)
{
$events = $e->getTarget()->getEventManager();
$events->attach('route', array($this, 'onRoutePost'), -100);
== RESTful Services Made Easy with ZF2 ==
Need a web service? Befuddled by WSDL? Does the lack of object support in
XML-RPC limit what you can do? Do you want to use your service with JavaScript?
Would you like to rely on native browser and client caching of your services?
REST is an alternative, capable of addressing all of these needs.
During this tutorial, we'll look at various aspects of REST, including proper
use of HTTP methods, the usage of media types, approaches to content
negotiation, and hyperlinking -- all the pieces necessary to build a good
@weierophinney
weierophinney / helper.php
Created October 29, 2012 13:54
static helper
<?php
abstract class Helper
{
public static function createHash(Paste $paste, PasteService $service)
{
$seed = $paste->language . $paste->timestamp . $paste->content;
do {
$seed . = uniqid();
$hash = hash('sha1', $seed);
} while ($service->exists($hash));
<?php
namespace My;
class Module
{
public function getServiceConfig()
{
return array(
'initializers' => array(
function ($instance, $services) {