1 | <?php |
||
18 | class Search extends SearchPlugin |
||
19 | { |
||
20 | /** |
||
21 | * Name. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | const NAME = 'world-art'; |
||
26 | |||
27 | /** |
||
28 | * Title. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | const TITLE = 'World-Art.ru'; |
||
33 | |||
34 | /** |
||
35 | * Path for search. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | const SEARH_URL = '/search.php?public_search=#NAME#&global_sector=#SECTOR#'; |
||
40 | |||
41 | /** |
||
42 | * XPath for list search items. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | const XPATH_FOR_LIST = '//center/table/tr/td/table/tr/td/table/tr/td'; |
||
47 | |||
48 | /** |
||
49 | * Default sector. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | const DEFAULT_SECTOR = 'all'; |
||
54 | |||
55 | /** |
||
56 | * Browser. |
||
57 | * |
||
58 | * @var \AnimeDb\Bundle\WorldArtFillerBundle\Service\Browser |
||
59 | */ |
||
60 | private $browser; |
||
61 | |||
62 | /** |
||
63 | * Construct. |
||
64 | * |
||
65 | * @param \AnimeDb\Bundle\WorldArtFillerBundle\Service\Browser $browser |
||
66 | */ |
||
67 | public function __construct(Browser $browser) |
||
71 | |||
72 | /** |
||
73 | * Get name. |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getName() |
||
81 | |||
82 | /** |
||
83 | * Get title. |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | public function getTitle() |
||
91 | |||
92 | /** |
||
93 | * Build menu for plugin. |
||
94 | * |
||
95 | * @param \Knp\Menu\ItemInterface $item |
||
96 | * |
||
97 | * @return \Knp\Menu\ItemInterface |
||
98 | */ |
||
99 | public function buildMenu(ItemInterface $item) |
||
104 | |||
105 | /** |
||
106 | * Search source by name. |
||
107 | * |
||
108 | * Return structure |
||
109 | * <code> |
||
110 | * [ |
||
111 | * \AnimeDb\Bundle\CatalogBundle\Plugin\Fill\Search\Item |
||
112 | * ] |
||
113 | * </code> |
||
114 | * |
||
115 | * @param array $data |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | public function search(array $data) |
||
175 | |||
176 | /** |
||
177 | * Get form. |
||
178 | * |
||
179 | * @return \AnimeDb\Bundle\WorldArtFillerBundle\Form\Type\Search |
||
180 | */ |
||
181 | public function getForm() |
||
185 | } |
||
186 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: