Skip to content

Commit

Permalink
Move Http\Client into Http package.
Browse files Browse the repository at this point in the history
Move Cake\Network\Http\Client into the Http package. This change just
moves the implementation and not the test cases. This shows that the
correct class renames are in place. I wanted to move the implementation
first to keep this change small and easy to review. I've renamed
FormData\Part to FormDataPart as the extra directories were not
necessary.

I also wanted get consensus on the renames before doing more work.
  • Loading branch information
markstory committed Apr 26, 2016
1 parent 4697b8e commit 5d866f0
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 44 deletions.
13 changes: 13 additions & 0 deletions config/bootstrap.php
Expand Up @@ -29,6 +29,19 @@ class_alias('Cake\Mailer\Email', 'Cake\Network\Email\Email');
class_alias('Cake\Mailer\Transport\MailTransport', 'Cake\Network\Email\MailTransport');
class_alias('Cake\Mailer\Transport\SmtpTransport', 'Cake\Network\Email\SmtpTransport');

// @deprecated Backwards compatibility with earler 3.x versions.
class_alias('Cake\Http\Client', 'Cake\Network\Http\Client');
class_alias('Cake\Http\Client\CookieCollection', 'Cake\Network\Http\CookieCollection');
class_alias('Cake\Http\Client\FormData', 'Cake\Network\Http\FormData');
class_alias('Cake\Http\Client\Message', 'Cake\Network\Http\Message');
class_alias('Cake\Http\Client\Request', 'Cake\Network\Http\Request');
class_alias('Cake\Http\Client\Response', 'Cake\Network\Http\Response');
class_alias('Cake\Http\Client\Adapter\Stream', 'Cake\Network\Http\Adapter\Stream');
class_alias('Cake\Http\Client\Auth\Basic', 'Cake\Network\Http\Auth\Basic');
class_alias('Cake\Http\Client\Auth\Digest', 'Cake\Network\Http\Auth\Digest');
class_alias('Cake\Http\Client\Auth\Oauth', 'Cake\Network\Http\Auth\Oauth');
class_alias('Cake\Http\Client\FormDataPart', 'Cake\Network\Http\FormData\Part');

require CAKE . 'basics.php';

// Sets the initial router state so future reloads work.
Expand Down
42 changes: 22 additions & 20 deletions src/Network/Http/Client.php → src/Http/Client.php
Expand Up @@ -11,11 +11,13 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Network\Http;
namespace Cake\Http;

use Cake\Core\App;
use Cake\Core\Exception\Exception;
use Cake\Core\InstanceConfigTrait;
use Cake\Http\Client\CookieCollection;
use Cake\Http\Client\Request;
use Cake\Utility\Hash;

/**
Expand Down Expand Up @@ -98,7 +100,7 @@ class Client
* @var array
*/
protected $_defaultConfig = [
'adapter' => 'Cake\Network\Http\Adapter\Stream',
'adapter' => 'Cake\Http\Client\Adapter\Stream',
'host' => null,
'port' => null,
'scheme' => 'http',
Expand All @@ -116,15 +118,15 @@ class Client
* Cookies are indexed by the cookie's domain or
* request host name.
*
* @var \Cake\Network\Http\CookieCollection
* @var \Cake\Http\Client\CookieCollection
*/
protected $_cookies;

/**
* Adapter for sending requests. Defaults to
* Cake\Network\Http\Adapter\Stream
*
* @var \Cake\Network\Http\Adapter\Stream
* @var \Cake\Http\Client\Adapter\Stream
*/
protected $_adapter;

Expand Down Expand Up @@ -175,7 +177,7 @@ public function __construct($config = [])
*
* Returns an array of cookie data arrays.
*
* @return \Cake\Network\Http\CookieCollection
* @return \Cake\Http\Client\CookieCollection
*/
public function cookies()
{
Expand All @@ -193,7 +195,7 @@ public function cookies()
* @param string $url The url or path you want to request.
* @param array $data The query data you want to send.
* @param array $options Additional options for the request.
* @return \Cake\Network\Http\Response
* @return \Cake\Http\Client\Response
*/
public function get($url, $data = [], array $options = [])
{
Expand All @@ -218,7 +220,7 @@ public function get($url, $data = [], array $options = [])
* @param string $url The url or path you want to request.
* @param mixed $data The post data you want to send.
* @param array $options Additional options for the request.
* @return \Cake\Network\Http\Response
* @return \Cake\Http\Client\Response
*/
public function post($url, $data = [], array $options = [])
{
Expand All @@ -233,7 +235,7 @@ public function post($url, $data = [], array $options = [])
* @param string $url The url or path you want to request.
* @param mixed $data The request data you want to send.
* @param array $options Additional options for the request.
* @return \Cake\Network\Http\Response
* @return \Cake\Http\Client\Response
*/
public function put($url, $data = [], array $options = [])
{
Expand All @@ -248,7 +250,7 @@ public function put($url, $data = [], array $options = [])
* @param string $url The url or path you want to request.
* @param mixed $data The request data you want to send.
* @param array $options Additional options for the request.
* @return \Cake\Network\Http\Response
* @return \Cake\Http\Client\Response
*/
public function patch($url, $data = [], array $options = [])
{
Expand All @@ -263,7 +265,7 @@ public function patch($url, $data = [], array $options = [])
* @param string $url The url or path you want to request.
* @param mixed $data The request data you want to send.
* @param array $options Additional options for the request.
* @return \Cake\Network\Http\Response
* @return \Cake\Http\Client\Response
*/
public function options($url, $data = [], array $options = [])
{
Expand All @@ -278,7 +280,7 @@ public function options($url, $data = [], array $options = [])
* @param string $url The url or path you want to request.
* @param mixed $data The request data you want to send.
* @param array $options Additional options for the request.
* @return \Cake\Network\Http\Response
* @return \Cake\Http\Client\Response
*/
public function trace($url, $data = [], array $options = [])
{
Expand All @@ -293,7 +295,7 @@ public function trace($url, $data = [], array $options = [])
* @param string $url The url or path you want to request.
* @param mixed $data The request data you want to send.
* @param array $options Additional options for the request.
* @return \Cake\Network\Http\Response
* @return \Cake\Http\Client\Response
*/
public function delete($url, $data = [], array $options = [])
{
Expand All @@ -308,7 +310,7 @@ public function delete($url, $data = [], array $options = [])
* @param string $url The url or path you want to request.
* @param array $data The query string data you want to send.
* @param array $options Additional options for the request.
* @return \Cake\Network\Http\Response
* @return \Cake\Http\Client\Response
*/
public function head($url, array $data = [], array $options = [])
{
Expand All @@ -324,7 +326,7 @@ public function head($url, array $data = [], array $options = [])
* @param string $url URL to request.
* @param mixed $data The request body.
* @param array $options The options to use. Contains auth, proxy etc.
* @return \Cake\Network\Http\Response
* @return \Cake\Http\Client\Response
*/
protected function _doRequest($method, $url, $data, $options)
{
Expand Down Expand Up @@ -354,9 +356,9 @@ protected function _mergeOptions($options)
* Used internally by other methods, but can also be used to send
* handcrafted Request objects.
*
* @param \Cake\Network\Http\Request $request The request to send.
* @param \Cake\Http\Client\Request $request The request to send.
* @param array $options Additional options to use.
* @return \Cake\Network\Http\Response
* @return \Cake\Http\Client\Response
*/
public function send(Request $request, $options = [])
{
Expand Down Expand Up @@ -414,7 +416,7 @@ public function buildUrl($url, $query = [], $options = [])
* @param string $url The url including query string.
* @param mixed $data The request body.
* @param array $options The options to use. Contains auth, proxy etc.
* @return \Cake\Network\Http\Request
* @return \Cake\Http\Client\Request
*/
protected function _createRequest($method, $url, $data, $options)
{
Expand Down Expand Up @@ -480,7 +482,7 @@ protected function _typeHeaders($type)
* Uses the authentication type to choose the correct strategy
* and use its methods to add headers.
*
* @param \Cake\Network\Http\Request $request The request to modify.
* @param \Cake\Http\Client\Request $request The request to modify.
* @param array $options Array of options containing the 'auth' key.
* @return void
*/
Expand All @@ -497,7 +499,7 @@ protected function _addAuthentication(Request $request, $options)
* Uses the authentication type to choose the correct strategy
* and use its methods to add headers.
*
* @param \Cake\Network\Http\Request $request The request to modify.
* @param \Cake\Http\Client\Request $request The request to modify.
* @param array $options Array of options containing the 'proxy' key.
* @return void
*/
Expand Down Expand Up @@ -525,7 +527,7 @@ protected function _createAuth($auth, $options)
$auth['type'] = 'basic';
}
$name = ucfirst($auth['type']);
$class = App::className($name, 'Network/Http/Auth');
$class = App::className($name, 'Http/Client/Auth');
if (!$class) {
throw new Exception(
sprintf('Invalid authentication type %s', $name)
Expand Down
Expand Up @@ -11,12 +11,12 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Network\Http\Adapter;
namespace Cake\Http\Client\Adapter;

use Cake\Core\Exception\Exception;
use Cake\Network\Http\FormData;
use Cake\Network\Http\Request;
use Cake\Network\Http\Response;
use Cake\Http\Client\FormData;
use Cake\Http\Client\Request;
use Cake\Http\Client\Response;

/**
* Implements sending Cake\Network\Http\Request
Expand Down Expand Up @@ -65,7 +65,7 @@ class Stream
/**
* Send a request and get a response back.
*
* @param \Cake\Network\Http\Request $request The request object to send.
* @param \Cake\Http\Client\Request $request The request object to send.
* @param array $options Array of options for the stream.
* @return array Array of populated Response objects
*/
Expand Down
Expand Up @@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Network\Http\Auth;
namespace Cake\Http\Client\Auth;

use Cake\Network\Http\Request;

Expand Down
Expand Up @@ -11,10 +11,10 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Network\Http\Auth;
namespace Cake\Http\Client\Auth;

use Cake\Network\Http\Client;
use Cake\Network\Http\Request;
use Cake\Http\Client;
use Cake\Http\Client\Request;

/**
* Digest authentication adapter for Cake\Network\Http\Client
Expand Down
Expand Up @@ -11,10 +11,10 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Network\Http\Auth;
namespace Cake\Http\Client\Auth;

use Cake\Core\Exception\Exception;
use Cake\Network\Http\Request;
use Cake\Http\Client\Request;

/**
* Oauth 1 authentication strategy for Cake\Network\Http\Client
Expand Down
Expand Up @@ -11,7 +11,9 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Network\Http;
namespace Cake\Http\Client;

use Cake\Http\Client\Response;

/**
* Container class for cookies used in Http\Client.
Expand Down
13 changes: 6 additions & 7 deletions src/Network/Http/FormData.php → src/Http/Client/FormData.php
Expand Up @@ -11,9 +11,9 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Network\Http;
namespace Cake\Http\Client;

use Cake\Network\Http\FormData\Part;
use Cake\Http\Client\FormDataPart;
use Countable;
use finfo;

Expand All @@ -23,7 +23,6 @@
*
* Used by Http\Client to upload POST/PUT data
* and files.
*
*/
class FormData implements Countable
{
Expand Down Expand Up @@ -75,11 +74,11 @@ public function boundary()
*
* @param string $name The name of the part.
* @param string $value The value to add.
* @return \Cake\Network\Http\FormData\Part
* @return \Cake\Network\Http\FormDataPart
*/
public function newPart($name, $value)
{
return new Part($name, $value);
return new FormDataPart($name, $value);
}

/**
Expand Down Expand Up @@ -109,7 +108,7 @@ public function add($name, $value = null)
E_USER_DEPRECATED
);
$this->_parts[] = $this->addFile($name, $value);
} elseif ($name instanceof Part && $value === null) {
} elseif ($name instanceof FormDataPart && $value === null) {
$this->_hasComplexPart = true;
$this->_parts[] = $name;
} else {
Expand Down Expand Up @@ -140,7 +139,7 @@ public function addMany(array $data)
*
* @param string $name The name to use.
* @param mixed $value Either a string filename, or a filehandle.
* @return \Cake\Network\Http\FormData\Part
* @return \Cake\Network\Http\FormDataPart
*/
public function addFile($name, $value)
{
Expand Down
Expand Up @@ -11,16 +11,18 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Network\Http\FormData;
namespace Cake\Http\Client;

/**
* Contains the data and behavior for a single
* part in a Multipart FormData request body.
*
* Added to Cake\Network\Http\FormData when sending
* data to a remote server.
*
* @internal
*/
class Part
class FormDataPart
{

/**
Expand Down
Expand Up @@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Network\Http;
namespace Cake\Http\Client;

/**
* Base class for other HTTP requests/responses
Expand Down
3 changes: 2 additions & 1 deletion src/Network/Http/Request.php → src/Http/Client/Request.php
Expand Up @@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Network\Http;
namespace Cake\Http\Client;

use Cake\Core\Exception\Exception;

Expand All @@ -20,6 +20,7 @@
*
* Used by Cake\Network\Http\Client to contain request information
* for making requests.
*
*/
class Request extends Message
{
Expand Down
Expand Up @@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Network\Http;
namespace Cake\Http\Client;

use RuntimeException;

Expand Down

0 comments on commit 5d866f0

Please sign in to comment.