|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- /**
- * @author La clic ! <contact@laclic.fr>
- */
-
-
- namespace Lc\SovBundle\Resolver;
-
-
- use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
- use Symfony\Component\HttpFoundation\RequestStack;
-
- class UrlResolver
- {
- protected ParameterBagInterface $parameterBag;
- protected RequestStack $requestStack;
-
- public function __construct(ParameterBagInterface $parameterBag, RequestStack $requestStack)
- {
- $this->parameterBag = $parameterBag;
- $this->requestStack = $requestStack;
- }
-
- public function isServerLocalhost(): bool
- {
- return in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']);
- }
-
- public function isBot(): bool
- {
- if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match(
- '/bot|crawl|slurp|spider/i',
- $_SERVER['HTTP_USER_AGENT']
- )) {
- return true;
- } else {
- return false;
- }
- }
-
- public function isRouteAdmin(): bool
- {
- return $this->testRoute(['admin_', 'file_manager']);
- }
-
- public function isRouteLogin(): bool
- {
- return $this->testRoute(['sov_login', 'sov_logout', 'frontend_security_login']) ;
- }
-
- public function testRoute($mixed, $route = null): bool
- {
- if(is_null($route)) {
- $route = $this->getRouteCurrentRequest();
- }
-
- if(!$route) {
- return false;
- }
-
- if(is_array($mixed)) {
- foreach($mixed as $testRoute) {
- if($this->testRoute($testRoute, $route)) {
- return true;
- }
- }
-
- return false;
- }
-
- return strpos($route, $mixed) !== false;
- }
-
- public function getRouteCurrentRequest(): ?string
- {
- $requestAttributes = $this->requestStack->getCurrentRequest()->attributes->all();
- $route = isset($requestAttributes['_route']) ? $requestAttributes['_route'] : null;
-
- return $route;
- }
-
- }
|