-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8977f2
commit 00ff590
Showing
15 changed files
with
240 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Nelmio\SecurityBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
|
||
class UAParserCompilerPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasParameter('nelmio_browser_adaptive_parser')) { | ||
return; | ||
} | ||
|
||
$container | ||
->getDefinition('nelmio_security.ua_parser') | ||
->setArguments(array($container->getDefinition($container->getParameter('nelmio_browser_adaptive_parser')))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Nelmio SecurityBundle. | ||
* | ||
* (c) Nelmio <hello@nelm.io> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\SecurityBundle\UserAgent\UAFamilyParser; | ||
|
||
use Doctrine\Common\Cache\Cache; | ||
|
||
class DoctrineCacheUAFamilyParser implements UAFamilyParserInterface | ||
{ | ||
private $cache; | ||
private $parser; | ||
private $lifetime; | ||
private $prefix; | ||
|
||
public function __construct(Cache $cache, UAFamilyParser $parser, $lifetime = 0, $prefix = 'nelmio-ua-parser-') | ||
{ | ||
$this->parser = $parser; | ||
$this->cache = $cache; | ||
$this->lifetime = $lifetime; | ||
$this->prefix = $prefix; | ||
} | ||
|
||
public function getUaFamily($userAgent) | ||
{ | ||
$id = $this->prefix.md5($userAgent); | ||
|
||
if (false !== $name = $this->cache->fetch($id)) { | ||
return $name; | ||
} | ||
|
||
$name = $this->parser->getUaFamily($userAgent); | ||
|
||
$this->cache->save($id, $name, $this->lifetime); | ||
|
||
return $name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Nelmio SecurityBundle. | ||
* | ||
* (c) Nelmio <hello@nelm.io> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\SecurityBundle\UserAgent\UAFamilyParser; | ||
|
||
use Psr\Cache\CacheItemPoolInterface; | ||
use Psr\Cache\CacheException; | ||
|
||
class PsrCacheUAFamilyParser implements UAFamilyParserInterface | ||
{ | ||
private $cache; | ||
private $parser; | ||
private $lifetime; | ||
private $prefix; | ||
|
||
public function __construct(CacheItemPoolInterface $cache, UAFamilyParser $parser, $lifetime = 0, $prefix = 'nelmio-ua-parser-') | ||
{ | ||
$this->parser = $parser; | ||
$this->cache = $cache; | ||
$this->lifetime = $lifetime; | ||
$this->prefix = $prefix; | ||
} | ||
|
||
public function getUaFamily($userAgent) | ||
{ | ||
$id = $this->prefix.md5($userAgent); | ||
|
||
$item = $this->cache->getItem($id); | ||
|
||
if ($item->isHit()) { | ||
return $item->get(); | ||
} | ||
|
||
$name = $this->parser->getUaFamily($userAgent); | ||
|
||
$this->cache->save($item->set($name)->expiresAfter($this->lifetime)); | ||
|
||
return $name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Nelmio SecurityBundle. | ||
* | ||
* (c) Nelmio <hello@nelm.io> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\SecurityBundle\UserAgent\UAFamilyParser; | ||
|
||
use UAParser\Parser; | ||
|
||
class UAFamilyParser implements UAFamilyParserInterface | ||
{ | ||
private $parser; | ||
|
||
public function __construct(Parser $parser) | ||
{ | ||
$this->parser = $parser; | ||
} | ||
|
||
public function getUaFamily($userAgent) | ||
{ | ||
return strtolower($this->parser->parse($userAgent)->ua->family); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Nelmio SecurityBundle. | ||
* | ||
* (c) Nelmio <hello@nelm.io> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\SecurityBundle\UserAgent\UAFamilyParser; | ||
|
||
interface UAFamilyParserInterface | ||
{ | ||
public function getUaFamily($userAgent); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters