當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。