1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* AnimeDb package. |
4
|
|
|
* |
5
|
|
|
* @author Peter Gribanov <[email protected]> |
6
|
|
|
* @copyright Copyright (c) 2011, Peter Gribanov |
7
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace AnimeDb\Bundle\CatalogBundle\Plugin\Fill\Filler; |
11
|
|
|
|
12
|
|
|
use AnimeDb\Bundle\CatalogBundle\Plugin\Plugin; |
13
|
|
|
use Knp\Menu\ItemInterface; |
14
|
|
|
use AnimeDb\Bundle\CatalogBundle\Entity\Item; |
15
|
|
|
use AnimeDb\Bundle\CatalogBundle\Form\Type\Plugin\Filler as FillerForm; |
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Routing\Router; |
17
|
|
|
use AnimeDb\Bundle\CatalogBundle\Plugin\Fill\Search\Item as ItemSearch; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Plugin filler. |
21
|
|
|
* |
22
|
|
|
* @author Peter Gribanov <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
abstract class Filler extends Plugin implements FillerInterface |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var Router |
28
|
|
|
*/ |
29
|
|
|
protected $router; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param ItemInterface $item |
33
|
|
|
* |
34
|
|
|
* @return ItemInterface |
35
|
|
|
*/ |
36
|
1 |
View Code Duplication |
public function buildMenu(ItemInterface $item) |
|
|
|
|
37
|
|
|
{ |
38
|
1 |
|
return $item->addChild($this->getTitle(), [ |
39
|
1 |
|
'route' => 'fill_filler', |
40
|
1 |
|
'routeParameters' => ['plugin' => $this->getName()], |
41
|
1 |
|
]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return Filler |
46
|
|
|
*/ |
47
|
6 |
|
public function getForm() |
48
|
|
|
{ |
49
|
6 |
|
return new FillerForm(); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param Router $router |
54
|
|
|
*/ |
55
|
1 |
|
public function setRouter(Router $router) |
56
|
|
|
{ |
57
|
1 |
|
$this->router = $router; |
58
|
1 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @throws \LogicException |
62
|
|
|
* |
63
|
|
|
* @param mixed $data |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
2 |
|
public function getLinkForFill($data) |
68
|
|
|
{ |
69
|
2 |
|
if (!($this->router instanceof Router)) { |
70
|
1 |
|
throw new \LogicException('Link cannot be built without a Router'); |
71
|
|
|
} |
72
|
|
|
|
73
|
1 |
|
return $this->router->generate( |
74
|
1 |
|
'fill_filler', |
75
|
|
|
[ |
76
|
1 |
|
'plugin' => $this->getName(), |
77
|
1 |
|
$this->getForm()->getName() => ['url' => $data], |
78
|
|
|
] |
79
|
1 |
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Fill from search result. |
84
|
|
|
* |
85
|
|
|
* @param ItemSearch $item |
86
|
|
|
* |
87
|
|
|
* @return Item|null |
88
|
|
|
*/ |
89
|
4 |
|
public function fillFromSearchResult(ItemSearch $item) |
90
|
|
|
{ |
91
|
4 |
|
$query = parse_url($item->getLink(), PHP_URL_QUERY); |
92
|
4 |
|
parse_str($query, $query); |
93
|
4 |
|
if (empty($query[$this->getForm()->getName()])) { |
94
|
3 |
|
return; |
95
|
|
|
} |
96
|
|
|
|
97
|
1 |
|
return $this->fill($query[$this->getForm()->getName()]); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $url |
102
|
|
|
* |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
|
|
public function isSupportedUrl($url) |
106
|
|
|
{ |
107
|
|
|
return false; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.