|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Superdesk Web Publisher Content Bundle. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright 2018 Sourcefabric z.ú. and contributors. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please see the |
|
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
|
12
|
|
|
* |
|
13
|
|
|
* @copyright 2018 Sourcefabric z.ú |
|
14
|
|
|
* @license http://www.superdesk.org/license |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace SWP\Bundle\ContentBundle\Loader; |
|
18
|
|
|
|
|
19
|
|
|
use SWP\Component\Common\Criteria\Criteria; |
|
20
|
|
|
use SWP\Component\Storage\Repository\RepositoryInterface; |
|
21
|
|
|
use SWP\Component\TemplatesSystem\Gimme\Factory\MetaFactoryInterface; |
|
22
|
|
|
use SWP\Component\TemplatesSystem\Gimme\Loader\LoaderInterface; |
|
23
|
|
|
|
|
24
|
|
|
final class KeywordLoader extends PaginatedLoader implements LoaderInterface |
|
25
|
|
|
{ |
|
26
|
|
|
public const SUPPORTED_TYPES = ['keyword']; |
|
27
|
|
|
|
|
28
|
|
|
public const PARAM_NAME_SLUG = 'slug'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var MetaFactoryInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
private $metaFactory; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var RepositoryInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
private $keywordRepository; |
|
39
|
|
|
|
|
40
|
|
|
public function __construct( |
|
41
|
|
|
MetaFactoryInterface $metaFactory, |
|
42
|
|
|
RepositoryInterface $keywordRepository |
|
43
|
|
|
) { |
|
44
|
|
|
$this->metaFactory = $metaFactory; |
|
45
|
|
|
$this->keywordRepository = $keywordRepository; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function load($type, $parameters = [], $withoutParameters = [], $responseType = LoaderInterface::SINGLE) |
|
49
|
|
|
{ |
|
50
|
|
|
$criteria = new Criteria(); |
|
51
|
|
|
|
|
52
|
|
|
if (LoaderInterface::SINGLE === $responseType) { |
|
53
|
|
|
if (array_key_exists(self::PARAM_NAME_SLUG, $parameters) && \is_string($parameters[self::PARAM_NAME_SLUG])) { |
|
54
|
|
|
$criteria->set(self::PARAM_NAME_SLUG, $parameters[self::PARAM_NAME_SLUG]); |
|
55
|
|
|
} else { |
|
56
|
|
|
return false; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$keyword = $this->keywordRepository->findOneBySlug($parameters[self::PARAM_NAME_SLUG]); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
if (null !== $keyword) { |
|
62
|
|
|
return $this->metaFactory->create($keyword); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return false; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function isSupported(string $type): bool |
|
70
|
|
|
{ |
|
71
|
|
|
return \in_array($type, self::SUPPORTED_TYPES, true); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.