redirectionio / proxy-sdk
PHP common code for redirection.io proxy
Installs: 143 167
Dependents: 2
Suggesters: 0
Security: 0
Stars: 7
Watchers: 5
Forks: 1
Open Issues: 0
Requires
- php: >=5.6
- psr/log: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.10
- monolog/monolog: ^1.24
- symfony/phpunit-bridge: ^4.1
- symfony/process: ^3.4
README
[DEPRECATED]: This library is deprecated and will not be maintained anymore. It does not work with the current version of the redirection.io agent, but only with the legacy 1.x branch. We advise you to migrate and use one of the recommended integrations.
redirection.io is a tool to track HTTP errors and setup useful HTTP redirections. It listens your website's HTTP traffic and logs every HTTP errors, so you can check that the project's redirection rules apply efficiently.
Quick demo (see below for detailed info):
$client = new RedirectionIO\Client\Sdk\Client($projectKey, $connections); $request = new RedirectionIO\Client\Sdk\HttpMessage\Request( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'], $_SERVER['HTTP_USER_AGENT'], $_SERVER['HTTP_REFERER'] ); $response = $client->request(new RedirectionIO\Client\Sdk\Command\MatchWithResponseCommand($request)); // There are no redirection for this Request if (null === $response) { $response = '...'; // Handle your request with your application } $client->request(new RedirectionIO\Client\Sdk\Command\LogCommand($request, $response)); // Finally, Returns your response
Requirements
- Composer
- PHP 5.5+
Installation
To use redirection.io in your project, add it to your composer.json file:
$ composer require redirectionio/proxy-sdk
Usage
Instantiate Client
Before starting, you need to instantiate a new Client.
use RedirectionIO\Client\Sdk\Client; $client = new Client(string $projectKey, array $connections, int $timeout = 10000, bool $debug = false, LoggerInterface $logger = null);
Parameters:
$projectKey
your project key (can be found in redirection.io dashboard)$projectKey = 'szio2389-bfdz-51e8-8468-02dcop129501:ep6a4805-eo6z-dzo6-aeb0-8c1lbmo40242';
$connections
array of connection(s) parameters to the Agent(s)$connections = [ 'connection_tcp' => 'tcp://127.0.0.1:10301', 'connection_unix' => 'unix:///var/run/redirectionio_agent.sock', ];
$timeout
timeout in microsecond for connection/request;$debug
enable or disable debug mode. In debug mode an exception is thrown is something goes wrong, if not every errors is silenced;\Psr\Log\LoggerInterface $logger
A logger.
Find if a redirection rule exists
Check if request URI matches a redirect rule in the agent. If yes return a
RedirectResponse
, else return null
.
use RedirectionIO\Client\Sdk\Client; use RedirectionIO\Client\Sdk\HttpMessage\Request; use RedirectionIO\Client\Sdk\Command\MatchCommand; $client->request(new MatchWithResponseCommand(Request $request);
Parameter:
\RedirectionIO\Client\Sdk\HttpMessage\Request $request
.
Return values:
\RedirectionIO\Client\Sdk\HttpMessage\RedirectResponse $response
if agent has found a redirect rule for the current request uri;null
if there isn't redirect rule set for the current uri in the agent.
Find if a redirection rule exists for old agent (<1.4.0)
Check if request URI matches a redirect rule in the agent. If yes return a
RedirectResponse
, else return null
.
This will also return null if the rule should have been matched against a Response Status Code. This is mainly for BC Compatibility and avoid old proxy to handle rules that it should not.
use RedirectionIO\Client\Sdk\Client; use RedirectionIO\Client\Sdk\HttpMessage\Request; use RedirectionIO\Client\Sdk\Command\MatchCommand; $client->request(new MatchCommand(Request $request);
Parameter:
\RedirectionIO\Client\Sdk\HttpMessage\Request $request
.
Return values:
\RedirectionIO\Client\Sdk\HttpMessage\RedirectResponse $response
if agent has found a redirect rule for the current request uri;null
if there isn't redirect rule set for the current uri in the agent.
Log a request/response couple
Allow you to log a request/response couple for every request.
use RedirectionIO\Client\Sdk\Client; use RedirectionIO\Client\Sdk\Command\LogCommand; use RedirectionIO\Client\Sdk\HttpMessage\Response; use RedirectionIO\Client\Sdk\HttpMessage\Request; $client->request(new LogCommand(Request $request, Response $response));
Parameters:
\RedirectionIO\Client\Sdk\HttpMessage\Response $request
\RedirectionIO\Client\Sdk\HttpMessage\Request $response
Return value:
bool
istrue
if log has been successfully added, elsefalse
Contribution
We take care of all new PRs. Any contribution is welcome :) Thanks.
Install
$ composer install
Run tests
$ composer test