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 2016 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 2016 Sourcefabric z.ú |
14
|
|
|
* @license http://www.superdesk.org/license |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace SWP\Bundle\ContentBundle\Loader; |
18
|
|
|
|
19
|
|
|
use SWP\Component\TemplatesSystem\Gimme\Factory\MetaFactoryInterface; |
20
|
|
|
use SWP\Component\TemplatesSystem\Gimme\Loader\LoaderInterface; |
21
|
|
|
use SWP\Component\TemplatesSystem\Gimme\Meta\Meta; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class RouteLoader. |
25
|
|
|
*/ |
26
|
|
|
class RouteLoader implements LoaderInterface |
27
|
|
|
{ |
28
|
|
|
const SUPPORTED_TYPE = 'route'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var MetaFactoryInterface |
32
|
|
|
*/ |
33
|
|
|
protected $metaFactory; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* RouteLoader constructor. |
37
|
|
|
* |
38
|
|
|
* @param MetaFactoryInterface $metaFactory |
39
|
|
|
*/ |
40
|
73 |
|
public function __construct(MetaFactoryInterface $metaFactory) |
41
|
|
|
{ |
42
|
73 |
|
$this->metaFactory = $metaFactory; |
43
|
73 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Load meta object by provided type and parameters. |
47
|
|
|
* |
48
|
|
|
* @MetaLoaderDoc( |
49
|
|
|
* description="Article Loader loads articles from Content Repository", |
50
|
|
|
* parameters={ |
51
|
|
|
* route_object="SINGLE|required route object" |
52
|
|
|
* } |
53
|
|
|
* ) |
54
|
|
|
* |
55
|
|
|
* @param string $type object type |
56
|
|
|
* @param array $parameters parameters needed to load required object type |
57
|
|
|
* @param int $responseType response type: single meta (LoaderInterface::SINGLE) |
58
|
|
|
* |
59
|
|
|
* @return Meta|bool false if meta cannot be loaded, a Meta instance otherwise |
60
|
|
|
*/ |
61
|
8 |
|
public function load($type, $parameters = [], $responseType = LoaderInterface::SINGLE) |
62
|
|
|
{ |
63
|
8 |
|
$route = isset($parameters['route_object']) ? $parameters['route_object'] : null; |
64
|
|
|
|
65
|
8 |
|
if (null !== $route) { |
66
|
8 |
|
return $this->metaFactory->create($route); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Checks if Loader supports provided type. |
74
|
|
|
* |
75
|
|
|
* @param string $type |
76
|
|
|
* |
77
|
|
|
* @return bool |
78
|
|
|
*/ |
79
|
8 |
|
public function isSupported(string $type) : bool |
80
|
|
|
{ |
81
|
8 |
|
return self::SUPPORTED_TYPE === $type; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|