user-agent/README.md

44 lines
1.1 KiB
Markdown
Raw Permalink Normal View History

2017-10-01 11:31:31 -07:00
# sikofitt/user-agent
Easily add a proper user agent to php projects that use Guzzle or Curl.
### Composer
`curl -LSs https://getcomposer.org/installer|php`
`composer.phar require sikofitt/user-agent:dev-master`
### Usage
```php
<?php declare(strict_types=1);
require __DIR__.'/../vendor/autoload.php';
use Sikofitt\UserAgent\UserAgent;
// Simple default example
$userAgent = UserAgent::create();
// PHP/7.1-70110 (sikofitt/user-agent; Linux x86_64) PHP/7.1.10-1+ubuntu17.04.1+deb.sury.org+1; guzzlehttp/6.2.1 curl/7.52.1 (https://packagist.org/sikofitt/user-agent)
// If guzzle is not installed the user agent would be -
// PHP/7.1-70110 (sikofitt/user-agent; Linux x86_64) PHP/7.1.10-1+ubuntu17.04.1+deb.sury.org+1; (https://packagist.org/sikofitt/user-agent)
// Extending
$ua = new class extends UserAgent {
protected static $format = 'PHP/%d.%d.%d';
protected static $params = [
PHP_MAJOR_VERSION,
PHP_MINOR_VERSION,
PHP_RELEASE_VERSION
];
};
$userAgent2 = $ua::create();
// PHP/7.1.10
```
### License
[GPL-3.0](https://repos.bgemi.net/sikofitt/user-agent/blob/master/LICENSE)
### Contribute
Go for it.