Skip to content

Commit

Permalink
update readme and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mimmi20 committed Dec 10, 2017
1 parent 656cd4d commit 2350ddd
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 54 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Expand Up @@ -15,6 +15,14 @@ cache:
- $TRAVIS_BUILD_DIR/resources
- $HOME/.composer/cache

stages:
- composer validate
- test
- test with coverage
- check coding style
- static code analysis
- compare results

before_install:
- .travis-scripts/cache-browscap.sh
- phpenv config-rm xdebug.ini || echo "xdebug not available"
Expand Down Expand Up @@ -51,6 +59,14 @@ jobs:
script: vendor/bin/phpunit -c phpunit.xml.dist --colors --verbose --exclude-group compare --coverage-text --coverage-clover=coverage.clover
after_success:
- wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover
- stage: composer validate
php: 7.1
before_install:
- phpenv config-rm xdebug.ini || echo "xdebug not available"
- echo 'opcache.enable=1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- echo 'opcache.enable_cli=1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
install: skip
script: composer validate --strict
- stage: check coding style
php: 7.1
env: COMPOSER_FLAGS=""
Expand Down
53 changes: 13 additions & 40 deletions README.md
Expand Up @@ -91,58 +91,33 @@ What's changed in version 3.x
Setup Examples
--------------

## Update your setup to version 3.x
## Update your setup to version 4.x

This is the base setup in version 2.x.
```php
// setup in version 2.x
$bc = new \phpbrowscap\Browscap($cacheDir);
$result = $bc->getBrowser();
```

Change this to the base setup for version 3.x. to use the v2 cache directory
This is the base setup in version 3.x.
```php
$bc = new \BrowscapPHP\Browscap();

$adapter = new \WurflCache\Adapter\File([\WurflCache\Adapter\File::DIR => $cacheDir]);
$bc->setCache($adapter);

$logger = new \Monolog\Logger('name');
$bc->setLogger($logger);

$result = $bc->getBrowser();
```

Note: In version 2.x a cache directory was required, but version 3.x has a default directory.
If you don't require a specific cache directory, the setup becomes more simple.
Change this to the base setup for version 4.x. to use the v3 cache directory
```php
$result = (new \BrowscapPHP\Browscap())->getBrowser();
```

## Setting up a logger

