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


PHP Application::get方法代码示例

本文整理汇总了PHP中Silex\Application::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::get方法的具体用法?PHP Application::get怎么用?PHP Application::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Silex\Application的用法示例。


在下文中一共展示了Application::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testRegisterAndRender

 public function testRegisterAndRender()
 {
     $app = new Application();
     $app->register(new MonologExtension(), array('monolog.class_path' => __DIR__ . '/../../../../vendor/monolog/src'));
     $app['monolog.handler'] = $app->share(function () use($app) {
         return new TestHandler($app['monolog.level']);
     });
     $app->get('/log', function () use($app) {
         $app['monolog']->addDebug('logging a message');
     });
     $app->get('/error', function () {
         throw new \RuntimeException('very bad error');
     });
     $app->error(function (\Exception $e) {
         return 'error handled';
     });
     $this->assertFalse($app['monolog.handler']->hasDebugRecords());
     $this->assertFalse($app['monolog.handler']->hasErrorRecords());
     $request = Request::create('/log');
     $app->handle($request);
     $request = Request::create('/error');
     $app->handle($request);
     $this->assertTrue($app['monolog.handler']->hasDebugRecords());
     $this->assertTrue($app['monolog.handler']->hasErrorRecords());
 }
开发者ID:nooks,项目名称:Silex,代码行数:25,代码来源:MonologExtensionTest.php

示例2: bootstrapApp

 private function bootstrapApp()
 {
     $app = new Application();
     $app['debug'] = true;
     $app->register(new TwigServiceProvider(), array('twig.templates' => array('main' => '{{ knp_menu_render("my_menu", {"compressed": true}, renderer) }}')));
     $app->register(new KnpMenuServiceProvider(), array('knp_menu.menus' => array('my_menu' => 'test.menu.my')));
     $app->register(new UrlGeneratorServiceProvider());
     $app['test.menu.my'] = function (Application $app) {
         /** @var $factory \Knp\Menu\FactoryInterface */
         $factory = $app['knp_menu.factory'];
         $root = $factory->createItem('root', array('childrenAttributes' => array('class' => 'nav')));
         $root->addChild('home', array('route' => 'homepage', 'label' => 'Home'));
         $root->addChild('KnpLabs', array('uri' => 'http://knplabs.com', 'extras' => array('routes' => 'other_route')));
         return $root;
     };
     $app['test.voter'] = $app->share(function (Application $app) {
         $voter = new RouteVoter();
         $voter->setRequest($app['request']);
         return $voter;
     });
     $app['knp_menu.matcher.configure'] = $app->protect(function (Matcher $matcher) use($app) {
         $matcher->addVoter($app['test.voter']);
     });
     $app->get('/twig', function (Application $app) {
         return $app['twig']->render('main', array('renderer' => 'twig'));
     })->bind('homepage');
     $app->get('/other-twig', function (Application $app) {
         return $app['twig']->render('main', array('renderer' => 'twig'));
     })->bind('other_route');
     $app->get('/list', function (Application $app) {
         return $app['twig']->render('main', array('renderer' => 'list'));
     })->bind('list');
     return $app;
 }
开发者ID:andrewkrug,项目名称:repucaution,代码行数:34,代码来源:KnpMenuServiceProviderTest.php

示例3: boot

 /**
  * Bootstraps the application.
  *
  * This method is called after all services are registered
  * and should be used for "dynamic" configuration (whenever
  * a service must be requested).
  */
 public function boot(Application $app)
 {
     $this->app = $app;
     $app->get($app["documentation.url"] . '/', function () use($app) {
         $subRequest = Request::create($app["documentation.url"], 'GET');
         return $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
     });
     $app->get($app["documentation.url"], function () use($app) {
         $home = $app["documentation.dir"] . '/' . $app["documentation.home"] . '.' . $app["documentation.extension"];
         if (is_file($home)) {
             if (is_readable($home)) {
                 $content = file_get_contents($home);
                 return $app["DocumentationRenderer"]->render($content);
             } else {
                 $app->abort("403", "Forbidden");
             }
         } else {
             $app->abort("404", "Documentation Page not Found ");
         }
     });
     $app->get($app["documentation.url"] . "/{pagename}", function (Request $request) use($app) {
         $page = $app["documentation.dir"] . '/' . $request->get('pagename') . '.' . $app["documentation.extension"];
         if (is_file($page)) {
             if (is_readable($page)) {
                 $content = file_get_contents($page);
                 return $app["DocumentationRenderer"]->render($content);
             } else {
                 $app->abort("403", "Forbidden");
             }
         } else {
             $app->abort("404", "Documentation Page not Found ");
         }
     })->assert('pagename', '[a-zA-Z0-9-/]*')->value("pagename", "index");
 }
