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 / OAuth2PdoAdapter.php
Created October 9, 2014 20:30
Example of a custom ZF\OAuth2 PdoAdapter implementation.
<?php
namespace MyLib;
use ZF\OAuth2\Adapter\PdoAdapter;
class OAuth2PdoAdapter extends PdoAdapter
{
protected $mapper;
public function setUsersMapper(Users\MapperInterface $mapper)
@weierophinney
weierophinney / rpc-hal-entity.php
Created September 25, 2014 14:06
One way to return a HAL entity from an Apigility RPC controller.
<?php
public function someAction()
{
$data = doSomeWorkFetchSomeData();
$entity = new \ZF\Hal\Entity($data, $data['id']); // or similar
return new \ZF\ContentNegotiation\ViewModel([
'payload' => $entity,
]);
}
@weierophinney
weierophinney / OAuth2PdoAdapterFactory.php
Created August 5, 2014 20:13
Example of pulling a PDO connection from an existing ZF2 DB adapter in order to seed a ZF\OAuth2\Adapter\PdoAdapter instance.
<?php
use ZF\OAuth2\Adapter\PdoAdapter;
class OAuth2PdoAdapterFactory
{
public function __invoke($services)
{
$db = $services->get('DB\MyDbName');
if (! $db instanceof Adapter) {
@weierophinney
weierophinney / TableGatewayFeaturesDelegatorFactory.php
Last active August 29, 2015 14:01
delegator for injecting TableGateway features into TableGateways created as part of the Apigility DB-Connected functionality.
<?php
use Zend\Db\TableGateway\Feature;
use Zend\ServiceManager\DelegatorFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class TableGatewayFeaturesDelegatorFactory implements DelegatorFactoryInterface
{
public function createDelegatorWithName(
ServiceLocatorInterface $services,
@weierophinney
weierophinney / Module.php
Created May 7, 2014 20:13
Returning early if a specific HTTP header is missing
<?php
namespace SomeApi;
use ZF\ApiProblem\ApiProblem;
use ZF\ApiProblem\ApiProblemResponse;
class Module
{
public function onBootstrap($e)
{
@weierophinney
weierophinney / composer.json
Created April 23, 2014 18:38
Adding apigility deps to an existing repo
{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"homepage": "http://framework.zend.com/",
"require": {

Keybase proof

I hereby claim:

  • I am weierophinney on github.
  • I am mwop (https://keybase.io/mwop) on keybase.
  • I have a public key whose fingerprint is 8D98 47CD E15F 050B 8197 6BA7 B545 7969 23ED 29DA

To claim this, I am signing this object:

@weierophinney
weierophinney / Module.php
Last active June 17, 2016 09:11
404 listener in ZF2
<?php
class Module
{
public function onBootstrap($e)
{
$app = $e->getApplication();
$events = $app->getEventManager();
// Direct instantiation
$events->attach(new RouteNotFoundListener());
@weierophinney
weierophinney / SoapController.php
Created February 12, 2014 16:46
Example of creating a SOAP controller for handling both WSDL and SOAP requests in ZF2.
<?php
namespace Soap\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Soap\AutoDiscover as SoapWsdlGenerator;
use Zend\Soap\Server as SoapServer;
class SoapController
{
@weierophinney
weierophinney / rtut.zsh
Created February 11, 2014 20:17
PHPUnit test runner using inotifywait
#!/bin/zsh
#
# Copyright (c) 2014, Joshua Thijssen
# Copyright (c) 2014, Matthew Weier O'Phinney
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.