If you want to log something that happens with the detector you may set an logger.
This logger has to implement the PSR3 logger interface from [Psr\Log](https://github.com/php-fig/log)
$fileCache = new \Doctrine\Common\Cache\FilesystemCache($cacheDir);
$cache = new \Roave\DoctrineSimpleCache\SimpleCacheAdapter($fileCache);

```php
$bc = new \BrowscapPHP\Browscap();
$logger = new \Monolog\Logger('name');
$bc->setLogger($logger);
```

## Setting up a Memcache

If you don't want to use a file cache, you may change the cache adapter.
This cache adapter has to implement the adapter interface from WurflCache\Adapter\AdapterInterface
```php
$memcacheConfiguration = [
'host' => '127.0.0.1', // optional, defaults to '127.0.0.1'
'port' => 11211, // optional, defaults to 11211
'namespace' => 'wurfl', // optional, defaults to 'wurfl'
'cacheExpiration' => 0, // optional, defaults to 0 (cache does not expire), expiration time in seconds
'cacheVersion' => '1234', // optional, default value may change in external library
];
$adapter = new \WurflCache\Adapter\Memcached($memcacheConfiguration);
$bc = new \BrowscapPHP\Browscap();
$bc->setCache($adapter);
$bc = new \BrowscapPHP\Browscap($cache, $logger);
$result = $bc->getBrowser();
```

NOTE: Please look into the [WurflCache](https://github.com/mimmi20/WurflCache) package for infomation about the other cache adapters.
NOTE: You may use any other cache which implements the [PSR-16](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-16-simple-cache.md) interface.

## Using the full browscap.ini file

Expand Down Expand Up @@ -188,8 +163,6 @@ $current_browser = $bc->getBrowser($the_user_agent);
the CLI commands
----------------

In version 3 some CLI commands were added.

NOTE: If you don't want to use a file cache, you could not use the CLI commands. It is not possible to use other caches there at the moment.
NOTE: Each operation (fetch, update, check-update) which fetches data from the remote host browscap.org may run into the
rate limit of that site. If this happens an Exception is thrown.
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Expand Up @@ -28,17 +28,17 @@
"psr/simple-cache": "^1.0",
"roave/doctrine-simplecache": "^1.1",
"guzzlehttp/guzzle": "^6.2",
"symfony/filesystem": "^3.3 || ^4.0",
"symfony/finder": "^3.3 || ^4.0",
"symfony/console": "^3.3 || ^4.0",
"symfony/filesystem": "^3.3||^4.0",
"symfony/finder": "^3.3||^4.0",
"symfony/console": "^3.3||^4.0",
"monolog/monolog": "^1.23"
},
"require-dev": {
"phpunit/phpunit": "^6.3",
"phpunit/phpunit": "^6.5",
"mikey179/vfsStream": "^1.6",
"squizlabs/php_codesniffer": "^3.1",
"friendsofphp/php-cs-fixer": "^2.7",
"phpstan/phpstan": "^0.8.5"
"friendsofphp/php-cs-fixer": "^2.9",
"phpstan/phpstan": "^0.9"
},
"suggest": {
"ext-curl": "to use curl requests to get the ini file"
Expand Down
3 changes: 1 addition & 2 deletions phpstan.neon
Expand Up @@ -6,5 +6,4 @@ parameters:
- */tests/*/data/*
- */tests/*/Full2Test.php
ignoreErrors:
- '~PHPUnit_Framework_MockObject_MockObject~'
- '~Strict comparison using === between true and false will always evaluate to false~'
- '~MockObject~'
2 changes: 1 addition & 1 deletion src/BrowscapUpdater.php
Expand Up @@ -32,7 +32,7 @@ final class BrowscapUpdater implements BrowscapUpdaterInterface
private $cache;

/**
* @var @var \Psr\Log\LoggerInterface
* @var \Psr\Log\LoggerInterface
*/
private $logger;

Expand Down
2 changes: 1 addition & 1 deletion src/Cache/BrowscapCache.php
Expand Up @@ -136,7 +136,7 @@ public function getType() : ?string
*
* @param string $cacheId
* @param bool $withVersion
* @param bool &$success
* @param bool $success
*
* @throws \Psr\SimpleCache\InvalidArgumentException
*
Expand Down
2 changes: 1 addition & 1 deletion src/Command/LogfileCommand.php
Expand Up @@ -134,7 +134,7 @@ protected function execute(InputInterface $input, OutputInterface $output) : voi
$collection = ReaderFactory::factory();
$fs = new Filesystem();

/** @var $file \Symfony\Component\Finder\SplFileInfo */
/** @var \Symfony\Component\Finder\SplFileInfo $file */
foreach ($this->getFiles($input) as $file) {
$this->uas = [];
$path = $this->getPath($file);
Expand Down
2 changes: 0 additions & 2 deletions src/Helper/ConverterInterface.php
Expand Up @@ -42,8 +42,6 @@ public function getIniVersion(string $iniString) : int;
* sets the version
*
* @param int $version
*
* @return ConverterInterface
*/
public function setVersion(int $version) : void;

Expand Down
2 changes: 1 addition & 1 deletion src/Parser/Helper/Pattern.php
Expand Up @@ -69,7 +69,7 @@ public static function getHashForPattern(string $pattern, bool $variants = false
/**
* returns a hash for one pattern
*
* @param $pattern
* @param string $pattern
*
* @return string
*/
Expand Down

0 comments on commit 2350ddd

Please sign in to comment.