Présentation
{ "require": { "silex/silex": "1.0.*" }, "minimum-stability": "dev" }
<?php // fichier web/demo1.php $loader = require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); $app['debug'] = true; // definitions $app->get('/hello/{name}', function ($name) { return 'hello ' . $name; }) ->assert('name', '[a-z]*') ->value('name', 'world'); $app->run();
<?php // fichier web/demo1.php $loader = require_once __DIR__.'/../bootstrap.php'; $app = new Silex\Application(); $app['debug'] = true; // sample for using monolog (dont' forget to install file with composer) $app->register(new Silex\Provider\MonologServiceProvider(), array( 'monolog.logfile' => __DIR__.'/../logs/development.log', )); // definitions $app->mount('/hello', new PeaksTuto\HelloControllerProvider); $app->run();
<?php $loader = require_once __DIR__.'/vendor/autoload.php'; // add your namespaces $prefixList = require_once __DIR__.'/kernel.php'; // load your controller for each namespace loaded by kernel if (count($prefixList) > 0) { foreach ($prefixList as $prefixName => $prefixSrc) { $loader->add($prefixName, $prefixSrc); } unset($prefixName, $prefixSrc); } $app = new Silex\Application();
<?php $prefixList = array( 'PeaksTuto' => __DIR__.'/src', ); return $prefixList;
<?php namespace PeaksTuto; use Silex\Application; use Silex\ControllerProviderInterface; class HelloControllerProvider implements ControllerProviderInterface { public function connect(Application $app) { $controllers = $app['controllers_factory']; // route will depend on mount name in index file : might be /hello/{name} but may also be /whatIWant/{name} $controllers->get('/{name}', function ($name) use ($app) { $app['monolog']->addInfo(sprintf("name selected is %s", $name)); return 'hello ' . $name; }) ->assert('name', '[a-z]*') ->value('name', 'world'); return $controllers; } }
php composer.phar create-project symfony/framework-standard-edition www/sf 2.1.6
php app/check.php
php console clear:cache --env=prod
php app/console generate:bundle
Peaks/DemoBundle
puis modifier le routing.yml pour changer le prefix : /peaks
videz votre cache ;-)
"require": {
"php": ">=5.4.0",
"rebolon/pager-bundle": "dev-master"
}
$this->get('NomDuService');
// fichier services.xml de votre bundle <parameters> <parameter key="rebolon_pager.pager.class">Rebolon\Bundle\Pager\Pager</parameter> </parameters> <services> <service id="rebolon_pager.pager" class="%rebolon_pager.pager.class%"> <call method="setContainer"> <argument type="service" id="service_container" /> </call> <call method="setSuffixName"> <argument>%rebolon_pager.suffixname%</argument> </call> ...
<?php use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Config\Loader\LoaderInterface; class AppKernel extends Kernel { public function registerBundles() { $bundles = array(... , new Rebolon\Bundle\Pager\RebolonPagerBundle(),
$dispatcher = new EventDispatcher();
$dispatcher->addListener('event.name', callable[, priority]);
$dispatcher->dispatch('event.name');
$stopwatch = new Stopwatch();
$stopwatch->start('eventName');
$event = $stopwatch->stop('eventName');
$event->getDuration();
$event->getMemory();
... Et plein d'autres choses
$process = new Process('ls -lsa');
$process->setTimeout(3600);
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
print $process->getOutput();
$finder = new Finder();
$finder->files()->in('src/Symfony/*/*/Resources')
->name('smiley*')->size('< 100K')->date('since 1 hour ago');
foreach ($finder->files() as $file) {
print $file->getFilename()."\n"; // SplFileInfo $file
}
// vous avez besoin d'une classe
class MyShellCommand extends Command
// et de 2 méthodes protected function configure() // pour setter les parametres, et le help protected function execute(InputInterface $input, OutputInterface $output)