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 / UserCollection.php
Created June 5, 2018 18:53
Example of casting an array of entities to a collection
<?php
namespace App\Entity;
use ArrayIterator;
class UserCollection extends ArrayIterator
{
}
@weierophinney
weierophinney / index.html
Created May 31, 2018 22:31
Prototype for auto-populating the component dropdown and making it searchable.
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Choices example</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
@weierophinney
weierophinney / changelog_generator.php
Created July 2, 2013 21:10
This is a version of the script I use to generate changelogs for my projects.
<?php
/**
* composer.json:
* {
* "require": {
* "zendframework/zend-http": "2.*"
* }
* }
*/
require __DIR__ . '/vendor/autoload.php';
@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 / RemoveDevPrefixMiddleware.php
Created September 14, 2017 19:23
Demonstrates stripping a path prefix prior to routing.
<?php
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ServerRequestInterface;
class RemoveDevPrefixMiddleware implements MiddlewareInterface
{
private $prefix;
@weierophinney
weierophinney / Module.php
Created August 17, 2017 20:02
Demonstrates a zend-mvc listener that short-circuits, and how to register it
<?php
// In a module class somewhere...
use Zend\EventManager\LazyListener;
use Zend\Mvc\MvcEvent;
class Module
{
public function onBootstrap(MvcEvent $e)
{

[Expressive] RFC: Programmatic pipelines

When we originally created the API for Expressive, it was programmatic:

We had pipelines:

$pipeline->pipe($loggingMiddleware);
$pipeline->pipe($serverUrlHelperMiddleware);
$pipeline-&gt;pipeRoutingMiddleware();
@weierophinney
weierophinney / QueryController.php
Created November 18, 2014 21:44
Example of embedding multiple collections in a HAL payload within Apigility.
<?php
/* We'll assume that all of the above classes are defined.
*
* We'll assume that Api\V1\Rpc\Query\QueryController will handle an RPC service
* call to /search?s=thing. It needs to be configured such that it responds to
* GET requests, and Content Negotiation is set to HalJson.
*
* This is what it will look like:
*/

[RFC] zend-expressive-router (and related) changes for Expressive 1.1.

Proposed zend-expressive-router changes include:

  • Adding a $path parameter to RouteResult::fromRouteMatch().

    What if instead we were to add a new static method, RouteResult::fromRoute(), and a new instance method, RouteResult::getRoute()? (as I have suggested in zendframework/zend-expressive#398)? This would allow consumers to then pull the path from the Route instead, and provide access to the path, name, allowed methods, options, etc. (e.g., $result->getRoute()->getPath())

    This could even be done in a new 1.3.0 minor release; users who depend on that new feature would need to update their project to pin to the new minor release or later; otherwise, everything continues working as normal.

@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)