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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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=@% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require "vendor/autoload.php"; | |
class MyClass | |
{ | |
public function __construct($a = 1) | |
{ | |
echo "__construct called \$a = $a\n"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Demo { | |
require __DIR__."/vendor/autoload.php"; | |
use Nocarrier\Hal; | |
class Resource extends Hal {} | |
class ResourceResponse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Demo\Controller; | |
use Silex\ControllerResolver as BaseControllerResolver; | |
use Symfony\Component\HttpFoundation\Request; | |
class ControllerResolver extends BaseControllerResolver | |
{ | |
/** |