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


PHP Application::handle方法代码示例

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


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

示例1: 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

示例2: build

 /**
  * Dump the given Route into a file
  *
  * @param Route $route
  * @param string $name
  * @param array $parameters
  */
 public function build(Route $route, $name, array $parameters = [])
 {
     $url = $this->app['url_generator']->generate($name, $parameters, UrlGeneratorInterface::ABSOLUTE_URL);
     $request = Request::create($url, 'GET', array_merge(['_format' => $route->getFormat()], $parameters));
     $response = $this->app->handle($request);
     $this->write($this->getFilePath($route, $parameters), $response->getContent(), $request->getFormat($response->headers->get('Content-Type')), $route->getFileName());
 }
开发者ID:phpillip,项目名称:phpillip,代码行数:14,代码来源:Builder.php

示例3: 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

示例4: run

 /**
  * Run react.
  *
  * @param int    $port
  * @param string $host
  */
 public function run($port, $host)
 {
     $request_handler = function (Request $request, Response $response) {
         echo $request->getMethod() . ' ' . $request->getPath() . PHP_EOL;
         $sf_request = $this->request_bridge->convertRequest($request);
         $sf_response = $this->app->handle($sf_request);
         $this->app->terminate($sf_request, $sf_response);
         $this->response_bridge->send($response, $sf_response);
     };
     $this->http->on('request', $request_handler);
     $this->socket->listen($port, $host);
     $this->loop->run();
 }
开发者ID:KEIII,项目名称:react-silex,代码行数:19,代码来源:ReactServer.php

示例5: testRegisterAndRender

 public function testRegisterAndRender()
 {
     $app = new Application();
     $app['debug'] = true;
     $app->register(new SmartyServiceProvider(), array('smarty.dir' => $this->smartyPath, 'smarty.options' => array('setTemplateDir' => $this->smartyPath . '/demo/templates', 'setCompileDir' => $this->smartyPath . '/demo/templates_c', 'setConfigDir' => $this->smartyPath . '/demo/configs', 'setCacheDir' => $this->smartyPath . '/demo/cache')));
     $app->get('/hello', function () use($app) {
         /** @var \Smarty $smarty  */
         $smarty = $app['smarty'];
         $smarty->debugging = true;
         $smarty->caching = true;
         $smarty->cache_lifetime = 120;
         $smarty->assign("Name", "Fred Irving Johnathan Bradley Peppergill", true);
         $smarty->assign("FirstName", array("John", "Mary", "James", "Henry"));
         $smarty->assign("LastName", array("Doe", "Smith", "Johnson", "Case"));
         $smarty->assign("Class", array(array("A", "B", "C", "D"), array("E", "F", "G", "H"), array("I", "J", "K", "L"), array("M", "N", "O", "P")));
         $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"), array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
         $smarty->assign("option_values", array("NY", "NE", "KS", "IA", "OK", "TX"));
         $smarty->assign("option_output", array("New York", "Nebraska", "Kansas", "Iowa", "Oklahoma", "Texas"));
         $smarty->assign("option_selected", "NE");
         return $smarty->fetch('index.tpl');
     });
     $request = Request::create('/hello');
     $response = $app->handle($request);
     $htmlContent = $response->getContent();
     $this->assertGreaterThan(7000, strlen($htmlContent));
     $this->assertNotRegExp('/Whoops/', $htmlContent);
 }
开发者ID:vincent,项目名称:Silex_SmartyServiceProvider,代码行数:27,代码来源:ServiceProviderTest.php

示例6: testLocaleWithBefore

 public function testLocaleWithBefore()
 {
     $app = new Application();
     $app->before(function (Request $request) use($app) {
         $request->setLocale('fr');
     });
     $app->get('/embed', function (Request $request) {
         return $request->getLocale();
     });
     $app->get('/', function (Request $request) use($app) {
         return $request->getLocale() . $app->handle(Request::create('/embed'), HttpKernelInterface::SUB_REQUEST)->getContent() . $request->getLocale();
     });
     $response = $app->handle(Request::create('/'));
     // locale in sub-request is "en" as the before filter is only executed for the main request
     $this->assertEquals('frenfr', $response->getContent());
 }
开发者ID:johnWIll17,项目名称:silex-blog,代码行数:16,代码来源:LocaleTest.php

示例7: 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

示例8: checkRouteResponse

 protected function checkRouteResponse(Application $app, $path, $expectedContent, $method = 'get', $message = null)
 {
     $app->register(new ServiceControllerServiceProvider());
     $request = Request::create($path, $method);
     $response = $app->handle($request);
     $this->assertEquals($expectedContent, $response->getContent(), $message);
 }
开发者ID:syntropysoftware,项目名称:cryptoffice-frontend,代码行数:7,代码来源:ServiceControllerResolverRouterTest.php

示例9: register

 /**
  *
  * @param  Application $app
  */
 public function register(Application $app)
 {
     /**
      *
      *
      */
     $app['helper.request.clone'] = $app->protect(function ($url, $options = [], $params = []) use($app) {
         $options += ['request' => '', 'method' => ''];
         $params += ['query' => [], 'request' => [], 'attributes' => [], 'cookies' => [], 'files' => [], 'server' => [], 'content' => null];
         if ($options['request'] == '') {
             $options['request'] = $app['request'];
         }
         $request = $options['request'];
         if ($options['method'] == '') {
             $options['method'] = $request->getMethod();
         }
         $params['query'] += $request->query->all();
         $params['request'] += $request->request->all();
         $params['cookies'] += $request->cookies->all();
         $params['files'] += $request->files->all();
         $params['server'] += $request->server->all();
         $subRequest = Request::create($url, $options['method'], [], $params['cookies'], $params['files'], $params['server']);
         if ($request->getSession()) {
             $subRequest->setSession($request->getSession());
         }
         foreach (['query', 'request', 'attributes'] as $p) {
             foreach ($params[$p] as $k => $v) {
                 $subRequest->{$p}->set($k, $v);
             }
         }
         return $subRequest;
     });
     /**
      *
      *
      */
     $app['helper.request.clone.master'] = $app->protect(function ($url, $options = [], $params = []) use($app) {
         return $app->handle($app['helper.request.clone']($url, $options, $params), HttpKernelInterface::MASTER_REQUEST, false);
     });
     /**
      *
      *
      */
     $app['helper.request.clone.sub'] = $app->protect(function ($url, $options = [], $params = []) use($app) {
         return $app->handle($app['helper.request.clone']($url, $options, $params), HttpKernelInterface::SUB_REQUEST, false);
     });
 }
开发者ID:wake,项目名称:Silex-SubRequest-Helper,代码行数:51,代码来源:SubRequestHelperProvider.php

示例10: testWrongAuthenticationType

 /**
  * @expectedException \LogicException
  */
 public function testWrongAuthenticationType()
 {
     $app = new Application();
     $app->register(new SecurityServiceProvider(), array('security.firewalls' => array('wrong' => array('foobar' => true, 'users' => array()))));
     $app->get('/', function () {
     });
     $app->handle(Request::create('/'));
 }
开发者ID:nekogami,项目名称:Silex,代码行数:11,代码来源:SecurityServiceProviderTest.php

示例11: testSecure

 public function testSecure()
 {
     $app = new Application();
     $app['route_class'] = 'Silex\\Tests\\Route\\SecurityRoute';
     $app->register(new SecurityServiceProvider(), array('security.firewalls' => array('default' => array('http' => true, 'users' => array('fabien' => array('ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg=='))))));
     $app->get('/', function () {
         return 'foo';
     })->secure('ROLE_ADMIN');
     $request = Request::create('/');
     $response = $app->handle($request);
     $this->assertEquals(401, $response->getStatusCode());
     $request = Request::create('/');
     $request->headers->set('PHP_AUTH_USER', 'fabien');
     $request->headers->set('PHP_AUTH_PW', 'foo');
     $response = $app->handle($request);
     $this->assertEquals(200, $response->getStatusCode());
 }
开发者ID:ahmedibr,项目名称:project,代码行数:17,代码来源:SecurityTraitTest.php

示例12: testFormatDetection

 /**
  * @depends testRegister
  */
 public function testFormatDetection(Application $app)
 {
     $app->get('/api/user/{id}', function ($id) use($app) {
         return $app['request']->getRequestFormat();
     });
     $request = Request::create('/api/user/1');
     $request->headers->set('Accept', 'application/json');
     $response = $app->handle($request);
     $this->assertEquals('json', $response->getContent());
 }
开发者ID:hingole,项目名称:Rest,代码行数:13,代码来源:ExtensionTest.php

示例13: testRouteWorks

 public function testRouteWorks()
 {
     $app = new Application();
     $app->register(new AutoRouteProvider());
     $app['MyTestController'] = $app->share(function () use($app) {
         return new MyTestController($app);
     });
     $request = Request::create('/my-test/test-method');
     $this->assertEquals('ok', $app->handle($request)->getContent());
 }
开发者ID:gerkirill,项目名称:silex-rad,代码行数:10,代码来源:AutoRouteProviderTest.php

示例14: testRegister

 public function testRegister()
 {
     $app = new Application();
     $app->register(new StatsDServiceProvider());
     $app->get('/', function () {
     });
     $request = Request::create('/');
     $app->handle($request);
     $this->assertInstanceOf('StatsD\\Client', $app['statsd']);
 }
开发者ID:angezanetti,项目名称:StatsDServiceProvider,代码行数:10,代码来源:StatsDServiceProviderTest.php

示例15: testSessionStorage

 public function testSessionStorage()
 {
     $app = new Application();
     $app->register(new SessionServiceProvider(), ['session.test' => true]);
     $app->register(new TagManagerServiceProvider(), ['gtm.options' => ['id' => 'GTM-XXX']]);
     $request = Request::create('/');
     $app->handle($request);
     $this->assertInstanceOf('ShineUnited\\TagManager\\Container', $app['gtm.container']);
     $this->assertInstanceOf('ShineUnited\\TagManager\\DataLayer', $app['gtm.datalayer']);
 }
开发者ID:shineunited,项目名称:tagmanager,代码行数:10,代码来源:TagManagerServiceProviderTest.php


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