当前位置: 首页>>代码示例>>PHP>>正文


PHP Application::factory方法代码示例

本文整理汇总了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']));
     }
 }
开发者ID:kron0s,项目名称:silex-rest,代码行数:25,代码来源:Resource.php

示例2: testOverriddenRoutesFactory

 public function testOverriddenRoutesFactory()
 {
     $app = new Application();
     $app['routes_factory'] = $app->factory(function () {
         return new RouteCollectionSubClass();
     });
     $this->assertInstanceOf('Silex\\Tests\\RouteCollectionSubClass', $app['routes']);
 }
开发者ID:rayrutjes,项目名称:Silex,代码行数:8,代码来源:ApplicationTest.php

示例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'));
 }
开发者ID:Kanizada,项目名称:microCMS,代码行数:13,代码来源:ValidatorServiceProviderTest.php

示例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);
 }
开发者ID:nix5longhorn,项目名称:Silex,代码行数:10,代码来源:ControllerCollectionTest.php


注:本文中的Silex\Application::factory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。