Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

URLChecker.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishCoreBundle\URLChecker;
8
9 use eZ\Publish\API\Repository\URLService as URLServiceInterface;
10 use eZ\Publish\API\Repository\Values\URL\SearchResult;
11 use eZ\Publish\API\Repository\Values\URL\URLQuery;
12 use Psr\Log\LoggerAwareTrait;
13 use Psr\Log\NullLogger;
14
15 class URLChecker implements URLCheckerInterface
16 {
17 use LoggerAwareTrait;
18
20 protected $urlService;
21
23 protected $handlerRegistry;
24
31 public function __construct(
32 URLServiceInterface $urlService,
33 URLHandlerRegistryInterface $handlerRegistry)
34 {
35 $this->urlService = $urlService;
36 $this->handlerRegistry = $handlerRegistry;
37 $this->logger = new NullLogger();
38 }
39
43 public function check(URLQuery $query)
44 {
45 $grouped = $this->fetchUrls($query);
46 foreach ($grouped as $scheme => $urls) {
47 if (!$this->handlerRegistry->supported($scheme)) {
48 $this->logger->error('Unsupported URL schema: ' . $scheme);
49 continue;
50 }
51
52 $handler = $this->handlerRegistry->getHandler($scheme);
53 $handler->validate($urls);
54 }
55 }
56
64 protected function fetchUrls(URLQuery $query)
65 {
66 return $this->groupByScheme(
67 $this->urlService->findUrls($query)
68 );
69 }
70
78 private function groupByScheme(SearchResult $urls)
79 {
80 $grouped = [];
81
82 foreach ($urls as $url) {
83 $scheme = parse_url($url->url, PHP_URL_SCHEME);
84 if (!$scheme) {
85 continue;
86 }
87
88 if (!isset($grouped[$scheme])) {
89 $grouped[$scheme] = [];
90 }
91
92 $grouped[$scheme][] = $url;
93 }
94
95 return $grouped;
96 }
97 }
eZ\Bundle\EzPublishCoreBundle\URLChecker\URLChecker
Definition: URLChecker.php:16
eZ\Bundle\EzPublishCoreBundle\URLChecker\URLChecker\check
check(URLQuery $query)
{Checks URLs returned by given query.}
Definition: URLChecker.php:43
eZ\Bundle\EzPublishCoreBundle\URLChecker\URLChecker\$urlService
$urlService
Definition: URLChecker.php:20
eZ\Bundle\EzPublishCoreBundle\URLChecker\URLChecker\__construct
__construct(URLServiceInterface $urlService, URLHandlerRegistryInterface $handlerRegistry)
URLChecker constructor.
Definition: URLChecker.php:31
eZ\Bundle\EzPublishCoreBundle\URLChecker\URLChecker\$handlerRegistry
$handlerRegistry
Definition: URLChecker.php:23
eZ\Bundle\EzPublishCoreBundle\URLChecker\URLChecker\fetchUrls
fetchUrls(URLQuery $query)
Fetch URLs to check.
Definition: URLChecker.php:64
eZ\Bundle\EzPublishCoreBundle\URLChecker\URLChecker\groupByScheme
groupByScheme(SearchResult $urls)
Group URLs by schema.
Definition: URLChecker.php:78
eZ\Publish\API\Repository\Values\URL\SearchResult
Definition: URL/SearchResult.php:13
eZ\Publish\API\Repository\Values\URL\URLQuery
This class is used to perform a URL query.
Definition: URLQuery.php:15
eZ\Bundle\EzPublishCoreBundle\URLChecker\URLCheckerInterface
Definition: URLCheckerInterface.php:12
eZ\Bundle\EzPublishCoreBundle\URLChecker\URLHandlerRegistryInterface
Definition: URLHandlerRegistryInterface.php:10
eZ\Publish\API\Repository\URLService
URL Service.
Definition: API/Repository/URLService.php:17
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.