當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Request::setFactory方法代碼示例

本文整理匯總了PHP中Symfony\Component\HttpFoundation\Request::setFactory方法的典型用法代碼示例。如果您正苦於以下問題:PHP Request::setFactory方法的具體用法?PHP Request::setFactory怎麽用?PHP Request::setFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\HttpFoundation\Request的用法示例。


在下文中一共展示了Request::setFactory方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: configureFactory

 /**
  * @param string $type
  */
 private static function configureFactory($type)
 {
     if (version_compare(Kernel::VERSION, '2.5', '<')) {
         // nothing to configure as Request::setFactory require SF > 2.5
         return;
     }
     if (!in_array($type, array('host_with_path', 'host_with_path_by_locale'))) {
         return;
     }
     Request::setFactory(function (array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null) {
         return new SiteRequest($query, $request, $attributes, $cookies, $files, $server, $content);
     });
 }
開發者ID:Neodork,項目名稱:SonataPageBundle,代碼行數:16,代碼來源:RequestFactory.php

示例2: testTrustedHosts

 /**
  * Tests hostname validation with settings.
  *
  * @covers ::setupTrustedHosts
  * @dataProvider providerTestTrustedHosts
  */
 public function testTrustedHosts($host, $server_name, $message, $expected = FALSE)
 {
     $request = new Request();
     $trusted_host_patterns = ['^example\\.com$', '^.+\\.example\\.com$', '^example\\.org', '^.+\\.example\\.org'];
     if (!empty($host)) {
         $request->headers->set('HOST', $host);
     }
     $request->server->set('SERVER_NAME', $server_name);
     $method = new \ReflectionMethod('Drupal\\Core\\DrupalKernel', 'setupTrustedHosts');
     $method->setAccessible(TRUE);
     $valid_host = $method->invoke(null, $request, $trusted_host_patterns);
     $this->assertSame($expected, $valid_host, $message);
     // Reset the trusted hosts because it is statically stored on the request.
     $method->invoke(null, $request, []);
     // Reset the request factory because it is statically stored on the request.
     Request::setFactory(NULL);
 }
開發者ID:dev981,項目名稱:gaptest,代碼行數:23,代碼來源:DrupalKernelTrustedHostsTest.php

示例3: testFactory

 public function testFactory()
 {
     Request::setFactory(function (array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null) {
         return new NewRequest();
     });
     $this->assertEquals('foo', Request::create('/')->getFoo());
     Request::setFactory(null);
 }
開發者ID:anderson-abc,項目名稱:sf2_kowee,代碼行數:8,代碼來源:RequestTest.php

示例4: setupTrustedHosts

 /**
  * Sets up the lists of trusted HTTP Host headers.
  *
  * Since the HTTP Host header can be set by the user making the request, it
  * is possible to create an attack vectors against a site by overriding this.
  * Symfony provides a mechanism for creating a list of trusted Host values.
  *
  * Host patterns (as regular expressions) can be configured throught
  * settings.php for multisite installations, sites using ServerAlias without
  * canonical redirection, or configurations where the site responds to default
  * requests. For example,
  *
  * @code
  * $settings['trusted_host_patterns'] = array(
  *   '^example\.com$',
  *   '^*.example\.com$',
  * );
  * @endcode
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  * @param array $host_patterns
  *   The array of trusted host patterns.
  *
  * @return boolean
  *   TRUE if the Host header is trusted, FALSE otherwise.
  *
  * @see https://www.drupal.org/node/1992030
  * @see \Drupal\Core\Http\TrustedHostsRequestFactory
  */
 protected static function setupTrustedHosts(Request $request, $host_patterns)
 {
     $request->setTrustedHosts($host_patterns);
     // Get the host, which will validate the current request.
     try {
         $host = $request->getHost();
         // Fake requests created through Request::create() without passing in the
         // server variables from the main request have a default host of
         // 'localhost'. If 'localhost' does not match any of the trusted host
         // patterns these fake requests would fail the host verification. Instead,
         // TrustedHostsRequestFactory makes sure to pass in the server variables
         // from the main request.
         $request_factory = new TrustedHostsRequestFactory($host);
         Request::setFactory([$request_factory, 'createRequest']);
     } catch (\UnexpectedValueException $e) {
         return FALSE;
     }
     return TRUE;
 }
開發者ID:Nikola-xiii,項目名稱:d8intranet,代碼行數:49,代碼來源:DrupalKernel.php

示例5: tearDown

 public function tearDown()
 {
     if ($this->hasFactory) {
         Request::setFactory(null);
     }
 }
開發者ID:Neodork,項目名稱:SonataPageBundle,代碼行數:6,代碼來源:RequestFactoryTest.php


注:本文中的Symfony\Component\HttpFoundation\Request::setFactory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。