开发者ID:mimiz,项目名称:silex-documentation-provider,代码行数:41,代码来源:DocumentationProvider.php

示例4: createResource

 /**
  * Create a resource and all its sub-resources.
  *
  * @param array $resourceConfig
  * @param array $parentUris
  * @throws \RuntimeException
  */
 public function createResource(array $resourceConfig, array $parentUris = array())
 {
     if (empty($resourceConfig['uri']) || empty($resourceConfig['ctl'])) {
         throw new \RuntimeException('Invalid resource config encountered. Config must contain uri and ctl keys');
     }
     if ($resourceConfig['ctl'] instanceof \Closure) {
         //registers controller factory inline
         $controllerName = $this->registerController($resourceConfig['uri'], $resourceConfig['ctl'], $parentUris);
     } elseif (is_string($resourceConfig['ctl'])) {
         $controllerName = $resourceConfig['ctl'];
     } else {
         throw new \RuntimeException('Ctl must be a factory (Closure) or existing service (string name)');
     }
     //setup routes
     $this->app->get($this->createRouteUri($resourceConfig['uri'], $parentUris, true), sprintf('%s:get', $controllerName));
     $this->app->get($this->createRouteUri($resourceConfig['uri'], $parentUris, false), sprintf('%s:cget', $controllerName));
     $this->app->post($this->createRouteUri($resourceConfig['uri'], $parentUris, false), sprintf('%s:post', $controllerName));
     $this->app->put($this->createRouteUri($resourceConfig['uri'], $parentUris, true), sprintf('%s:put', $controllerName));
     $this->app->patch($this->createRouteUri($resourceConfig['uri'], $parentUris, true), sprintf('%s:patch', $controllerName));
     $this->app->delete($this->createRouteUri($resourceConfig['uri'], $parentUris, true), sprintf('%s:delete', $controllerName));
     //handle sub resources
     if (!empty($resourceConfig['sub'])) {
         if (!is_array($resourceConfig['sub'])) {
             throw new \RuntimeException('sub config must contain array of sub resources');
         }
         //append current uri as parent
         $parentUris[] = $resourceConfig['uri'];
         foreach ($resourceConfig['sub'] as $subResource) {
             $this->createResource($subResource, $parentUris);
         }
     }
 }
开发者ID:warmans,项目名称:silex-rest-provider,代码行数:39,代码来源:RestService.php

示例5: testRegister

 public function testRegister()
 {
     $app = new Application();
     $app->register(new SessionServiceProvider());
     /**
      * Smoke test
      */
     $defaultStorage = $app['session.storage'];
     $app['session.storage'] = $app->share(function () use($app) {
         return new MockArraySessionStorage();
     });
     $app->get('/login', function () use($app) {
         $app['session']->set('logged_in', true);
         return 'Logged in successfully.';
     });
     $app->get('/account', function () use($app) {
         if (!$app['session']->get('logged_in')) {
             return 'You are not logged in.';
         }
         return 'This is your account.';
     });
     $request = Request::create('/login');
     $response = $app->handle($request);
     $this->assertEquals('Logged in successfully.', $response->getContent());
     $request = Request::create('/account');
     $response = $app->handle($request);
     $this->assertEquals('This is your account.', $response->getContent());
 }
开发者ID:nicodmf,项目名称:Silex,代码行数:28,代码来源:SessionServiceProviderTest.php

示例6: setUp

 protected function setUp()
 {
     $this->app = new Application(['debug' => 'true']);
     $this->app->get('/', function () {
         return new Response('', 200);
     });
 }
开发者ID:evaneos,项目名称:silex-jwt-provider,代码行数:7,代码来源:SecurityJWTServiceProviderTest.php

示例7: boot

 public function boot(Application $app)
 {
     $app->get('/vendor/{vendor}/{project}/{file}', function ($vendor, $project, $file) use($app) {
         return $app['public-vendor.response']($app['public-vendor']->resolve($vendor, $file, $project));
     })->assert('file', '.*');
     $app->get('/vendor/{alias}/{file}', function ($alias, $file) use($app) {
         return $app['public-vendor.response']($app['public-vendor']->resolve($alias, $file));
     });
 }
开发者ID:johnpitcher,项目名称:public-vendor,代码行数:9,代码来源:ServiceProvider.php

