1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* BB's Zend Framework 2 Components |
4
|
|
|
* |
5
|
|
|
* UI Components |
6
|
|
|
* |
7
|
|
|
* @package [MyApplication] |
8
|
|
|
* @subpackage BB's Zend Framework 2 Components |
9
|
|
|
* @subpackage UI Components |
10
|
|
|
* @author Björn Bartels <[email protected]> |
11
|
|
|
* @link https://gitlab.bjoernbartels.earth/groups/zf2 |
12
|
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 |
13
|
|
|
* @copyright copyright (c) 2016 Björn Bartels <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace UIComponents\View\Helper\Components; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* |
20
|
|
|
* render nothing |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
class Element extends \UIComponents\View\Helper\AbstractHelper |
24
|
|
|
//implements \Zend\ServiceManager\ServiceLocatorAwareInterface |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* View helper entry point: |
29
|
|
|
* Retrieves helper and optionally sets component options to operate on |
30
|
|
|
* |
31
|
|
|
* @param array|StdClass $options [optional] component options to operate on |
32
|
|
|
* @return string|self |
33
|
|
|
*/ |
34
|
|
|
public function __invoke($options = array()) |
35
|
|
|
{ |
36
|
|
View Code Duplication |
if ( is_object($options) && method_exists($options, 'toArray') ) { |
|
|
|
|
37
|
|
|
$options = $options->toArray(); |
38
|
|
|
} else if ( is_object($options) ) { |
39
|
|
|
$options = (array)$options; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if (isset($options['container']) && (null !== $options['container'])) { |
43
|
|
|
$this->setContainer($options['container']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
View Code Duplication |
if (isset($options['tagname']) && (null !== $options['tagname'])) { |
|
|
|
|
47
|
|
|
$this->setTagname($options['tagname']); |
48
|
|
|
} |
49
|
|
View Code Duplication |
if (isset($options['class']) && (null !== $options['class'])) { |
|
|
|
|
50
|
|
|
$this->setClassnames($options['class']); |
51
|
|
|
} |
52
|
|
View Code Duplication |
if (isset($options['classnames']) && (null !== $options['classnames'])) { |
|
|
|
|
53
|
|
|
$this->setClassnames($options['classnames']); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
if (isset($options['attr']) && (null !== $options['attr'])) { |
|
|
|
|
57
|
|
|
$this->setAttributes($options['attr']); |
58
|
|
|
} |
59
|
|
View Code Duplication |
if (isset($options['attributes']) && (null !== $options['attributes'])) { |
|
|
|
|
60
|
|
|
$this->setAttributes($options['attributes']); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
View Code Duplication |
if (isset($options['content']) && (null !== $options['content'])) { |
|
|
|
|
64
|
|
|
$this->setContent($options['content']); |
65
|
|
|
} |
66
|
|
View Code Duplication |
if (isset($options['children']) && (null !== $options['children'])) { |
|
|
|
|
67
|
|
|
$this->setContent($options['children']); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$component = clone $this; |
71
|
|
|
return $component; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
} |
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.