/** * {@inheritDoc} */ public function register(Application $app) { $app['bing_wallpaper'] = $app->share(function (Application $app) { $app->flush(); return new BingWallpaper(); }); }
public function register(Application $app) { $app['url_generator'] = $app->share(function () use($app) { $app->flush(); return new UrlGenerator($app['routes'], $app['request_context']); }); }
/** * {@inheritdoc} * * @param \Silex\Application $app * * @return void */ public function register(Application $app) { $app['url_generator'] = $app->share(function ($app) { $app->flush(); return $app['routers']; }); }
/** * {@inheritDoc} */ public function register(Application $app) { $app['slugify'] = $app->share(function (Application $app) { $app->flush(); return new Slugify(); }); }
public function register(Application $app) { $app['sync_zmq'] = $app->share(function (Application $app) { $app->flush(); return new \ZMQContext(); }); }
public function register(Application $app) { $app['request_api'] = $app->share(function (Application $app) { $app->flush(); return new RequestApi($app['sync_zmq']); }); }
public function register(\Silex\Application $app) { $app['url_generator'] = $app->share(function ($app) { $app->flush(); return new services\UrlGenerator($app['routes'], $app['request_context']); }); }
/** * {@inheritdoc} */ public function register(Application $app) { $app['url_generator'] = $app->share(function ($app) { $app->flush(); $configuration = array('preserve' => isset($app['url_generator.preserve']) ? $app['url_generator.preserve'] : array(), 'token' => isset($app['url_generator.token']) ? $app['url_generator.token'] : false, 'token_len' => isset($app['url_generator.token_length']) ? $app['url_generator.token_length'] : false); return new EnhancedUrlGenerator($app['routes'], $app['request_context'], $app['request'], $configuration); }); }
/** * @param RequestContext $context * * @return SilexRouter */ protected function getRouter(RequestContext $context) { $app = new Application(); $app->register(new RoutingServiceProvider()); $app->get('/hello', 'test')->bind('hello1'); $app->get('/hello2', 'test')->bind('hello2'); $app->flush(); $app['request_context'] = $context; return new SilexRouter($app); }
/** * {@inheritdoc} */ public function setUp() { $app = new SilexApplication(); $app->register(new ConsoleServiceProvider(), ['console.name' => 'Awesome name', 'console.version' => '1.2.3', 'console.request' => ['host' => 'example.com', 'scheme' => 'https', 'httpsPort' => 443, 'url' => 'hello']]); $app->register(new TwigServiceProvider(), ['twig.path' => __DIR__ . '/Resources/views', 'twig.options' => ['cache' => false]]); $app->get('/test.html', function () { return ''; })->bind('test'); $app->flush(); $this->console = $app['console']; }
public function register(Application $app) { $configFile = $this->configFile; //configuration $app['dump_provider.config'] = $app->share(function ($app) use($configFile) { $app->flush(); $config = Yaml::parse($configFile); $config = new Configuration($config); return $config; }); // dumper-registry $app['dump_provider.dumper_registry'] = $app->share(function ($app) { $app->flush(); $registry = new DumperRegistry($app['dump_provider.config']); return $registry; }); $app['dump_provider.dump_repository'] = $app->share(function ($app) { $app->flush(); $repository = new DumpRepository($app['dump_provider.config'], $app['url_generator']); return $repository; }); }
public function testBind() { $app = new Application(); $app->get('/', function () { return 'hello'; })->bind('homepage'); $app->get('/foo', function () { return 'foo'; })->bind('foo_abc'); $app->flush(); $routes = $app['routes']; $this->assertInstanceOf('Symfony\\Component\\Routing\\Route', $routes->get('homepage')); $this->assertInstanceOf('Symfony\\Component\\Routing\\Route', $routes->get('foo_abc')); }
public function testGetRoutesWithRoutes() { $app = new Application(); $app->get('/foo', function () { return 'foo'; }); $app->get('/bar', function () { return 'bar'; }); $routes = $app['routes']; $this->assertInstanceOf('Symfony\\Component\\Routing\\RouteCollection', $routes); $this->assertEquals(0, count($routes->all())); $app->flush(); $this->assertEquals(2, count($routes->all())); }
public function register(Application $app) { // Options if (!isset($app['router.resource'])) { $app['router.resource'] = null; } if (!isset($app['router.cache_dir'])) { $app['router.cache_dir'] = null; } // Router $app['router'] = $app->share(function () use($app) { $options = array('cache_dir' => $app['router.cache_dir'], 'debug' => $app['debug']); return new Router($app['router.loader'], $app['router.resource'], $options, $app['request_context'], $app['logger']); }); // Annotation loader $app['router.annotation.loader'] = $app->share(function () use($app) { $reader = $app['doctrine.common.annotation_reader']; return new AnnotatedRouteControllerLoader($reader); }); $app['router.file.locator'] = $app->share(function () { return new FileLocator(); }); $app['router.loader'] = $app->share(function () use($app) { return new AnnotationDirectoryLoader($app['router.file.locator'], $app['router.annotation.loader']); }); // Override matcher and generator. $app['url_matcher'] = $app->share(function () use($app) { /** @var $router Router */ $router = $app['router']; $matcher = $router->getMatcher(); if ($matcher instanceof UrlMatcherDecorator) { // Important to set routes by link. On security service does not working. $matcher->setRoutes($app['routes']); } return $matcher; }); $app['url_generator'] = $app->share(function () use($app) { $app->flush(); /** @var $router Router */ $router = $app['router']; $generator = $router->getGenerator(); if ($generator instanceof UrlGeneratorDecorator) { // Important to set routes by link. On security service does not working. $generator->setRoutes($app['routes']); } return $generator; }); }
/** * (non-PHPdoc) * @see \Silex\ServiceProviderInterface::boot() */ public function boot(Application $app) { $app->flush(); /* @var $routes \Symfony\Component\Routing\RouteCollection */ $routes = $app['routes']; /* @var $route \Silex\Route */ foreach ($routes->getIterator() as $id => $route) { $path = $route->getPath(); $headers = implode(',', ['Authorization', 'Accept', 'X-Request-With', 'Content-Type', 'X-Session-Token', 'X-Hmac-Hash', 'X-Time', 'X-Url']); /* @var $controller \Silex\Controller */ $controller = $app->match($path, function () use($headers) { return new Response(null, 204, ["Allow" => "GET,POST,PUT,DELETE", "Access-Control-Max-Age" => 84600, "Access-Control-Allow-Origin" => "*", "Access-Control-Allow-Credentials" => "false", "Access-Control-Allow-Methods" => "GET,POST,PUT,DELETE", "Access-Control-Allow-Headers" => $headers]); }); $controller->method('OPTIONS'); /* @var $controllerRoute \Silex\Route */ $controllerRoute = $controller->getRoute(); $controllerRoute->setCondition($route->getCondition()); $controllerRoute->setSchemes($route->getSchemes()); $controllerRoute->setMethods('OPTIONS'); } }
public function boot(Application $app) { // Add OPTIONS method support for all routes $app->flush(); $allow = array(); foreach ($app["routes"] as $route) { $path = $route->getPath(); if (!array_key_exists($path, $allow)) { $allow[$path] = array("methods" => array(), "requirements" => array()); } $allow[$path]["methods"] = array_merge($allow[$path]["methods"], $route->getMethods()); $allow[$path]["requirements"] = array_merge($allow[$path]["requirements"], $route->getRequirements()); } foreach ($allow as $path => $routeDetails) { $methods = $routeDetails["methods"]; $controller = $app->match($path, function () use($methods) { return new Response("", 204, array("Allow" => implode(",", $methods))); })->method('OPTIONS'); unset($routeDetails["requirements"]["_method"]); $controller->setRequirements($routeDetails["requirements"]); } }
public function testMountCallable() { $app = new Application(); $app->mount('/prefix', function (ControllerCollection $coll) { $coll->get('/path'); }); $app->flush(); $this->assertEquals(1, $app['routes']->count()); }
public function testMountPreservesOrder() { $app = new Application(); $mounted = new ControllerCollection(new Route()); $mounted->get('/mounted')->bind('second'); $app->get('/before')->bind('first'); $app->mount('/', $mounted); $app->get('/after')->bind('third'); $app->flush(); $this->assertEquals(array('first', 'second', 'third'), array_keys(iterator_to_array($app['routes']))); }
/** * {@inheritDoc} */ public function boot(Application $app) { $app->flush(); $this->createOptionsRoutes($app); }
public function testFakeRoutesAreSerializable() { $app = new Application(); $app->register(new SecurityServiceProvider(), array('security.firewalls' => array('admin' => array('logout' => true)))); $app->boot(); $app->flush(); $this->assertCount(1, unserialize(serialize($app['routes']))); }
/** * Add OPTIONS method support for all routes * * @param Application $app */ public function boot(Application $app) { $app->flush(); // This seems to be necessary sometimes. I'm not sure why. $this->createOptionsRoutes($app, $this->determineAllowedMethods($app["routes"])); }
<?php use Mparaiso\Provider\ConsoleServiceProvider; use Silex\Application; $autoload = (require __DIR__ . '/../vendor/autoload.php'); $autoload->add("", __DIR__ . '/../lib'); $autoload->add("", __DIR__ . '/lib'); $app = new Application(array('debug' => true)); $app->register(new ConsoleServiceProvider()); $app->register(new Config()); $app->boot(); $app->flush(); $app['console']->run();