示例8: getRouter

 /**
  * @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);
 }
开发者ID:project-a,项目名称:silex-routing,代码行数:15,代码来源:SilexRouterTest.php

示例9: loadCall

 private function loadCall()
 {
     $this->application->get('/api/' . $this->version . '/click2call.json', function (Application $application) {
         $controller = new Click2Call($application);
         return $controller->getAll();
     });
     $this->application->get('/api/' . $this->version . '/click2call/call/{name}/{phone}', function (Application $application, $name, $phone) {
         $controller = new Click2Call($application);
         return $controller->call($name, $phone);
     });
 }
开发者ID:bflechel,项目名称:OpenAddressBook,代码行数:11,代码来源:Dispatcher.php

示例10: testResolveController

 public function testResolveController()
 {
     $resolver = new ControllerResolver($this->app);
     $class = 'Jonsa\\SilexResolver\\Test\\Data\\IndexController';
     $method = "{$class}::index";
     $request = Request::create('/');
     $request->attributes->set('_controller', $method);
     $this->app->get('/', $method);
     $callable = $resolver->getController($request);
     $this->assertInstanceOf($class, $callable[0]);
 }
开发者ID:jonsa,项目名称:silex-ioc,代码行数:11,代码来源:ControllerResolverTest.php

示例11: boot

 /**
  * Add routes to the swagger UI documentation browser
  *
  * @param Application $app
  */
 public function boot(Application $app)
 {
     preg_match('/(\\/.*)\\/.*|(\\/)/', $app['swaggerui.path'], $matches);
     $assetsPath = count($matches) ? array_pop($matches) : $app['swaggerui.path'];
     // Index route
     $app->get($app['swaggerui.path'], array($this, 'getIndex'));
     // Asset in the root directory
     $app->get($assetsPath . '/{asset}', array($this, 'getAsset'));
     // Assets in a folder
     $app->get($assetsPath . '/{directory}/{asset}', array($this, 'getAssetFromDirectory'));
 }
开发者ID:Ard-Jan,项目名称:silex-swagger-ui,代码行数:16,代码来源:SwaggerUIServiceProvider.php

示例12: testUrlGenerationWithHttps

 public function testUrlGenerationWithHttps()
 {
     $app = new Application();
     $app->get('/secure', function () {
     })->bind('secure_page')->requireHttps();
     $app->get('/', function () use($app) {
         return $app['url_generator']->generate('secure_page');
     });
     $request = Request::create('http://localhost/');
     $response = $app->handle($request);
     $this->assertEquals('https://localhost/secure', $response->getContent());
 }
开发者ID:abdonor,项目名称:silex_simple_api,代码行数:12,代码来源:RoutingServiceProviderTest.php

示例13: createApplication

 private function createApplication()
 {
     $app = new Application();
     unset($app['exception_handler']);
     $app->register(new EkinoNewRelicServiceProvider(), array('new_relic.enabled' => true));
     $app['new_relic.interactor.real'] = $this->getMock('Ekino\\Bundle\\NewRelicBundle\\NewRelic\\NewRelicInteractor');
     $app->get('/page', function () {
         return 'OK';
     })->bind('my_page');
     $app->get('/error', function () {
         throw new \RuntimeException('Test Exception');
     })->bind('my_error');
     return $app;
 }
开发者ID:Aerendir,项目名称:EkinoNewRelicBundle,代码行数:14,代码来源:EkinoNewRelicServiceProviderTest.php

示例14: init

 public static function init(Application $app)
 {
     $app->register(new ServiceControllerServiceProvider());
     $app['locations.controller'] = $app->share(function () use($app) {
         return new LocationsController($app, $app['locations.service']);
     });
     $app['locations.service'] = $app->share(function () use($app) {
         return new LocationsService();
     });
     $app->get('/', function () {
         return "API is UP";
     });
     $app->get('/locations/{mediaId}', "locations.controller:getLocation");
 }
开发者ID:eacheble,项目名称:locations,代码行数:14,代码来源:Bootstrap.php

示例15: configureApplication

 protected function configureApplication(Application $app)
 {
     $app['logger'] = $this->getMockLogger();
     $app->register(new \Silex\Provider\SessionServiceProvider());
     $app->register(new \Silex\Provider\SecurityServiceProvider());
     $app->register(new \Renegare\Scoauth\OAuthClientServiceProvider());
     $app['security.firewalls'] = ['healthcheck' => ['pattern' => '^/healthcheck', 'anonymous' => true, 'stateless' => true], 'app' => ['pattern' => '^/', 'scoauth' => true]];
     $app->get('/healthcheck', function () {
         return 'All Good!';
     });
     $app->get('/proteted-uri', function () {
         return 'All Good!';
     });
 }
开发者ID:renegare,项目名称:scoauth,代码行数:14,代码来源:WebtestCase.php


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