|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @copyright 2013 - 2017 Cross Solution <http://cross-solution.de> |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** */ |
|
11
|
|
|
namespace Core\Factory\View\Helper; |
|
12
|
|
|
|
|
13
|
|
|
use Core\View\Helper\Snippet; |
|
14
|
|
|
use Interop\Container\ContainerInterface; |
|
15
|
|
|
use Zend\ServiceManager\AbstractPluginManager; |
|
16
|
|
|
use Zend\ServiceManager\FactoryInterface; |
|
17
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Factory for Snippet view helper |
|
21
|
|
|
* |
|
22
|
|
|
* @author Mathias Gelhausen <[email protected]> |
|
23
|
|
|
* @since 0,29 |
|
24
|
|
|
*/ |
|
25
|
|
View Code Duplication |
class SnippetFactory implements FactoryInterface |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Creates snippet view helper |
|
30
|
|
|
* |
|
31
|
|
|
* @param ContainerInterface $container |
|
32
|
|
|
* @param string $requestedName |
|
33
|
|
|
* @param array $options |
|
|
|
|
|
|
34
|
|
|
* |
|
35
|
|
|
* @return Snippet |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
38
|
|
|
{ |
|
39
|
|
|
$config = $container->get('Config'); |
|
40
|
|
|
$config = isset($config['view_helper_config']['snippets']) ? $config['view_helper_config']['snippets'] : []; |
|
41
|
|
|
|
|
42
|
|
|
$events = $container->get('Core/ViewSnippets/Events'); |
|
43
|
|
|
|
|
44
|
|
|
$helpers = $container->get('ViewHelperManager'); |
|
45
|
|
|
$partials = $helpers->get('partial'); |
|
46
|
|
|
|
|
47
|
|
|
return new Snippet($partials, $events, $config); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Creates snippet view helper- |
|
53
|
|
|
* |
|
54
|
|
|
* @param ServiceLocatorInterface|AbstractPluginManager $serviceLocator |
|
55
|
|
|
* |
|
56
|
|
|
* @return Snippet |
|
57
|
|
|
*/ |
|
58
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
|
59
|
|
|
{ |
|
60
|
|
|
$container = $serviceLocator->getServiceLocator(); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
return $this($container, Snippet::class); |
|
63
|
|
|
} |
|
64
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.