-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,177 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Ivory Http Adapter package. | ||
* | ||
* (c) Eric GELOEN <geloen.eric@gmail.com> | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Ivory\HttpAdapter; | ||
|
||
use Ivory\HttpAdapter\Message\RequestInterface; | ||
|
||
/** | ||
* Abstract http adapter template. | ||
* | ||
* @author GeLo <geloen.eric@gmail.com> | ||
*/ | ||
abstract class AbstractHttpAdapterTemplate implements HttpAdapterInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function get($url, array $headers = array()) | ||
{ | ||
return $this->send($url, RequestInterface::METHOD_GET, $headers); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function head($url, array $headers = array()) | ||
{ | ||
return $this->send($url, RequestInterface::METHOD_HEAD, $headers); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function trace($url, array $headers = array()) | ||
{ | ||
return $this->send($url, RequestInterface::METHOD_TRACE, $headers); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function post($url, array $headers = array(), $datas = array(), array $files = array()) | ||
{ | ||
return $this->send($url, RequestInterface::METHOD_POST, $headers, $datas, $files); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function put($url, array $headers = array(), $datas = array(), array $files = array()) | ||
{ | ||
return $this->send($url, RequestInterface::METHOD_PUT, $headers, $datas, $files); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function patch($url, array $headers = array(), $datas = array(), array $files = array()) | ||
{ | ||
return $this->send($url, RequestInterface::METHOD_PATCH, $headers, $datas, $files); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function delete($url, array $headers = array(), $datas = array(), array $files = array()) | ||
{ | ||
return $this->send($url, RequestInterface::METHOD_DELETE, $headers, $datas, $files); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function options($url, array $headers = array(), $datas = array(), array $files = array()) | ||
{ | ||
return $this->send($url, RequestInterface::METHOD_OPTIONS, $headers, $datas, $files); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Ivory Http Adapter package. | ||
* | ||
* (c) Eric GELOEN <geloen.eric@gmail.com> | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Ivory\HttpAdapter\Event\Subscriber; | ||
|
||
use Ivory\HttpAdapter\Event\ExceptionEvent; | ||
use Ivory\HttpAdapter\Event\PostSendEvent; | ||
use Ivory\HttpAdapter\HttpAdapterException; | ||
use Ivory\HttpAdapter\Message\InternalRequestInterface; | ||
use Ivory\HttpAdapter\Message\ResponseInterface; | ||
|
||
/** | ||
* Abstract debugger subscriber. | ||
* | ||
* @author GeLo <geloen.eric@gmail.com> | ||
*/ | ||
abstract class AbstractDebuggerSubscriber extends AbstractTimerSubscriber | ||
{ | ||
/** | ||
* On post send event. | ||
* | ||
* @param \Ivory\HttpAdapter\Event\PostSendEvent $event The post send event. | ||
* | ||
* @return array The formatted event. | ||
*/ | ||
public function onPostSend(PostSendEvent $event) | ||
{ | ||
return array( | ||
'time' => parent::onPostSend($event), | ||
'adapter' => $event->getHttpAdapter()->getName(), | ||
'request' => $this->formatRequest($event->getRequest()), | ||
'response' => $this->formatResponse($event->getResponse()), | ||
); | ||
} | ||
|
||
/** | ||
* On exception event. | ||
* | ||
* @param \Ivory\HttpAdapter\Event\ExceptionEvent $event The exception event. | ||
* | ||
* @return array The formatted event. | ||
*/ | ||
public function onException(ExceptionEvent $event) | ||
{ | ||
return array( | ||
'time' => parent::onException($event), | ||
'adapter' => $event->getHttpAdapter()->getName(), | ||
'request' => $this->formatRequest($event->getRequest()), | ||
'exception' => $this->formatException($event->getException()), | ||
); | ||
} | ||
|
||
/** | ||
* Formats the request. | ||
* | ||
* @param \Ivory\HttpAdapter\Message\InternalRequestInterface $request The request. | ||
* | ||
* @return array The formatted request. | ||
*/ | ||
private function formatRequest(InternalRequestInterface $request) | ||
{ | ||
return array( | ||
'protocol_version' => $request->getProtocolVersion(), | ||
'url' => (string) $request->getUrl(), | ||
'method' => $request->getMethod(), | ||
'headers' => $request->getHeaders(), | ||
'raw_datas' => $request->getRawDatas(), | ||
'datas' => $request->getDatas(), | ||
'files' => $request->getFiles(), | ||
'parameters' => $request->getParameters(), | ||
); | ||
} | ||
|
||
/** | ||
* Formats the response. | ||
* | ||
* @param \Ivory\HttpAdapter\Message\ResponseInterface $response The response. | ||
* | ||
* @return array The formatted response. | ||
*/ | ||
private function formatResponse(ResponseInterface $response) | ||
{ | ||
return array( | ||
'protocol_version' => $response->getProtocolVersion(), | ||
'status_code' => $response->getStatusCode(), | ||
'reason_phrase' => $response->getReasonPhrase(), | ||
'headers' => $response->getHeaders(), | ||
'body' => (string) $response->getBody(), | ||
'parameters' => $response->getParameters(), | ||
); | ||
} | ||
|
||
/** | ||
* Formats the exception. | ||
* | ||
* @param \Ivory\HttpAdapter\HttpAdapterException $exception The exception. | ||
* | ||
* @return array The formatted exception. | ||
*/ | ||
private function formatException(HttpAdapterException $exception) | ||
{ | ||
return array( | ||
'code' => $exception->getCode(), | ||
'message' => $exception->getMessage(), | ||
'line' => $exception->getLine(), | ||
'file' => $exception->getFile(), | ||
); | ||
} | ||
} |
Oops, something went wrong.