class Client in Zircon Profile 8
Same name in this branch
- 8 vendor/symfony/http-kernel/Client.php \Symfony\Component\HttpKernel\Client
- 8 vendor/symfony/browser-kit/Client.php \Symfony\Component\BrowserKit\Client
- 8 vendor/fabpot/goutte/Goutte/Client.php \Goutte\Client
- 8 vendor/guzzlehttp/guzzle/src/Client.php \GuzzleHttp\Client
- 8 vendor/behat/mink-goutte-driver/src/Goutte/Client.php \Behat\Mink\Driver\Goutte\Client
Same name and namespace in other branches
- 8.0 vendor/symfony/http-kernel/Client.php \Symfony\Component\HttpKernel\Client
Client simulates a browser and makes requests to a Kernel object.
@author Fabien Potencier <fabien@symfony.com>
Hierarchy
Expanded class hierarchy of Client
5 files declare their use of Client
- BaseUrlTest.php in vendor/
behat/ mink-browserkit-driver/ tests/ Custom/ BaseUrlTest.php - BrowserKitConfig.php in vendor/
behat/ mink-browserkit-driver/ tests/ BrowserKitConfig.php - BrowserKitDriver.php in vendor/
behat/ mink-browserkit-driver/ src/ BrowserKitDriver.php - ClientTest.php in vendor/
symfony/ http-kernel/ Tests/ ClientTest.php - TestClient.php in vendor/
symfony/ http-kernel/ Tests/ Fixtures/ TestClient.php
File
- vendor/
symfony/ http-kernel/ Client.php, line 29
Namespace
Symfony\Component\HttpKernelView source
class Client extends BaseClient {
protected $kernel;
/**
* Constructor.
*
* @param HttpKernelInterface $kernel An HttpKernel instance
* @param array $server The server parameters (equivalent of $_SERVER)
* @param History $history A History instance to store the browser history
* @param CookieJar $cookieJar A CookieJar instance to store the cookies
*/
public function __construct(HttpKernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null) {
// These class properties must be set before calling the parent constructor, as it may depend on it.
$this->kernel = $kernel;
$this->followRedirects = false;
parent::__construct($server, $history, $cookieJar);
}
/**
* {@inheritdoc}
*
* @return Request|null A Request instance
*/
public function getRequest() {
return parent::getRequest();
}
/**
* {@inheritdoc}
*
* @return Response|null A Response instance
*/
public function getResponse() {
return parent::getResponse();
}
/**
* Makes a request.
*
* @param Request $request A Request instance
*
* @return Response A Response instance
*/
protected function doRequest($request) {
$response = $this->kernel
->handle($request);
if ($this->kernel instanceof TerminableInterface) {
$this->kernel
->terminate($request, $response);
}
return $response;
}
/**
* Returns the script to execute when the request must be insulated.
*
* @param Request $request A Request instance
*
* @return string
*/
protected function getScript($request) {
$kernel = str_replace("'", "\\'", serialize($this->kernel));
$request = str_replace("'", "\\'", serialize($request));
$r = new \ReflectionClass('\\Symfony\\Component\\ClassLoader\\ClassLoader');
$requirePath = str_replace("'", "\\'", $r
->getFileName());
$symfonyPath = str_replace("'", "\\'", dirname(dirname(dirname(__DIR__))));
$errorReporting = error_reporting();
$code = <<<EOF
<?php
error_reporting({<span class="php-variable">$errorReporting</span>} & ~E_USER_DEPRECATED);
require_once '{<span class="php-variable">$requirePath</span>}';
\$loader = new Symfony\\Component\\ClassLoader\\ClassLoader();
\$loader->addPrefix('Symfony', '{<span class="php-variable">$symfonyPath</span>}');
\$loader->register();
\$kernel = unserialize('{<span class="php-variable">$kernel</span>}');
\$request = unserialize('{<span class="php-variable">$request</span>}');
EOF;
return $code . $this
->getHandleScript();
}
protected function getHandleScript() {
return <<<'EOF'
$response = $kernel->handle($request);
if ($kernel instanceof Symfony\Component\HttpKernel\TerminableInterface) {
$kernel->terminate($request, $response);
}
echo serialize($response);
EOF;
}
/**
* Converts the BrowserKit request to a HttpKernel request.
*
* @param DomRequest $request A DomRequest instance
*
* @return Request A Request instance
*/
protected function filterRequest(DomRequest $request) {
$httpRequest = Request::create($request
->getUri(), $request
->getMethod(), $request
->getParameters(), $request
->getCookies(), $request
->getFiles(), $request
->getServer(), $request
->getContent());
foreach ($this
->filterFiles($httpRequest->files
->all()) as $key => $value) {
$httpRequest->files
->set($key, $value);
}
return $httpRequest;
}
/**
* Filters an array of files.
*
* This method created test instances of UploadedFile so that the move()
* method can be called on those instances.
*
* If the size of a file is greater than the allowed size (from php.ini) then
* an invalid UploadedFile is returned with an error set to UPLOAD_ERR_INI_SIZE.
*
* @see UploadedFile
*
* @param array $files An array of files
*
* @return array An array with all uploaded files marked as already moved
*/
protected function filterFiles(array $files) {
$filtered = array();
foreach ($files as $key => $value) {
if (is_array($value)) {
$filtered[$key] = $this
->filterFiles($value);
}
elseif ($value instanceof UploadedFile) {
if ($value
->isValid() && $value
->getSize() > UploadedFile::getMaxFilesize()) {
$filtered[$key] = new UploadedFile('', $value
->getClientOriginalName(), $value
->getClientMimeType(), 0, UPLOAD_ERR_INI_SIZE, true);
}
else {
$filtered[$key] = new UploadedFile($value
->getPathname(), $value
->getClientOriginalName(), $value
->getClientMimeType(), $value
->getClientSize(), $value
->getError(), true);
}
}
}
return $filtered;
}
/**
* Converts the HttpKernel response to a BrowserKit response.
*
* @param Response $response A Response instance
*
* @return DomResponse A DomResponse instance
*/
protected function filterResponse($response) {
$headers = $response->headers
->all();
if ($response->headers
->getCookies()) {
$cookies = array();
foreach ($response->headers
->getCookies() as $cookie) {
$cookies[] = new DomCookie($cookie
->getName(), $cookie
->getValue(), $cookie
->getExpiresTime(), $cookie
->getPath(), $cookie
->getDomain(), $cookie
->isSecure(), $cookie
->isHttpOnly());
}
$headers['Set-Cookie'] = $cookies;
}
// this is needed to support StreamedResponse
ob_start();
$response
->sendContent();
$content = ob_get_clean();
return new DomResponse($content, $response
->getStatusCode(), $headers);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Client:: |
protected | property | ||
Client:: |
protected | property | ||
Client:: |
protected | property | ||
Client:: |
protected | property | ||
Client:: |
protected | property | ||
Client:: |
protected | property | ||
Client:: |
protected | property | ||
Client:: |
private | property | ||
Client:: |
protected | property | ||
Client:: |
private | property | ||
Client:: |
protected | property | ||
Client:: |
private | property | ||
Client:: |
protected | property | ||
Client:: |
protected | property | ||
Client:: |
protected | property | ||
Client:: |
public | function | Goes back in the browser history. | |
Client:: |
public | function | Clicks on a given link. | |
Client:: |
protected | function | Creates a crawler. | |
Client:: |
protected | function |
Makes a request. Overrides Client:: |
|
Client:: |
protected | function | Makes a request in another process. | |
Client:: |
private | function | ||
Client:: |
protected | function | Filters an array of files. | |
Client:: |
protected | function |
Converts the BrowserKit request to a HttpKernel request. Overrides Client:: |
|
Client:: |
protected | function |
Converts the HttpKernel response to a BrowserKit response. Overrides Client:: |
|
Client:: |
public | function | Follow redirects? | |
Client:: |
public | function | Sets whether to automatically follow redirects or not. | |
Client:: |
public | function | Goes forward in the browser history. | |
Client:: |
protected | function | Takes a URI and converts it to absolute if it is not already absolute. | |
Client:: |
public | function | Returns the CookieJar instance. | |
Client:: |
public | function | Returns the current Crawler instance. | |
Client:: |
protected | function | ||
Client:: |
public | function | Returns the History instance. | |
Client:: |
public | function | Returns the current BrowserKit Request instance. | |
Client:: |
public | function | Returns the current BrowserKit Response instance. | |
Client:: |
public | function |
Overrides Client:: |
|
Client:: |
public | function |
Overrides Client:: |
|
Client:: |
protected | function |
Returns the script to execute when the request must be insulated. Overrides Client:: |
|
Client:: |
public | function | Gets single server parameter for specified key. | |
Client:: |
public | function | Sets the insulated flag. | |
Client:: |
public | function | Reloads the current browser. | |
Client:: |
public | function | Calls a URI. | |
Client:: |
protected | function | Makes a request from a Request object directly. | |
Client:: |
public | function | Restarts the client. | |
Client:: |
public | function | Sets the maximum number of requests that crawler can follow. | |
Client:: |
public | function | Sets single server parameter. | |
Client:: |
public | function | Sets server parameters. | |
Client:: |
public | function | Submits a form. | |
Client:: |
private | function | ||
Client:: |
public | function |
Constructor. Overrides Client:: |