Completed
Push — master ( 536df1...5ff829 )
by Aimeos
02:18
created
src/Controller/Extadm.php 1 patch
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -32,63 +32,63 @@  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, 'backend' );
45
-		$context = self::setLocale( $context, $site, $lang );
44
+		$context = $container->get('aimeos_context')->get(false, $args, 'backend');
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
-				$jsbAbsPath = $base . '/' . $path;
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
-		$jsonUrl = $router->pathFor( 'aimeos_shop_extadm_json', array( 'site' => $site, $csrfname => $csrfvalue ) );
70
-		$jqadmUrl = $router->pathFor( 'aimeos_shop_jqadm_search', array( 'site' => $site, 'lang' => $lang, 'resource' => 'dashboard' ) );
71
-		$adminUrl = $router->pathFor( 'aimeos_shop_extadm', array( 'site' => '<site>', 'lang' => '<lang>', 'tab' => '<tab>' ) );
68
+		$router = $container->get('router');
69
+		$jsonUrl = $router->pathFor('aimeos_shop_extadm_json', array('site' => $site, $csrfname => $csrfvalue));
70
+		$jqadmUrl = $router->pathFor('aimeos_shop_jqadm_search', array('site' => $site, 'lang' => $lang, 'resource' => 'dashboard'));
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
-			'extensions' => implode( ',', $aimeos->getExtensions() ),
88
+			'extensions' => implode(',', $aimeos->getExtensions()),
89 89
 		);
90 90
 
91
-		return $container->get( 'view' )->render( $response, 'Extadm/index.html.twig', $vars );
91
+		return $container->get('view')->render($response, 'Extadm/index.html.twig', $vars);
92 92
 	}
93 93
 
94 94
 
@@ -101,22 +101,22 @@  discard block
 block discarded – undo
101 101
 	 * @param array $args Associative list of route parameters
102 102
 	 * @return ResponseInterface $response Modified response object with generated output
103 103
 	 */
