1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\URLChecker\Handler; |
8
|
|
|
|
9
|
|
|
use DateTime; |
10
|
|
|
use Exception; |
11
|
|
|
use eZ\Bundle\EzPublishCoreBundle\URLChecker\URLHandlerInterface; |
12
|
|
|
use eZ\Publish\API\Repository\URLService; |
13
|
|
|
use eZ\Publish\API\Repository\Values\URL\URL; |
14
|
|
|
use Psr\Log\LoggerAwareTrait; |
15
|
|
|
use Psr\Log\NullLogger; |
16
|
|
|
|
17
|
|
|
abstract class AbstractURLHandler implements URLHandlerInterface |
18
|
|
|
{ |
19
|
|
|
use LoggerAwareTrait; |
20
|
|
|
|
21
|
|
|
/** @var \eZ\Publish\API\Repository\URLService */ |
22
|
|
|
protected $urlService; |
23
|
|
|
|
24
|
|
|
/** @var array */ |
25
|
|
|
protected $options; |
26
|
|
|
|
27
|
|
|
public function __construct(URLService $urlService) |
28
|
|
|
{ |
29
|
|
|
$this->logger = new NullLogger(); |
30
|
|
|
$this->urlService = $urlService; |
31
|
|
|
$this->options = $this->getOptionsResolver()->resolve(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns options resolver. |
36
|
|
|
* |
37
|
|
|
* @return \Symfony\Component\OptionsResolver\OptionsResolver |
38
|
|
|
*/ |
39
|
|
|
abstract protected function getOptionsResolver(); |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function setOptions(array $options = null) |
45
|
|
|
{ |
46
|
|
|
if ($options === null) { |
47
|
|
|
$options = []; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$this->options = $this->getOptionsResolver()->resolve($options); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Sets URL status. |
55
|
|
|
* |
56
|
|
|
* @param \eZ\Publish\API\Repository\Values\URL\URL $url |
57
|
|
|
* @param bool $isValid |
58
|
|
|
*/ |
59
|
|
|
protected function setUrlStatus(URL $url, $isValid) |
60
|
|
|
{ |
61
|
|
|
try { |
62
|
|
|
$updateStruct = $this->urlService->createUpdateStruct(); |
63
|
|
|
$updateStruct->isValid = $isValid; |
64
|
|
|
$updateStruct->lastChecked = new DateTime(); |
65
|
|
|
|
66
|
|
|
$this->urlService->updateUrl($url, $updateStruct); |
67
|
|
|
|
68
|
|
|
$this->logger->info(sprintf('URL id = %d (%s) was checked (valid = %s)', $url->id, $url->url, (int) $isValid)); |
|
|
|
|
69
|
|
|
} catch (Exception $e) { |
70
|
|
|
$this->logger->error(sprintf('Cannot update URL id = %d status: %s', $url->id, $url->url)); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.