本文整理匯總了PHP中Silex\Application::factory方法的典型用法代碼示例。如果您正苦於以下問題:PHP Application::factory方法的具體用法?PHP Application::factory怎麽用?PHP Application::factory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Silex\Application
的用法示例。
在下文中一共展示了Application::factory方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __construct
public function __construct(Application $app, $path, $controller = null, $idVariable = 'id')
{
if (is_object($controller)) {
$controllerClass = static::underscoreDot(get_class($controller));
$app[$controllerClass] = $app->factory(function () use($controller) {
return $controller;
});
$controller = $controllerClass;
}
$this->app = $app;
$this->path = $path;
$this->idVariable = $idVariable;
$this->routes = array();
$this->prefix = substr($path, 1);
$this->prefix = str_replace('/{' . $idVariable . '}', '', $this->prefix);
$this->prefix = str_replace('/', '_', $this->prefix);
if ($controller !== null) {
$this->cget(sprintf('%s:%s', $controller, $app['rest.methods.cget']));
$this->post(sprintf('%s:%s', $controller, $app['rest.methods.post']));
$this->get(sprintf('%s:%s', $controller, $app['rest.methods.get']));
$this->put(sprintf('%s:%s', $controller, $app['rest.methods.put']));
$this->patch(sprintf('%s:%s', $controller, $app['rest.methods.patch']));
$this->delete(sprintf('%s:%s', $controller, $app['rest.methods.delete']));
}
}
示例2: testOverriddenRoutesFactory
public function testOverriddenRoutesFactory()
{
$app = new Application();
$app['routes_factory'] = $app->factory(function () {
return new RouteCollectionSubClass();
});
$this->assertInstanceOf('Silex\\Tests\\RouteCollectionSubClass', $app['routes']);
}
示例3: testAddResourceAlternate
public function testAddResourceAlternate()
{
$app = new Application();
$app['locale'] = 'fr';
$app->register(new ValidatorServiceProvider());
$app->register(new TranslationServiceProvider());
$app->factory($app->extend('translator.resources', function ($resources, $app) {
$resources = array_merge($resources, array(array('array', array('This value should not be blank.' => 'Pas vide'), 'fr', 'validators')));
return $resources;
}));
$app['validator'];
$this->assertEquals('Pas vide', $app['translator']->trans('This value should not be blank.', array(), 'validators', 'fr'));
}
示例4: testRoutesFactoryInConstructor
public function testRoutesFactoryInConstructor()
{
$app = new Application();
$app['routes_factory'] = $app->factory(function () {
return new RouteCollectionSubClass2();
});
$controllers = new ControllerCollection(new Route(), $app['routes_factory']);
$routes = $controllers->flush();
$this->assertInstanceOf('Silex\\Tests\\RouteCollectionSubClass2', $routes);
}