104
-	public static function doAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args )
104
+	public static function doAction(ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args)
105 105
 	{
106
-		$cntlPaths = $container->get( 'aimeos' )->getCustomPaths( 'controller/extjs' );
106
+		$cntlPaths = $container->get('aimeos')->getCustomPaths('controller/extjs');
107 107
 
108
-		$context = $container->get( 'aimeos_context' )->get( false, $args, 'backend' );
109
-		$context->setView( $container->get( 'aimeos_view' )->create( $context->getConfig(), $request, $response, $args, array() ) );
110
-		$context = self::setLocale( $context );
108
+		$context = $container->get('aimeos_context')->get(false, $args, 'backend');
109
+		$context->setView($container->get('aimeos_view')->create($context->getConfig(), $request, $response, $args, array()));
110
+		$context = self::setLocale($context);
111 111
 
112 112
 		$params = $request->getQueryParams();
113
-		if( ( $post = $request->getParsedBody() ) !== null ) {
114
-			$params = array_merge( $params, (array) $post );
113
+		if (($post = $request->getParsedBody()) !== null) {
114
+			$params = array_merge($params, (array) $post);
115 115
 		}
116 116
 
117
-		$controller = new \Aimeos\Controller\ExtJS\JsonRpc( $context, $cntlPaths );
118
-		$output = $controller->process( $params, (string) $request->getBody() );
119
-		$response->getBody()->write( $output );
117
+		$controller = new \Aimeos\Controller\ExtJS\JsonRpc($context, $cntlPaths);
118
+		$output = $controller->process($params, (string) $request->getBody());
119
+		$response->getBody()->write($output);
120 120
 
121 121
 		return $response;
122 122
 	}
@@ -131,30 +131,30 @@  discard block
 block discarded – undo
131 131
 	 * @param array $args Associative list of route parameters
132 132
 	 * @return ResponseInterface $response Modified response object with generated output
133 133
 	 */
134
-	public static function fileAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args )
134
+	public static function fileAction(ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args)
135 135
 	{
136 136
 		$contents = '';
137 137
 		$jsFiles = array();
138
-		$aimeos = $container->get( 'aimeos' );
138
+		$aimeos = $container->get('aimeos');
139 139
 
140
-		foreach( $aimeos->getCustomPaths( 'admin/extjs' ) as $base => $paths )
140
+		foreach ($aimeos->getCustomPaths('admin/extjs') as $base => $paths)
141 141
 		{
142
-			foreach( $paths as $path )
142
+			foreach ($paths as $path)
143 143
 			{
144
-				$jsbAbsPath = $base . '/' . $path;
145
-				$jsb2 = new \Aimeos\MW\Jsb2\Standard( $jsbAbsPath, dirname( $jsbAbsPath ) );
146
-				$jsFiles = array_merge( $jsFiles, $jsb2->getFiles( 'js' ) );
144
+				$jsbAbsPath = $base.'/'.$path;
145
+				$jsb2 = new \Aimeos\MW\Jsb2\Standard($jsbAbsPath, dirname($jsbAbsPath));
146
+				$jsFiles = array_merge($jsFiles, $jsb2->getFiles('js'));
147 147
 			}
148 148
 		}
149 149
 
150
-		foreach( $jsFiles as $file )
150
+		foreach ($jsFiles as $file)
151 151
 		{
152
-			if( ( $content = file_get_contents( $file ) ) !== false ) {
152
+			if (($content = file_get_contents($file)) !== false) {
153 153
 				$contents .= $content;
154 154
 			}
155 155
 		}
156 156
 
157
-		return $response->withHeader( 'Content-Type', 'application/javascript' )->getBody()->write( $contents );
157
+		return $response->withHeader('Content-Type', 'application/javascript')->getBody()->write($contents);
158 158
 	}
159 159
 
160 160
 
@@ -164,15 +164,15 @@  discard block
 block discarded – undo
164 164
 	 * @param \Aimeos\Bootstrap $aimeos Aimeos object
165 165
 	 * @return array List of language IDs with labels
166 166
 	 */
167
-	protected static function getJsonLanguages( \Aimeos\Bootstrap $aimeos )
167
+	protected static function getJsonLanguages(\Aimeos\Bootstrap $aimeos)
168 168
 	{
169 169
 		$result = array();
170 170
 
171
-		foreach( $aimeos->getI18nList( 'admin' ) as $id ) {
172
-			$result[] = array( 'id' => $id, 'label' => $id );
171
+		foreach ($aimeos->getI18nList('admin') as $id) {
172
+			$result[] = array('id' => $id, 'label' => $id);
173 173
 		}
174 174
 
175
-		return json_encode( $result );
175
+		return json_encode($result);
176 176
 	}
177 177
 
178 178
 
@@ -182,10 +182,10 @@  discard block
 block discarded – undo
182 182
 	 * @param \Aimeos\MShop\Context\Item\Iface $context Context item object
183 183
 	 * @return string JSON encoded configuration object
184 184
 	 */
185
-	protected static function getJsonClientConfig( \Aimeos\MShop\Context\Item\Iface $context )
185
+	protected static function getJsonClientConfig(\Aimeos\MShop\Context\Item\Iface $context)
186 186
 	{
187
-		$config = $context->getConfig()->get( 'admin/extjs', array() );
188
-		return json_encode( array( 'admin' => array( 'extjs' => $config ) ), JSON_FORCE_OBJECT );
187
+		$config = $context->getConfig()->get('admin/extjs', array());
188
+		return json_encode(array('admin' => array('extjs' => $config)), JSON_FORCE_OBJECT);
189 189
 	}
190 190
 
191 191
 
@@ -196,16 +196,16 @@  discard block
 block discarded – undo
196 196
 	 * @param string $lang ISO language code like "en" or "en_GB"
197 197
 	 * @return string JSON encoded translation object
198 198
 	 */
199
-	protected static function getJsonClientI18n( array $i18nPaths, $lang )
199
+	protected static function getJsonClientI18n(array $i18nPaths, $lang)
200 200
 	{
201
-		$i18n = new \Aimeos\MW\Translation\Gettext( $i18nPaths, $lang );
201
+		$i18n = new \Aimeos\MW\Translation\Gettext($i18nPaths, $lang);
202 202
 
203 203
 		$content = array(
204
-			'admin' => $i18n->getAll( 'admin' ),
205
-			'admin/ext' => $i18n->getAll( 'admin/ext' ),
204
+			'admin' => $i18n->getAll('admin'),
205
+			'admin/ext' => $i18n->getAll('admin/ext'),
206 206
 		);
207 207
 
208
-		return json_encode( $content, JSON_FORCE_OBJECT );
208
+		return json_encode($content, JSON_FORCE_OBJECT);
209 209
 	}
210 210
 
211 211
 
@@ -217,19 +217,19 @@  discard block
 block discarded – undo
217 217
 	 * @return string JSON encoded site item object
218 218
 	 * @throws Exception If no site item was found for the code
219 219
 	 */
220
-	protected static function getJsonSiteItem( \Aimeos\MShop\Context\Item\Iface $context, $site )
220
+	protected static function getJsonSiteItem(\Aimeos\MShop\Context\Item\Iface $context, $site)
221 221
 	{
222
-		$manager = \Aimeos\MShop\Factory::createManager( $context, 'locale/site' );
222
+		$manager = \Aimeos\MShop\Factory::createManager($context, 'locale/site');
223 223
 
224 224
 		$criteria = $manager->createSearch();
225
-		$criteria->setConditions( $criteria->compare( '==', 'locale.site.code', $site ) );
226
-		$items = $manager->searchItems( $criteria );
225
+		$criteria->setConditions($criteria->compare('==', 'locale.site.code', $site));
226
+		$items = $manager->searchItems($criteria);
227 227
 
228
-		if( ( $item = reset( $items ) ) === false ) {
229
-			throw new \Exception( sprintf( 'No site found for code "%1$s"', $site ) );
228
+		if (($item = reset($items)) === false) {
229
+			throw new \Exception(sprintf('No site found for code "%1$s"', $site));
230 230
 		}
231 231
 
232
-		return json_encode( $item->toArray() );
232
+		return json_encode($item->toArray());
233 233
 	}
234 234
 
235 235
 
@@ -241,17 +241,17 @@  discard block
 block discarded – undo
241 241
 	 * @param string $locale ISO language code, e.g. "en" or "en_GB"
242 242
 	 * @return \Aimeos\MShop\Context\Item\Iface Modified context object
243 243
 	 */
244
-	protected static function setLocale( \Aimeos\MShop\Context\Item\Iface $context, $sitecode = 'default', $locale = null )
244
+	protected static function setLocale(\Aimeos\MShop\Context\Item\Iface $context, $sitecode = 'default', $locale = null)
245 245
 	{
246
-		$localeManager = \Aimeos\MShop\Factory::createManager( $context, 'locale' );
246
+		$localeManager = \Aimeos\MShop\Factory::createManager($context, 'locale');
247 247
 
248 248
 		try {
249
-			$localeItem = $localeManager->bootstrap( $sitecode, $locale, '', false );
250
-		} catch( \Aimeos\MShop\Locale\Exception $e ) {
249
+			$localeItem = $localeManager->bootstrap($sitecode, $locale, '', false);
250
+		} catch (\Aimeos\MShop\Locale\Exception $e) {
251 251
 			$localeItem = $localeManager->createItem();
252 252
 		}
253 253
 
254
-		$context->setLocale( $localeItem );
254
+		$context->setLocale($localeItem);
255 255
 
256 256
 		return $context;
257 257
 	}
Please login to merge, or discard this patch.