Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ddrv/php-cpa-tds
The simple php traffic direction system
https://github.com/ddrv/php-cpa-tds
Last synced: 3 days ago
JSON representation
The simple php traffic direction system
- Host: GitHub
- URL: https://github.com/ddrv/php-cpa-tds
- Owner: ddrv
- License: mit
- Created: 2018-07-24T12:02:03.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-26T09:06:33.000Z (over 5 years ago)
- Last Synced: 2024-04-23T05:59:51.792Z (7 months ago)
- Language: PHP
- Size: 34.2 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Install
```
composer require cpa/tds /path/to/project
```# Add library
```php
click($request)->response()->out();
```# Configure
```php
path->links = '/path/to/links'; // path to compiled links classes. By default /path/to/project/data/links
$config->path->responses = '/path/to/responses'; // path to compiled responses classes. By default /path/to/project/data/responses
$config->path->tmp = '/path/to/temporary'; // path to compiled links classes. By default /tmp/*
* ------------------------------------
* Key (define link id).
* For example, link key = test
* ------------------------------------
*//*
* in path
* http://site.com/link/test/some/path/positions
* ^ ^ ^ ^ ^
* | | | | |
* position: 0 1 2 3 4
*
*/
$config->key->in = 'path';
$config->key->position = 1;/*
* in query
* http//site.com/go.php?query1=test&query2=2&query3=some-value
* ^ ^ ^
* | | |
* position: query1 query2 query3
*/
$config->key->in = 'query';
$config->key->position = 'query1';/*
* in subdomain
* http://tets.site.com/some/path
*/
$config->key->in = 'uri';
$config->key->position = 'host';
$config->key->pattern = '/^(?[a-z](a-z0-9\-)?)\./ui';
$config->key->match = 'link';/*
* ------------------------------------
* Traffic back (default response)
* ------------------------------------
*/
$config->trafficBack->status = 301;
$config->trafficBack->headers = ['location: https://google.com', 'content-type: text/plain'];
$config->trafficBack->body = 'redirect to google';$tds = new \Cpa\TDS\TDS($config);
```
## Adding responses
```php
storage()->response()->save($json);// save from file
file_put_contents('/path/to/project/data/responses/e404.json', $json);
$tds->storage()->response()->save('/path/to/project/data/responses/e404.json');
```## Adding links
```php
storage()->link()->save($json);// save from file
file_put_contents('/path/to/project/data/links/test.json', $json);
$tds->storage()->response()->save('/path/to/project/data/links/test.json');
```## AB tests
```php
storage()->response()->save($responseA);
$tds->storage()->response()->save($responseB);
$tds->storage()->link()->save($link);/*
* you nueno save links and responses ONLY when changing
*/
```## Traffic Rules
```php
array(
'type' => 'phone'
),
);
$body = file_get_contents('php://input');
$request = new \Cpa\TDS\Core\Request($_SERVER, $_GET, $body, $_COOKIE, $extends);$link = <<storage()->link()->save($link);
```
## Tokens
```php
storage()->response()->save($langSite);
$tds->storage()->response()->save($default);
// link
$link = << array(
'country' => 'en' // You must define it
),
);
$body = file_get_contents('php://input');
$request = new \Cpa\TDS\Core\Request($_SERVER, $_GET, $body, $_COOKIE, $extends);
$tds->storage()->link()->save($link);```
## Deleting responses and links
```php
storage()->response()->delete('response-a');
$tds->storage()->link()->delete('test');
```## Metrics
```php
click($request);/*
* You can process the request and response data
* $click->response()->key() - key of response
* $click->response()->body() - body of response
* $click->response()->headers(false) - array of response headers (for example, array('location: http://site.com'))
* $click->response()->headers(true) - assoc array of response headers (for example, array('location' => 'http://site.com'))
* $click->response()->status() - status of response
* (string)$request - raw data of request
* (string)$click->response() - raw data of response
* $click->criteria() - criteria of current rule
* $click->link() - link key
* $click->tokens() - associative array of tokens
*/$click->response()->out();
```