Skip to content

Commit

Permalink
[Encapsulation] Move everything from protected to private (except for…
Browse files Browse the repository at this point in the history
… entry point)
  • Loading branch information
GeLoLabs committed Nov 7, 2014
1 parent 83e1c99 commit 6e10883
Show file tree
Hide file tree
Showing 87 changed files with 386 additions and 328 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# UPGRADE

### 0.5 to 0.6

* All protected properties and methods have been updated to private except for entry points. This is mostly motivated
for enforcing the encapsulation and easing backward compatibility.

### 0.4 to 0.5

* The `Ivory\HttpAdapter\Guzzle3HttpAdapter` has been renamed to `Ivory\HttpAdapter\GuzzleHttpAdapter` and its name
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "0.5-dev"
"dev-master": "0.6-dev"
}
}
}
46 changes: 23 additions & 23 deletions src/AbstractCurlHttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ protected function prepareContent(InternalRequestInterface $internalRequest)
return $content;
}

/**
* Creates a file.
*
* @param string $file The file.
*
* @return mixed The created file.
*/
protected function createFile($file)
{
return $this->isSafeUpload() ? new \CurlFile($file) : '@'.$file;
}

/**
* Checks if it is safe upload.
*
* @return boolean TRUE if it is safe upload else FALSE.
*/
protected function isSafeUpload()
{
return defined('CURLOPT_SAFE_UPLOAD');
}

