Skip to content

Introduces configurable logic #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Configurable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Http Adapter package.
*
* (c) Eric GELOEN <[email protected]>
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*/

namespace Http\Adapter;

/**
* Allows to modify configuration
*
* @author Márk Sági-Kazár [email protected]>
*/
interface Configurable extends HasConfiguration
{
/**
* Sets an option
*
* @param string $name
* @param mixed $option
*/
public function setOption($name, $option);

/**
* Sets all options
*
* @param array $options
*/
public function setOptions(array $options);
}
163 changes: 163 additions & 0 deletions src/ConfigurableHttpAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?php

/*
* This file is part of the Http Adapter package.
*
* (c) Eric GELOEN <[email protected]>
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*/

namespace Http\Adapter;

use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
use Psr\Http\Message\ResponseInterface;

/**
* Allows request level configurations
*
* @author Márk Sági-Kazár [email protected]>
*/
interface ConfigurableHttpAdapter extends HttpAdapter
{
/**
* Sends a GET request
*
* @param string|UriInterface $uri
* @param string[] $headers
* @param array $options
*
* @throws \InvalidArgumentException
* @throws HttpAdapterException
*
* @return ResponseInterface
*/
public function get($uri, array $headers = [], array $options = []);

/**
* Sends an HEAD request
*
* @param string|UriInterface $uri
* @param string[] $headers
* @param array $options
*
* @throws \InvalidArgumentException
* @throws HttpAdapterException
*
* @return ResponseInterface
*/
public function head($uri, array $headers = [], array $options = []);

/**
* Sends a TRACE request
*
* @param string|UriInterface $uri
* @param string[] $headers
* @param array $options
*
* @throws \InvalidArgumentException
* @throws HttpAdapterException
*
* @return ResponseInterface
*/
public function trace($uri, array $headers = [], array $options = []);

/**
* Sends a POST request
*
* @param string|UriInterface $uri
* @param string[] $headers
* @param array|string|StreamInterface $data
* @param array $files
* @param array $options
*
* @throws \InvalidArgumentException
* @throws HttpAdapterException
*
* @return ResponseInterface
*/
public function post($uri, array $headers = [], $data = [], array $files = [], array $options = []);

/**
* Sends a PUT request
*
* @param string|UriInterface $uri
* @param string[] $headers
* @param array|string|StreamInterface $data
* @param array $files
* @param array $options
*
* @throws \InvalidArgumentException
* @throws HttpAdapterException
*
* @return ResponseInterface
*/
public function put($uri, array $headers = [], $data = [], array $files = [], array $options = []);

/**
* Sends a PATCH request
*
* @param string|UriInterface $uri
* @param string[] $headers
* @param array|string|StreamInterface $data
* @param array $files
* @param array $options
*
* @throws \InvalidArgumentException
* @throws HttpAdapterException
*
* @return ResponseInterface
*/
public function patch($uri, array $headers = [], $data = [], array $files = [], array $options = []);

/**
* Sends a DELETE request
*
* @param string|UriInterface $uri
* @param string[] $headers
* @param array|string|StreamInterface $data
* @param array $files
* @param array $options
*
* @throws \InvalidArgumentException
* @throws HttpAdapterException
*
* @return ResponseInterface
*/
public function delete($uri, array $headers = [], $data = [], array $files = [], array $options = []);

/**
* Sends an OPTIONS request
*
* @param string|UriInterface $uri
* @param string[] $headers
* @param array|string|StreamInterface $data
* @param array $files
* @param array $options
*
* @throws \InvalidArgumentException
* @throws HttpAdapterException
*
* @return ResponseInterface
*/
public function options($uri, array $headers = [], $data = [], array $files = [], array $options = []);

/**
* Sends a request
*
* @param string $method
* @param string|UriInterface $uri
* @param string[] $headers
* @param array|string|StreamInterface $data
* @param array $files
* @param array $options
*
* @throws \InvalidArgumentException
* @throws HttpAdapterException
*
* @return ResponseInterface
*/
public function send($method, $uri, array $headers = [], $data = [], array $files = [], array $options = []);
}
54 changes: 54 additions & 0 deletions src/HasConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/*
* This file is part of the Http Adapter package.
*
* (c) Eric GELOEN <[email protected]>
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*/

namespace Http\Adapter;

/**
* Allows global configurations
*
* This interface does not allow modifying options
*
* @author Márk Sági-Kazár [email protected]>
*/
interface HasConfiguration
{
/**
* Returns an option by name
*
* @param string $name
*
* @return mixed
*/
public function getOption($name);

/**
* Returns all options
*
* @return array
*/
public function getOptions();

/**
* Checks if an option exists
*
* @param string $name
*
* @return boolean
*/
public function hasOption($name);

/**
* Checks if any option exists
*
* @return boolean
*/
public function hasOptions();
}
42 changes: 42 additions & 0 deletions src/Message/ConfigurableRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the Http Adapter package.
*
* (c) Eric GELOEN <[email protected]>
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*/

namespace Http\Adapter\Message;

use Psr\Http\Message\RequestInterface;
use Psr\Http\HasConfiguration;

/**
* Allows to modify configuration in a request an immutable way
*
* @author Márk Sági-Kazár [email protected]>
*/
interface ConfigurableRequest extends RequestInterface, HasConfiguration
{
/**
* Sets an option
*
* @param string $name
* @param mixed $option
*
* @return self
*/
public function withOption($name, $option);

/**
* Removes an option
*
* @param string $name
*
* @return self
*/
public function withoutOption($name);
}
8 changes: 3 additions & 5 deletions src/Message/InternalRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@

namespace Http\Adapter\Message;

use Psr\Http\Message\RequestInterface;

/**
* @author GeLo <[email protected]>
*/
interface InternalRequest extends RequestInterface, ParameterableMessage
interface InternalRequest extends ConfigurableRequest, ParameterableMessage
{
/**
* Returns some data by name
Expand Down Expand Up @@ -89,14 +87,14 @@ public function withoutData($name);
public function getFile($name);

/**
* Returns the files
* Returns all files
*
* @return array
*/
public function getFiles();

/**
* Checks if the file exists
* Checks if a file exists
*
* @param string $name
*
Expand Down
4 changes: 2 additions & 2 deletions src/Message/ParameterableMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ interface ParameterableMessage
public function getParameter($name);

/**
* Returns the parameters
* Returns all parameters
*
* @return array
*/
public function getParameters();

/**
* Checks if the parameter exists
* Checks if a parameter exists
*
* @param string $name
*
Expand Down