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
@davedevelopment
davedevelopment / gist:3273991
Created August 6, 2012 12:09
Run a whole feature or nearest scenario in vim
" Run behat features
function! RunFeature(...)
" Are we in a feature file?
let in_feature_file = match(expand("%"), '.feature$') != -1
let run_nearest_scenario = a:0
if in_feature_file
" if so, store the path for later
let t:dm_feature_file=@%
@davedevelopment
davedevelopment / gist:3701011
Created September 11, 2012 19:06
Migrating passwords to Symfony's Password encoder
<?php
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder as SyMessageDigestPasswordEncoder;
/**
* Used to allow for use of existing passwords that were just sha1 in the db,
*/
class Sha1MessageDigestPasswordEncoder extends SyMessageDigestPasswordEncoder
{
public function encodePassword($raw, $salt)
/**
* The Application(which is an instance of Pimple) sets up it's required dependencies, one of which is a logger
*/
$this['logger'] = null;
/** snip */
/**
* The controller resolver takes an optional logger
*/
<?php
require "vendor/autoload.php";
class MyClass
{
public function __construct($a = 1)
{
echo "__construct called \$a = $a\n";
@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
@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));
<?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 / 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
namespace Demo\Controller;
use Silex\ControllerResolver as BaseControllerResolver;
use Symfony\Component\HttpFoundation\Request;
class ControllerResolver extends BaseControllerResolver
{
/**
@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.