Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

Commit

Permalink
fixed CS
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed May 15, 2012
1 parent 2c64936 commit 6fec6ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 51 deletions.
46 changes: 18 additions & 28 deletions src/Goutte/Client.php
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Goutte package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Goutte;

use Symfony\Component\BrowserKit\Client as BaseClient;
Expand All @@ -14,15 +23,6 @@
use Guzzle\Service\ClientInterface as GuzzleClientInterface;
use Guzzle\Service\Client as GuzzleClient;

/*
* This file is part of the Goutte package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Client.
*
Expand All @@ -32,7 +32,7 @@
*/
class Client extends BaseClient
{
const VERSION = '0.1';
const VERSION = '0.2';

protected $headers = array();
protected $auth = null;
Expand Down Expand Up @@ -75,7 +75,7 @@ public function setAuth($user, $password = '', $type = GuzzleRequestInterface::A
protected function doRequest($request)
{
$guzzleRequest = $this->getClient()->createRequest(
strtoupper($request->getMethod()),
$request->getMethod(),
$request->getUri(),
$this->headers,
$request->getParameters()
Expand All @@ -93,44 +93,34 @@ protected function doRequest($request)
$guzzleRequest->addCookie($name, $value);
}

if ($request->getMethod() == 'POST') {
if ('POST' == $request->getMethod()) {
foreach ($request->getFiles() as $name => $info) {
if (isset($info['tmp_name']) && '' !== $info['tmp_name']) {
$guzzleRequest->addPostFiles(array(
$name => $info['tmp_name']
));
$guzzleRequest->addPostFiles(array($name => $info['tmp_name']));
}
}
}

$guzzleRequest->setHeader('User-Agent', $this->server['HTTP_USER_AGENT']);

$guzzleRequest->getCurlOptions()->merge(array(
CURLOPT_MAXREDIRS => 0,
CURLOPT_TIMEOUT => 30
));
$guzzleRequest->getCurlOptions()->merge(array(CURLOPT_MAXREDIRS => 0, CURLOPT_TIMEOUT => 30));

// Let BrowserKit handle redirects
try {
$response = $guzzleRequest->send();
} catch (CurlException $e) {
if (strpos($e->getMessage(), 'redirects')) {
$response = $e->getResponse();
} else {
if (!strpos($e->getMessage(), 'redirects')) {
throw $e;
}

$response = $e->getResponse();
}

return $this->createResponse($response);
}

protected function createResponse(GuzzleResponse $response)
{
return new Response(
$response->getBody(true),
$response->getStatusCode(),
$response->getHeaders()->getAll()
);
return new Response($response->getBody(true), $response->getStatusCode(), $response->getHeaders()->getAll());
}
}

31 changes: 8 additions & 23 deletions tests/Goutte/Tests/ClientTest.php
@@ -1,28 +1,13 @@
<?php

/*
* This file is part of Goutte.
*
* Copyright (c) 2009 Fabien Potencier
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
* This file is part of the Goutte package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Goutte\Tests;

Expand Down Expand Up @@ -164,4 +149,4 @@ public function testHandlesRedirectsCorrectly()
// Ensure that two requests were sent
$this->assertEquals(2, count($this->history));
}
}
}

0 comments on commit 6fec6ef

Please sign in to comment.