|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://www.gnu.org/copyleft/lgpl.html |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
|
6
|
|
|
* @package flow |
|
7
|
|
|
* @subpackage Base |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Shop\Base; |
|
12
|
|
|
|
|
13
|
|
|
use TYPO3\Flow\Annotations as Flow; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class providing the view objects |
|
18
|
|
|
* |
|
19
|
|
|
* @package flow |
|
20
|
|
|
* @subpackage Base |
|
21
|
|
|
* @Flow\Scope("singleton") |
|
22
|
|
|
*/ |
|
23
|
|
|
class View |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var \Aimeos\Shop\Base\I18n |
|
27
|
|
|
* @Flow\Inject |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $i18n; |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Creates the view object for the HTML client. |
|
34
|
|
|
* |
|
35
|
|
|
* @param \Aimeos\MW\Config\Iface $config Config object |
|
36
|
|
|
* @param \TYPO3\Flow\Mvc\Routing\UriBuilder $uriBuilder URL builder object |
|
37
|
|
|
* @param array $templatePaths List of base path names with relative template paths as key/value pairs |
|
38
|
|
|
* @param \TYPO3\Flow\Mvc\RequestInterface|null $request Request object |
|
39
|
|
|
* @param string|null $langid Language ID |
|
40
|
|
|
* @return \Aimeos\MW\View\Iface View object |
|
41
|
|
|
*/ |
|
42
|
|
|
public function create( \Aimeos\MW\Config\Iface $config, |
|
43
|
|
|
\TYPO3\Flow\Mvc\Routing\UriBuilder $uriBuilder, array $templatePaths, |
|
44
|
|
|
\TYPO3\Flow\Mvc\RequestInterface $request = null, $langid = null ) |
|
45
|
|
|
{ |
|
46
|
|
|
$params = $fixed = array(); |
|
47
|
|
|
|
|
48
|
|
|
if( $request !== null && $langid !== null ) |
|
49
|
|
|
{ |
|
50
|
|
|
$params = $request->getArguments(); |
|
51
|
|
|
$fixed = $this->getFixedParams( $request ); |
|
52
|
|
|
|
|
53
|
|
|
$i18n = $this->i18n->get( array( $langid ) ); |
|
54
|
|
|
$translation = $i18n[$langid]; |
|
55
|
|
|
} |
|
56
|
|
|
else |
|
57
|
|
|
{ |
|
58
|
|
|
$translation = new \Aimeos\MW\Translation\None( 'en' ); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
$view = new \Aimeos\MW\View\Standard( $templatePaths ); |
|
63
|
|
|
|
|
64
|
|
|
$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $translation ); |
|
65
|
|
|
$view->addHelper( 'translate', $helper ); |
|
66
|
|
|
|
|
67
|
|
|
$helper = new \Aimeos\MW\View\Helper\Url\Flow( $view, $uriBuilder, $fixed ); |
|
68
|
|
|
$view->addHelper( 'url', $helper ); |
|
69
|
|
|
|
|
70
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $params ); |
|
71
|
|
|
$view->addHelper( 'param', $helper ); |
|
72
|
|
|
|
|
73
|
|
|
$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config ); |
|
74
|
|
|
$view->addHelper( 'config', $helper ); |
|
75
|
|
|
|
|
76
|
|
|
$sepDec = $config->get( 'client/html/common/format/seperatorDecimal', '.' ); |
|
77
|
|
|
$sep1000 = $config->get( 'client/html/common/format/seperator1000', ' ' ); |
|
78
|
|
|
$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, $sepDec, $sep1000 ); |
|
79
|
|
|
$view->addHelper( 'number', $helper ); |
|
80
|
|
|
|
|
81
|
|
|
if( $request !== null ) |
|
82
|
|
|
{ |
|
83
|
|
|
$req = $request->getHttpRequest(); |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
$files = ( is_array( $_FILES ) ? $_FILES : array() ); |
|
86
|
|
|
$query = ( is_array( $_GET ) ? $_GET : array() ); |
|
87
|
|
|
$post = ( is_array( $_POST ) ? $_POST : array() ); |
|
88
|
|
|
$cookie = ( is_array( $_COOKIE ) ? $_COOKIE : array() ); |
|
89
|
|
|
$server = ( is_array( $_SERVER ) ? $_SERVER : array() ); |
|
90
|
|
|
|
|
91
|
|
|
$helper = new \Aimeos\MW\View\Helper\Request\Flow( $view, $req, $files, $query, $post, $cookie, $server ); |
|
92
|
|
|
$view->addHelper( 'request', $helper ); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$helper = new \Aimeos\MW\View\Helper\Response\Flow( $view ); |
|
96
|
|
|
$view->addHelper( 'response', $helper ); |
|
97
|
|
|
|
|
98
|
|
|
return $view; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Returns the fixed parameters that should be included in every URL |
|
104
|
|
|
* |
|
105
|
|
|
* @param \TYPO3\Flow\Mvc\RequestInterface $request Request object |
|
106
|
|
|
* @return array Associative list of site, language and currency if available |
|
107
|
|
|
*/ |
|
108
|
|
|
protected function getFixedParams( \TYPO3\Flow\Mvc\RequestInterface $request ) |
|
109
|
|
|
{ |
|
110
|
|
|
$fixed = array(); |
|
111
|
|
|
|
|
112
|
|
|
$params = $request->getArguments(); |
|
113
|
|
|
|
|
114
|
|
|
if( isset( $params['site'] ) ) { |
|
115
|
|
|
$fixed['site'] = $params['site']; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
if( isset( $params['locale'] ) ) { |
|
119
|
|
|
$fixed['locale'] = $params['locale']; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
if( isset( $params['currency'] ) ) { |
|
123
|
|
|
$fixed['currency'] = $params['currency']; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
return $fixed; |
|
127
|
|
|
} |
|
128
|
|
|
} |
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: