Completed
Push — master ( e93f17...96c485 )
by Aimeos
02:31
created
src/Controller/Extadm.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -32,62 +32,62 @@  discard block
 block discarded – undo
32 32
 	 * @param array $args Associative list of route parameters
33 33
 	 * @return ResponseInterface $response Modified response object with generated output
34 34
 	 */
35
-	public static function indexAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args )
35
+	public static function indexAction(ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args)
36 36
 	{
37
-		$site = ( isset( $args['site'] ) ? $args['site'] : 'default' );
38
-		$lang = ( isset( $args['lang'] ) ? $args['lang'] : 'en' );
39
-		$tab = ( isset( $args['tab'] ) ? $args['tab'] : 0 );
37
+		$site = (isset($args['site']) ? $args['site'] : 'default');
38
+		$lang = (isset($args['lang']) ? $args['lang'] : 'en');
39
+		$tab = (isset($args['tab']) ? $args['tab'] : 0);
40 40
 
41
-		$aimeos = $container->get( 'aimeos' );
42
-		$cntlPaths = $aimeos->getCustomPaths( 'controller/extjs' );
41
+		$aimeos = $container->get('aimeos');
42
+		$cntlPaths = $aimeos->getCustomPaths('controller/extjs');
43 43
 
44
-		$context = $container->get( 'aimeos_context' )->get( false, $args );
45
-		$context = self::setLocale( $context, $site, $lang );
44
+		$context = $container->get('aimeos_context')->get(false, $args);
45
+		$context = self::setLocale($context, $site, $lang);
46 46
 
47
-		$controller = new \Aimeos\Controller\ExtJS\JsonRpc( $context, $cntlPaths );
47
+		$controller = new \Aimeos\Controller\ExtJS\JsonRpc($context, $cntlPaths);
48 48
 		$cssFiles = array();
49 49
 
50
-		foreach( $aimeos->getCustomPaths( 'admin/extjs' ) as $base => $paths )
50
+		foreach ($aimeos->getCustomPaths('admin/extjs') as $base => $paths)
51 51
 		{
52
-			foreach( $paths as $path )
52
+			foreach ($paths as $path)
53 53
 			{
54 54
 				$jsbAbsPath = $base . '/' . $path;
55 55
 
56
-				if( !is_file( $jsbAbsPath ) ) {
57
-					throw new \Exception( sprintf( 'JSB2 file "%1$s" not found', $jsbAbsPath ) );
56
+				if (!is_file($jsbAbsPath)) {
57
+					throw new \Exception(sprintf('JSB2 file "%1$s" not found', $jsbAbsPath));
58 58
 				}
59 59
 
60
-				$jsb2 = new \Aimeos\MW\Jsb2\Standard( $jsbAbsPath, dirname( $path ) );
61
-				$cssFiles = array_merge( $cssFiles, $jsb2->getUrls( 'css' ) );
60
+				$jsb2 = new \Aimeos\MW\Jsb2\Standard($jsbAbsPath, dirname($path));
61
+				$cssFiles = array_merge($cssFiles, $jsb2->getUrls('css'));
62 62
 			}
63 63
 		}
64 64
 
65
-		$csrfname = $request->getAttribute( 'csrf_name' );
66
-		$csrfvalue = $request->getAttribute( 'csrf_value' );
65
+		$csrfname = $request->getAttribute('csrf_name');
66
+		$csrfvalue = $request->getAttribute('csrf_value');
67 67
 
68
-		$router = $container->get( 'router' );
69
-		$jqadmUrl = $router->pathFor( 'aimeos_shop_jqadm_search', array( 'site' => $site, 'resource' => 'product' ) );
70
-		$jsonUrl = $router->pathFor( 'aimeos_shop_extadm_json', array( 'site' => $site, $csrfname => $csrfvalue ) );
71
-		$adminUrl = $router->pathFor( 'aimeos_shop_extadm', array( 'site' => '<site>', 'lang' => '<lang>', 'tab' => '<tab>' ) );
68
+		$router = $container->get('router');
69
+		$jqadmUrl = $router->pathFor('aimeos_shop_jqadm_search', array('site' => $site, 'resource' => 'product'));
70
+		$jsonUrl = $router->pathFor('aimeos_shop_extadm_json', array('site' => $site, $csrfname => $csrfvalue));
71
+		$adminUrl = $router->pathFor('aimeos_shop_extadm', array('site' => '<site>', 'lang' => '<lang>', 'tab' => '<tab>'));
72 72
 
73 73
 		$vars = array(
74 74
 			'lang' => $lang,
75 75
 			'cssFiles' => $cssFiles,
76
-			'languages' => self::getJsonLanguages( $aimeos ),
77
-			'config' => self::getJsonClientConfig( $context ),
78
-			'site' => self::getJsonSiteItem( $context, $site ),
79
-			'i18nContent' => self::getJsonClientI18n( $aimeos->getI18nPaths(), $lang ),
80
-			'uploaddir' => $context->getConfig()->get( 'uploaddir', '/.' ),
76
+			'languages' => self::getJsonLanguages($aimeos),
77
+			'config' => self::getJsonClientConfig($context),
78
+			'site' => self::getJsonSiteItem($context, $site),
79
+			'i18nContent' => self::getJsonClientI18n($aimeos->getI18nPaths(), $lang),
80
+			'uploaddir' => $context->getConfig()->get('uploaddir', '/.'),
81 81
 			'searchSchemas' => $controller->getJsonSearchSchemas(),
82 82
 			'itemSchemas' => $controller->getJsonItemSchemas(),
83
-			'smd' => $controller->getJsonSmd( $jsonUrl ),
83
+			'smd' => $controller->getJsonSmd($jsonUrl),
84 84
 			'urlTemplate' => $adminUrl,
85 85
 			'jqadmurl' => $jqadmUrl,
86 86
 			'activeTab' => $tab,
87 87
 			'version' => \Aimeos\Slim\Bootstrap::getVersion(),
88 88
 		);
89 89
 
90
-		return $container->get( 'view' )->render( $response, 'Extadm/index.html.twig', $vars );
90
+		return $container->get('view')->render($response, 'Extadm/index.html.twig', $vars);
91 91
 	}
92 92
 
93 93
 
@@ -100,22 +100,22 @@  discard block
 block discarded – undo
100 100
 	 * @param array $args Associative list of route parameters
101 101
 	 * @return ResponseInterface $response Modified response object with generated output
102 102
 	 */
103
-	public static function doAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args )
103
+	public static function doAction(ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args)
104 104
 	{
105
-		$cntlPaths = $container->get( 'aimeos' )->getCustomPaths( 'controller/extjs' );
105
+		$cntlPaths = $container->get('aimeos')->getCustomPaths('controller/extjs');
106 106
 
107
-		$context = $container->get( 'aimeos_context' )->get( false, $args );
108
-		$context->setView( $container->get( 'aimeos_view' )->create( $request, $response, $args, array() ) );
109
-		$context = self::setLocale( $context );
107
+		$context = $container->get('aimeos_context')->get(false, $args);
108
+		$context->setView($container->get('aimeos_view')->create($request, $response, $args, array()));
109
+		$context = self::setLocale($context);
110 110
 
111 111
 		$params = $request->getQueryParams();
112
-		if( ( $post = $request->getParsedBody() ) !== null ) {
113
-			$params = array_merge( $params, (array) $post );
112
+		if (($post = $request->getParsedBody()) !== null) {
113
+			$params = array_merge($params, (array) $post);
114 114
 		}
115 115
 
116
-		$controller = new \Aimeos\Controller\ExtJS\JsonRpc( $context, $cntlPaths );
117
-		$output = $controller->process( $params, (string) $request->getBody() );
118
-		$response->getBody()->write( $output );
116
+		$controller = new \Aimeos\Controller\ExtJS\JsonRpc($context, $cntlPaths);
117
+		$output = $controller->process($params, (string) $request->getBody());
118
+		$response->getBody()->write($output);
119 119
 
120 120
 		return $response;
121 121
 	}
@@ -130,30 +130,30 @@  discard block
 block discarded – undo
130 130
 	 * @param array $args Associative list of route parameters
131 131
 	 * @return ResponseInterface $response Modified response object with generated output
132 132
 	 */
133
-	public static function fileAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args )
133
+	public static function fileAction(ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args)
134 134
 	{
135 135
 		$contents = '';
136 136
 		$jsFiles = array();
137
-		$aimeos = $container->get( 'aimeos' );
137
+		$aimeos = $container->get('aimeos');
138 138
 
139
-		foreach( $aimeos->getCustomPaths( 'admin/extjs' ) as $base => $paths )
139
+		foreach ($aimeos->getCustomPaths('admin/extjs') as $base => $paths)
140 140
 		{
141
-			foreach( $paths as $path )
141
+			foreach ($paths as $path)
142 142
 			{
143 143
 				$jsbAbsPath = $base . '/' . $path;
144
-				$jsb2 = new \Aimeos\MW\Jsb2\Standard( $jsbAbsPath, dirname( $jsbAbsPath ) );
145
-				$jsFiles = array_merge( $jsFiles, $jsb2->getFiles( 'js' ) );
144
+				$jsb2 = new \Aimeos\MW\Jsb2\Standard($jsbAbsPath, dirname($jsbAbsPath));
145
+				$jsFiles = array_merge($jsFiles, $jsb2->getFiles('js'));
146 146
 			}
147 147
 		}
148 148
 
149
-		foreach( $jsFiles as $file )
149
+		foreach ($jsFiles as $file)
150 150
 		{
151
-			if( ( $content = file_get_contents( $file ) ) !== false ) {
151
+			if (($content = file_get_contents($file)) !== false) {
152 152
 				$contents .= $content;
153 153
 			}
154 154
 		}
155 155
 
156
-		return $response->withHeader( 'Content-Type', 'application/javascript' )->getBody()->write( $contents );
156
+		return $response->withHeader('Content-Type', 'application/javascript')->getBody()->write($contents);
157 157
 	}
158 158
 
159 159
 
@@ -163,15 +163,15 @@  discard block
 block discarded – undo
163 163
 	 * @param \Aimeos\Bootstrap $aimeos Aimeos object
164 164
 	 * @return array List of language IDs with labels
165 165
 	 */
166
-	protected static function getJsonLanguages( \Aimeos\Bootstrap $aimeos )
166
+	protected static function getJsonLanguages(\Aimeos\Bootstrap $aimeos)
167 167
 	{
168 168
 		$result = array();
169 169
 
170
-		foreach( $aimeos->getI18nList( 'admin' ) as $id ) {
171
-			$result[] = array( 'id' => $id, 'label' => $id );
170
+		foreach ($aimeos->getI18nList('admin') as $id) {
171
+			$result[] = array('id' => $id, 'label' => $id);
172 172
 		}
173 173
 
174
-		return json_encode( $result );
174
+		return json_encode($result);
175 175
 	}
176 176
 
177 177
 
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
 	 * @param \Aimeos\MShop\Context\Item\Iface $context Context item object
182 182
 	 * @return string JSON encoded configuration object
183 183
 	 */
184
-	protected static function getJsonClientConfig( \Aimeos\MShop\Context\Item\Iface $context )
184
+	protected static function getJsonClientConfig(\Aimeos\MShop\Context\Item\Iface $context)
185 185
 	{
186
-		$config = $context->getConfig()->get( 'admin/extjs', array() );
187
-		return json_encode( array( 'admin' => array( 'extjs' => $config ) ), JSON_FORCE_OBJECT );
186
+		$config = $context->getConfig()->get('admin/extjs', array());
187
+		return json_encode(array('admin' => array('extjs' => $config)), JSON_FORCE_OBJECT);
188 188
 	}
189 189
 
190 190
 
@@ -195,16 +195,16 @@  discard block
 block discarded – undo
195 195
 	 * @param string $lang ISO language code like "en" or "en_GB"
196 196
 	 * @return string JSON encoded translation object
197 197
 	 */
198
-	protected static function getJsonClientI18n( array $i18nPaths, $lang )
198
+	protected static function getJsonClientI18n(array $i18nPaths, $lang)
199 199
 	{
200
-		$i18n = new \Aimeos\MW\Translation\Gettext( $i18nPaths, $lang );
200
+		$i18n = new \Aimeos\MW\Translation\Gettext($i18nPaths, $lang);
201 201
 
202 202
 		$content = array(
203
-			'admin' => $i18n->getAll( 'admin' ),
204
-			'admin/ext' => $i18n->getAll( 'admin/ext' ),
203
+			'admin' => $i18n->getAll('admin'),
204
+			'admin/ext' => $i18n->getAll('admin/ext'),
205 205
 		);
206 206
 
207
-		return json_encode( $content, JSON_FORCE_OBJECT );
207
+		return json_encode($content, JSON_FORCE_OBJECT);
208 208
 	}
209 209
 
210 210
 
@@ -216,19 +216,19 @@  discard block
 block discarded – undo
216 216
 	 * @return string JSON encoded site item object
217 217
 	 * @throws Exception If no site item was found for the code
218 218
 	 */
219
-	protected static function getJsonSiteItem( \Aimeos\MShop\Context\Item\Iface $context, $site )
219
+	protected static function getJsonSiteItem(\Aimeos\MShop\Context\Item\Iface $context, $site)
220 220
 	{
221
-		$manager = \Aimeos\MShop\Factory::createManager( $context, 'locale/site' );
221
+		$manager = \Aimeos\MShop\Factory::createManager($context, 'locale/site');
222 222
 
223 223
 		$criteria = $manager->createSearch();
224
-		$criteria->setConditions( $criteria->compare( '==', 'locale.site.code', $site ) );
225
-		$items = $manager->searchItems( $criteria );
224
+		$criteria->setConditions($criteria->compare('==', 'locale.site.code', $site));
225
+		$items = $manager->searchItems($criteria);
226 226
 
227
-		if( ( $item = reset( $items ) ) === false ) {
228
-			throw new \Exception( sprintf( 'No site found for code "%1$s"', $site ) );
227
+		if (($item = reset($items)) === false) {
228
+			throw new \Exception(sprintf('No site found for code "%1$s"', $site));
229 229
 		}
230 230
 
231
-		return json_encode( $item->toArray() );
231
+		return json_encode($item->toArray());
232 232
 	}
233 233
 
234 234
 
@@ -240,17 +240,17 @@  discard block
 block discarded – undo
240 240
 	 * @param string $locale ISO language code, e.g. "en" or "en_GB"
241 241
 	 * @return \Aimeos\MShop\Context\Item\Iface Modified context object
242 242
 	 */
243
-	protected static function setLocale( \Aimeos\MShop\Context\Item\Iface $context, $sitecode = 'default', $locale = null )
243
+	protected static function setLocale(\Aimeos\MShop\Context\Item\Iface $context, $sitecode = 'default', $locale = null)
244 244
 	{
245
-		$localeManager = \Aimeos\MShop\Factory::createManager( $context, 'locale' );
245
+		$localeManager = \Aimeos\MShop\Factory::createManager($context, 'locale');
246 246
 
247 247
 		try {
248
-			$localeItem = $localeManager->bootstrap( $sitecode, $locale, '', false );
249
-		} catch( \Aimeos\MShop\Locale\Exception $e ) {
248
+			$localeItem = $localeManager->bootstrap($sitecode, $locale, '', false);
249
+		} catch (\Aimeos\MShop\Locale\Exception $e) {
250 250
 			$localeItem = $localeManager->createItem();
251 251
 		}
252 252
 
253
-		$context->setLocale( $localeItem );
253
+		$context->setLocale($localeItem);
254 254
 
255 255
 		return $context;
256 256
 	}
Please login to merge, or discard this patch.