Skip to content

Instantly share code, notes, and snippets.

View davedevelopment's full-sized avatar
😬
I may be slow to respond.

Dave Marshall davedevelopment

😬
I may be slow to respond.
View GitHub Profile
#!/usr/bin/env php
<?php
$app = require __DIR__ . '/../app/bootstrap.php';
$routes = $app['routes']->all();
$data = array();
foreach($routes as $route) {
<?php
/**
* Ideas for parameter converters
*
* I've used the word argument here rather than convert or converter,
* because there may not be any converting as such. It may be that things are
* plucked out of the request etc
*
* The idea being that some of the controller arguments come from the url,
@davedevelopment
davedevelopment / RussianDependencyRoulettePimple.php
Created January 7, 2013 15:42
RussianDependencyRoulettePimple
<?php
class RussianDependencyRoulettePimple extends Pimple
{
public function offsetGet($id)
{
return parent::offsetGet(reset(shuffle($this->keys())));
}
}
@davedevelopment
davedevelopment / controllers_as_services.rst
Last active December 10, 2015 14:38
Controllers as a Service as a Decorator

How to define Controllers as Services

As your Silex application grows, you may wish to begin organizing your controllers in a more formal fashion. Silex can use controller classes out of the box, but with a bit of work, your controllers can be created as services, giving you the full power of dependency injection and lazy loading.

<?php
namespace Demo\Controller;
use Silex\ControllerResolver as BaseControllerResolver;
use Symfony\Component\HttpFoundation\Request;
class ControllerResolver extends BaseControllerResolver
{
/**
@davedevelopment
davedevelopment / build.sh
Created December 14, 2012 22:25 — forked from igorw/build.sh
#!/bin/bash
# Amazing static site generator
# Works for PHP and HTML sites
# Assumes web root to be in /web
# Dumps the site into a directory named "static"
#
# rm -rf static/*; seq 1 4 | time parallel -j 4 ./build.sh 900{}
PORT=${1:-9999}
<?php
// Service Provider
$app->register(new Via\Content\ContentServiceProvider());
// Route
$app->get('/{id}', function($id) use ($app) {
return $app['content.id_checker']->check($id);
});
// and in .... ContentServiceProvider
@davedevelopment
davedevelopment / app_bootstrap.php
Created November 26, 2012 23:45
Silex Route Helpers
<?php
use Silex\Application;
use Demo\Entity\Post;
use Demo\Controller\PostController;
$app = new Application;
$app['route_class'] = 'CustomRoute';
$app['dispatcher']->addSubscriber(new TemplateRenderingListener($app));
@davedevelopment
davedevelopment / index.php
Created November 13, 2012 16:36
Tinkering with a Hal resource DTO, separating the framework from the app and content negotiation
<?php
namespace Demo {
require __DIR__."/vendor/autoload.php";
use Nocarrier\Hal;
class Resource extends Hal {}
class ResourceResponse
<?php
require "vendor/autoload.php";
class MyClass
{
public function __construct($a = 1)
{
echo "__construct called \$a = $a\n";