/**
* Prepares the raw content.
*
Expand All @@ -86,7 +108,7 @@ protected function prepareContent(InternalRequestInterface $internalRequest)
*
* @return array The prepared raw content.
*/
protected function prepareRawContent($name, $data, $isFile = false)
private function prepareRawContent($name, $data, $isFile = false)
{
if (is_array($data)) {
$preparedData = array();
Expand All @@ -103,26 +125,4 @@ protected function prepareRawContent($name, $data, $isFile = false)

return array($name => $isFile ? $this->createFile($data) : $data);
}

/**
* Creates a file.
*
* @param string $file The file.
*
* @return mixed The created file.
*/
protected function createFile($file)
{
return $this->isSafeUpload() ? new \CurlFile($file) : '@'.$file;
}

/**
* Checks if it is safe upload.
*
* @return boolean TRUE if it is safe upload else FALSE.
*/
protected function isSafeUpload()
{
return defined('CURLOPT_SAFE_UPLOAD');
}
}
64 changes: 32 additions & 32 deletions src/AbstractHttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
abstract class AbstractHttpAdapter implements HttpAdapterInterface
{
/** @var \Ivory\HttpAdapter\ConfigurationInterface */
protected $configuration;
private $configuration;

/**
* Creates an http adapter.
Expand Down Expand Up @@ -273,37 +273,6 @@ protected function prepareBody(InternalRequestInterface $internalRequest)
return $body;
}

/**
* Prepares the raw body.
*
* @param string $name The name.
* @param array|string $data The data.
* @param boolean $isFile TRUE if the data is a file path else FALSE.
*
* @return string The formatted raw body.
*/
protected function prepareRawBody($name, $data, $isFile = false)
{
if (is_array($data)) {
$body = '';

foreach ($data as $subName => $subData) {
$body .= $this->prepareRawBody($this->prepareName($name, $subName), $subData, $isFile);
}

return $body;
}

$body = '--'.$this->configuration->getBoundary()."\r\n".'Content-Disposition: form-data; name="'.$name.'"';

if ($isFile) {
$body .= '; filename="'.basename($data).'"';
$data = file_get_contents($data);
}

return $body."\r\n\r\n".$data."\r\n";
}

/**
* Prepares the name.
*
Expand Down Expand Up @@ -346,4 +315,35 @@ protected function createResponse(
$parameters
);
}

/**
* Prepares the raw body.
*
* @param string $name The name.
* @param array|string $data The data.
* @param boolean $isFile TRUE if the data is a file path else FALSE.
*
* @return string The formatted raw body.
*/
private function prepareRawBody($name, $data, $isFile = false)
{
if (is_array($data)) {
$body = '';

foreach ($data as $subName => $subData) {
$body .= $this->prepareRawBody($this->prepareName($name, $subName), $subData, $isFile);
}

return $body;
}

$body = '--'.$this->configuration->getBoundary()."\r\n".'Content-Disposition: form-data; name="'.$name.'"';

if ($isFile) {
$body .= '; filename="'.basename($data).'"';
$data = file_get_contents($data);
}

return $body."\r\n\r\n".$data."\r\n";
}
}
2 changes: 1 addition & 1 deletion src/AbstractStreamHttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function doSend(InternalRequestInterface $internalRequest)
'follow_location' => false,
'max_redirects' => 1,
'ignore_errors' => true,
'timeout' => $this->configuration->getTimeout(),
'timeout' => $this->getConfiguration()->getTimeout(),
'protocol_version' => $internalRequest->getProtocolVersion(),
'method' => $internalRequest->getMethod(),
'header' => $this->prepareHeaders($internalRequest, false),
Expand Down
4 changes: 2 additions & 2 deletions src/BuzzHttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class BuzzHttpAdapter extends AbstractCurlHttpAdapter
{
/** @var \Buzz\Browser */
protected $browser;
private $browser;

/**
* Creates a buzz http adapter.
Expand Down Expand Up @@ -65,7 +65,7 @@ public function getName()
*/
protected function doSend(InternalRequestInterface $internalRequest)
{
$this->browser->getClient()->setTimeout($this->configuration->getTimeout());
$this->browser->getClient()->setTimeout($this->getConfiguration()->getTimeout());
$this->browser->getClient()->setMaxRedirects(0);

$url = (string) $internalRequest->getUrl();
Expand Down
16 changes: 8 additions & 8 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@
class Configuration implements ConfigurationInterface
{
/** @var \Ivory\HttpAdapter\Message\MessageFactoryInterface */
protected $messageFactory;
private $messageFactory;

/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */
protected $eventDispatcher;
private $eventDispatcher;

/** @var string */
protected $protocolVersion = MessageInterface::PROTOCOL_VERSION_1_1;
private $protocolVersion = MessageInterface::PROTOCOL_VERSION_1_1;

/** @var boolean */
protected $keepAlive = false;
private $keepAlive = false;

/** @var string|null */
protected $encodingType;
private $encodingType;

/** @var string */
protected $boundary;
private $boundary;

/** @var float */
protected $timeout = 10;
private $timeout = 10;

/** @var string */
protected $userAgent = 'Ivory Http Adapter';
private $userAgent = 'Ivory Http Adapter';

/**
* Creates an http adapter.
Expand Down
4 changes: 2 additions & 2 deletions src/CurlHttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ protected function doSend(InternalRequestInterface $internalRequest)
private function configureTimeout($curl, $type)
{
if (defined($type.'_MS')) {
curl_setopt($curl, constant($type.'_MS'), $this->configuration->getTimeout() * 1000);
curl_setopt($curl, constant($type.'_MS'), $this->getConfiguration()->getTimeout() * 1000);
} else { // @codeCoverageIgnoreStart
curl_setopt($curl, constant($type), $this->configuration->getTimeout());
curl_setopt($curl, constant($type), $this->getConfiguration()->getTimeout());
} // @codeCoverageIgnoreEnd
}
}
4 changes: 2 additions & 2 deletions src/Event/AbstractEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
abstract class AbstractEvent extends Event
{
/** @var \Ivory\HttpAdapter\HttpAdapterInterface */
protected $httpAdapter;
private $httpAdapter;

/** @var \Ivory\HttpAdapter\Message\InternalRequestInterface */
protected $request;
private $request;

/**
* Creates a pre send event.
Expand Down
10 changes: 5 additions & 5 deletions src/Event/Cookie/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
class Cookie implements CookieInterface
{
/** @var string|null */
protected $name;
private $name;

/** @var string|null */
protected $value;
private $value;

/** @var array */
protected $attributes;
private $attributes;

/** @var integer */
protected $createdAt;
private $createdAt;

/**
* Creates a cookie.
Expand Down Expand Up @@ -315,7 +315,7 @@ public function __toString()
*
* @return string The fixes attribute.
*/
protected function fixAttribute($attribute)
private function fixAttribute($attribute)
{
return strtolower(trim($attribute));
}
Expand Down
8 changes: 4 additions & 4 deletions src/Event/Cookie/Jar/AbstractPersistentCookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ public function unserialize($serialized)
$data = json_decode($serialized, true);

if (empty($data)) {
$this->cookies = array();
$this->clear();
} else {
$cookieFactory = $this->cookieFactory;
$cookieFactory = $this->getCookieFactory();

$this->cookies = array_map(function (array $cookie) use ($cookieFactory) {
$this->setCookies(array_map(function (array $cookie) use ($cookieFactory) {
return $cookieFactory->create(
$cookie['name'],
$cookie['value'],
$cookie['attributes'],
$cookie['created_at']
);
}, $data);
}, $data));
}
}
}
4 changes: 2 additions & 2 deletions src/Event/Cookie/Jar/CookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
class CookieJar implements CookieJarInterface
{
/** @var \Ivory\HttpAdapter\Event\Cookie\CookieFactoryInterface */
protected $cookieFactory;
private $cookieFactory;

/** @var array */
protected $cookies = array();
private $cookies = array();

/**
* Creates a cookie jar.
Expand Down
2 changes: 1 addition & 1 deletion src/Event/Cookie/Jar/FileCookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class FileCookieJar extends AbstractPersistentCookieJar
{
/** @var string */
protected $file;
private $file;

/**
* Creates a file cookie jar.
Expand Down
2 changes: 1 addition & 1 deletion src/Event/Cookie/Jar/SessionCookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class SessionCookieJar extends AbstractPersistentCookieJar
{
/** @var string */
protected $key;
private $key;

/**
* Creates a session cookie jar.
Expand Down
4 changes: 2 additions & 2 deletions src/Event/ExceptionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
class ExceptionEvent extends AbstractEvent
{
/** @var \Ivory\HttpAdapter\HttpAdapterException */
protected $exception;
private $exception;

/** @var \Ivory\HttpAdapter\Message\ResponseInterface|null */
protected $response;
private $response;

/**
* Creates an exception event.
Expand Down
6 changes: 3 additions & 3 deletions src/Event/History/Journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
class Journal implements JournalInterface
{
/** @var \Ivory\HttpAdapter\Event\History\JournalEntryFactoryInterface */
protected $journalEntryFactory;
private $journalEntryFactory;

/** @var array */
protected $entries = array();
private $entries = array();

/** @var integer */
protected $limit = 10;
private $limit = 10;

/**
* Creates a journal.
Expand Down
6 changes: 3 additions & 3 deletions src/Event/History/JournalEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
class JournalEntry implements JournalEntryInterface
{
/** @var \Ivory\HttpAdapter\Message\InternalRequestInterface */
protected $request;
private $request;

/** @var \Ivory\HttpAdapter\Message\ResponseInterface */
protected $response;
private $response;

/** @var float */
protected $time;
private $time;

/**
* Creates a journal entry.
Expand Down
2 changes: 1 addition & 1 deletion src/Event/PostSendEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class PostSendEvent extends AbstractEvent
{
/** @var \Ivory\HttpAdapter\Message\ResponseInterface */
protected $response;
private $response;

/**
* Creates a post send event.
Expand Down

0 comments on commit 6e10883

Please sign in to comment.