|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* YAWIK |
|
5
|
|
|
* |
|
6
|
|
|
* @filesource |
|
7
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Core\View\Helper; |
|
12
|
|
|
|
|
13
|
|
|
use Zend\View\ViewEvent; |
|
14
|
|
|
use Core\View\Helper\InsertFile\FileEvent; |
|
15
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
16
|
|
|
use Zend\View\HelperPluginManager; |
|
17
|
|
|
|
|
18
|
|
|
class InsertFile extends AbstractEventsHelper |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var ServiceLocatorInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $serviceManager; |
|
25
|
|
|
|
|
26
|
|
|
protected $files = array(); |
|
27
|
|
|
|
|
28
|
|
|
protected $ListenersUnaware = true; |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
protected $event; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param ServiceLocatorInterface $serviceManager |
|
34
|
|
|
* @param string $identifiers |
|
|
|
|
|
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(ServiceLocatorInterface $serviceManager, $identifiers = null) |
|
37
|
|
|
{ |
|
38
|
|
|
parent::__construct($identifiers); |
|
39
|
|
|
$this->serviceManager = $serviceManager; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* render a File-Object |
|
44
|
|
|
* |
|
45
|
|
|
* @param string |
|
46
|
|
|
* @return string |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __invoke($fileName, $parameter = array()) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->listenToRenderer(); |
|
51
|
|
|
$event = $this->getEvent(); |
|
52
|
|
|
$event->addFilename($fileName); |
|
53
|
|
|
$event->setRenderParameter($parameter); |
|
54
|
|
|
$return = 'file not found'; |
|
55
|
|
|
|
|
56
|
|
|
// ensure, that we have a file-object |
|
57
|
|
|
$result = $this->trigger(FileEvent::GETFILE, $event); |
|
58
|
|
|
if (!empty($result)) { |
|
59
|
|
|
// ask someone else for rendering |
|
60
|
|
|
$result = $this->trigger(FileEvent::RENDERFILE, $event); |
|
61
|
|
|
$return = $result->last(); |
|
62
|
|
|
} |
|
63
|
|
|
return $return; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
protected function getEvent() |
|
67
|
|
|
{ |
|
68
|
|
|
if (!isset($this->event)) { |
|
69
|
|
|
$this->event = new FileEvent(); |
|
70
|
|
|
} |
|
71
|
|
|
return $this->event; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* hook into the rendering-process to provide a summary of all included files |
|
76
|
|
|
*/ |
|
77
|
|
|
public function listenToRenderer() |
|
78
|
|
|
{ |
|
79
|
|
|
if ($this->ListenersUnaware) { |
|
80
|
|
|
// set a listener at the end of the Rendering-Process |
|
81
|
|
|
// to announce what files have been inserted |
|
82
|
|
|
$this->ListenersUnaware = false; |
|
83
|
|
|
$view = $this->serviceManager->get('View'); |
|
84
|
|
|
$viewEvents = $view->getEventManager(); |
|
85
|
|
|
// rendering ist over |
|
86
|
|
|
// get the attached Files very early |
|
87
|
|
|
// before any other postprocessing has started |
|
88
|
|
|
$viewEvents->attach(ViewEvent::EVENT_RESPONSE, array($this, 'anounceAttachedFiles'), 1000); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function anounceAttachedFiles(ViewEvent $e) |
|
|
|
|
|
|
93
|
|
|
{ |
|
94
|
|
|
$event = $this->getEvent(); |
|
95
|
|
|
$this->trigger(FileEvent::INSERTFILE, $event); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param HelperPluginManager $helperPluginManager |
|
100
|
|
|
* @return InsertFile |
|
101
|
|
|
*/ |
|
102
|
|
|
public static function factory(HelperPluginManager $helperPluginManager) |
|
103
|
|
|
{ |
|
104
|
|
|
return new static($helperPluginManager->getServiceLocator()); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.