本文整理汇总了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);
}