Completed
Push — master ( 3b2949...37184d )
by Aimeos
02:44
created
Controller/ExtadmController.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -30,63 +30,63 @@  discard block
 block discarded – undo
30 30
 	 * @param Request $request Symfony request object
31 31
 	 * @return Response Generated output for the admin interface
32 32
 	 */
33
-	public function indexAction( Request $request )
33
+	public function indexAction(Request $request)
34 34
 	{
35
-		$site = $request->attributes->get( 'site', $request->query->get( 'site', 'default' ) );
36
-		$lang = $request->attributes->get( 'lang', $request->query->get( 'lang', 'en' ) );
37
-		$tab = $request->attributes->get( 'tab', $request->query->get( 'tab', 0 ) );
35
+		$site = $request->attributes->get('site', $request->query->get('site', 'default'));
36
+		$lang = $request->attributes->get('lang', $request->query->get('lang', 'en'));
37
+		$tab = $request->attributes->get('tab', $request->query->get('tab', 0));
38 38
 
39
-		$context = $this->get( 'aimeos_context' )->get( false );
40
-		$context = $this->setLocale( $context, $site, $lang );
39
+		$context = $this->get('aimeos_context')->get(false);
40
+		$context = $this->setLocale($context, $site, $lang);
41 41
 
42
-		$aimeos = $this->get( 'aimeos' );
42
+		$aimeos = $this->get('aimeos');
43 43
 		$bootstrap = $aimeos->get();
44 44
 
45
-		$cntlPaths = $bootstrap->getCustomPaths( 'controller/extjs' );
46
-		$controller = new \Aimeos\Controller\ExtJS\JsonRpc( $context, $cntlPaths );
45
+		$cntlPaths = $bootstrap->getCustomPaths('controller/extjs');
46
+		$controller = new \Aimeos\Controller\ExtJS\JsonRpc($context, $cntlPaths);
47 47
 		$cssFiles = array();
48 48
 
49
-		foreach( $bootstrap->getCustomPaths( 'admin/extjs' ) as $base => $paths )
49
+		foreach ($bootstrap->getCustomPaths('admin/extjs') as $base => $paths)
50 50
 		{
51
-			foreach( $paths as $path )
51
+			foreach ($paths as $path)
52 52
 			{
53
-				$jsbAbsPath = $base . '/' . $path;
53
+				$jsbAbsPath = $base.'/'.$path;
54 54
 
55
-				if( !is_file( $jsbAbsPath ) ) {
56
-					throw new \Exception( sprintf( 'JSB2 file "%1$s" not found', $jsbAbsPath ) );
55
+				if (!is_file($jsbAbsPath)) {
56
+					throw new \Exception(sprintf('JSB2 file "%1$s" not found', $jsbAbsPath));
57 57
 				}
58 58
 
59
-				$jsb2 = new \Aimeos\MW\Jsb2\Standard( $jsbAbsPath, dirname( $path ) );
60
-				$cssFiles = array_merge( $cssFiles, $jsb2->getUrls( 'css' ) );
59
+				$jsb2 = new \Aimeos\MW\Jsb2\Standard($jsbAbsPath, dirname($path));
60
+				$cssFiles = array_merge($cssFiles, $jsb2->getUrls('css'));
61 61
 			}
62 62
 		}
63 63
 
64
-		$params = array( 'site' => '{site}', 'lang' => '{lang}', 'tab' => '{tab}' );
65
-		$adminUrl = $this->generateUrl( 'aimeos_shop_extadm', $params );
64
+		$params = array('site' => '{site}', 'lang' => '{lang}', 'tab' => '{tab}');
65
+		$adminUrl = $this->generateUrl('aimeos_shop_extadm', $params);
66 66
 
67
-		$token = $this->get( 'security.csrf.token_manager' )->getToken( 'aimeos_admin_token' )->getValue();
68
-		$jsonUrl = $this->generateUrl( 'aimeos_shop_extadm_json', array( '_token' => $token, 'site' => $site ) );
67
+		$token = $this->get('security.csrf.token_manager')->getToken('aimeos_admin_token')->getValue();
68
+		$jsonUrl = $this->generateUrl('aimeos_shop_extadm_json', array('_token' => $token, 'site' => $site));
69 69
 
70
-		$jqadmUrl = $this->generateUrl( 'aimeos_shop_jqadm_search', array( 'site' => $site, 'resource' => 'product' ) );
70
+		$jqadmUrl = $this->generateUrl('aimeos_shop_jqadm_search', array('site' => $site, 'resource' => 'product'));
71 71
 
72 72
 		$vars = array(
73 73
 			'lang' => $lang,
74 74
 			'cssFiles' => $cssFiles,
75 75
 			'languages' => $this->getJsonLanguages(),
76
-			'config' => $this->getJsonClientConfig( $context ),
77
-			'site' => $this->getJsonSiteItem( $context, $site ),
78
-			'i18nContent' => $this->getJsonClientI18n( $bootstrap->getI18nPaths(), $lang ),
76
+			'config' => $this->getJsonClientConfig($context),
77
+			'site' => $this->getJsonSiteItem($context, $site),
78
+			'i18nContent' => $this->getJsonClientI18n($bootstrap->getI18nPaths(), $lang),
79 79
 			'searchSchemas' => $controller->getJsonSearchSchemas(),
80 80
 			'itemSchemas' => $controller->getJsonItemSchemas(),
81
-			'smd' => $controller->getJsonSmd( $jsonUrl ),
82
-			'urlTemplate' => urldecode( $adminUrl ),
83
-			'uploaddir' => $this->container->getParameter( 'aimeos_shop.uploaddir' ),
81
+			'smd' => $controller->getJsonSmd($jsonUrl),
82
+			'urlTemplate' => urldecode($adminUrl),
83
+			'uploaddir' => $this->container->getParameter('aimeos_shop.uploaddir'),
84 84
 			'version' => $aimeos->getVersion(),
85 85
 			'jqadmurl' => $jqadmUrl,
86 86
 			'activeTab' => $tab,
87 87
 		);
88 88
 
89
-		return $this->render( 'AimeosShopBundle:Extadm:index.html.twig', $vars );
89
+		return $this->render('AimeosShopBundle:Extadm:index.html.twig', $vars);
90 90
 	}
91 91
 
92 92
 
@@ -96,23 +96,23 @@  discard block
 block discarded – undo
96 96
 	 * @param Request $request Symfony request object
97 97
 	 * @return Response JSON RPC message response
98 98
 	 */
99
-	public function doAction( Request $request )
99
+	public function doAction(Request $request)
100 100
 	{
101 101
 		$csrfProvider = $this->get('security.csrf.token_manager');
102 102
 
103
-		if( $csrfProvider->isTokenValid( new CsrfToken( 'aimeos_admin_token',  $request->query->get( '_token' ) ) ) !== true ) {
104
-			throw new \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException( 'CSRF token is invalid' );
103
+		if ($csrfProvider->isTokenValid(new CsrfToken('aimeos_admin_token', $request->query->get('_token'))) !== true) {
104
+			throw new \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException('CSRF token is invalid');
105 105
 		}
106 106
 
107
-		$cntlPaths = $this->get( 'aimeos' )->get()->getCustomPaths( 'controller/extjs' );
108
-		$context = $this->get( 'aimeos_context' )->get( false );
109
-		$context->setView( $this->get( 'aimeos_view' )->create( $context->getConfig(), array() ) );
110
-		$context = $this->setLocale( $context );
107
+		$cntlPaths = $this->get('aimeos')->get()->getCustomPaths('controller/extjs');
108
+		$context = $this->get('aimeos_context')->get(false);
109
+		$context->setView($this->get('aimeos_view')->create($context->getConfig(), array()));
110
+		$context = $this->setLocale($context);
111 111
 
112
-		$controller = new \Aimeos\Controller\ExtJS\JsonRpc( $context, $cntlPaths );
112
+		$controller = new \Aimeos\Controller\ExtJS\JsonRpc($context, $cntlPaths);
113 113
 
114
-		$response = $controller->process( $request->request->all(), $request->getContent() );
115
-		return $this->render( 'AimeosShopBundle:Extadm:do.html.twig', array( 'output' => $response ) );
114
+		$response = $controller->process($request->request->all(), $request->getContent());
115
+		return $this->render('AimeosShopBundle:Extadm:do.html.twig', array('output' => $response));
116 116
 	}
117 117
 
118 118
 
@@ -125,27 +125,27 @@  discard block
 block discarded – undo
125 125
 	{
126 126
 		$contents = '';
127 127
 		$jsFiles = array();
128
-		$aimeos = $this->get( 'aimeos' )->get();
128
+		$aimeos = $this->get('aimeos')->get();
129 129
 
130
-		foreach( $aimeos->getCustomPaths( 'admin/extjs' ) as $base => $paths )
130
+		foreach ($aimeos->getCustomPaths('admin/extjs') as $base => $paths)
131 131
 		{
132
-			foreach( $paths as $path )
132
+			foreach ($paths as $path)
133 133
 			{
134
-				$jsbAbsPath = $base . '/' . $path;
135
-				$jsb2 = new \Aimeos\MW\Jsb2\Standard( $jsbAbsPath, dirname( $jsbAbsPath ) );
136
-				$jsFiles = array_merge( $jsFiles, $jsb2->getFiles( 'js' ) );
134
+				$jsbAbsPath = $base.'/'.$path;
135
+				$jsb2 = new \Aimeos\MW\Jsb2\Standard($jsbAbsPath, dirname($jsbAbsPath));
136
+				$jsFiles = array_merge($jsFiles, $jsb2->getFiles('js'));
137 137
 			}
138 138
 		}
139 139
 
140
-		foreach( $jsFiles as $file )
140
+		foreach ($jsFiles as $file)
141 141
 		{
142
-			if( ( $content = file_get_contents( $file ) ) !== false ) {
142
+			if (($content = file_get_contents($file)) !== false) {
143 143
 				$contents .= $content;
144 144
 			}
145 145
 		}
146 146
 
147
-		$response = new Response( $contents );
148
-		$response->headers->set( 'Content-Type', 'application/javascript' );
147
+		$response = new Response($contents);
148
+		$response->headers->set('Content-Type', 'application/javascript');
149 149
 
150 150
 		return $response;
151 151
 	}
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
 	{
161 161
 		$result = array();
162 162
 
163
-		foreach( $this->get( 'aimeos' )->get()->getI18nList( 'admin' ) as $id ) {
164
-			$result[] = array( 'id' => $id, 'label' => $id );
163
+		foreach ($this->get('aimeos')->get()->getI18nList('admin') as $id) {
164
+			$result[] = array('id' => $id, 'label' => $id);
165 165
 		}
166 166
 
167
-		return json_encode( $result );
167
+		return json_encode($result);
168 168
 	}
169 169
 
170 170
 
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 	 * @param \Aimeos\MShop\Context\Item\Iface $context Context item object
175 175
 	 * @return string JSON encoded configuration object
176 176
 	 */
177
-	protected function getJsonClientConfig( \Aimeos\MShop\Context\Item\Iface $context )
177
+	protected function getJsonClientConfig(\Aimeos\MShop\Context\Item\Iface $context)
178 178
 	{
179
-		$config = $context->getConfig()->get( 'admin/extjs', array() );
180
-		return json_encode( array( 'admin' => array( 'extjs' => $config ) ), JSON_FORCE_OBJECT );
179
+		$config = $context->getConfig()->get('admin/extjs', array());
180
+		return json_encode(array('admin' => array('extjs' => $config)), JSON_FORCE_OBJECT);
181 181
 	}
182 182
 
183 183
 
@@ -188,16 +188,16 @@  discard block
 block discarded – undo
188 188
 	 * @param string $lang ISO language code like "en" or "en_GB"
189 189
 	 * @return string JSON encoded translation object
190 190
 	 */
191
-	protected function getJsonClientI18n( array $i18nPaths, $lang )
191
+	protected function getJsonClientI18n(array $i18nPaths, $lang)
192 192
 	{
193
-		$i18n = new \Aimeos\MW\Translation\Gettext( $i18nPaths, $lang );
193
+		$i18n = new \Aimeos\MW\Translation\Gettext($i18nPaths, $lang);
194 194
 
195 195
 		$content = array(
196
-			'admin' => $i18n->getAll( 'admin' ),
197
-			'admin/ext' => $i18n->getAll( 'admin/ext' ),
196
+			'admin' => $i18n->getAll('admin'),
197
+			'admin/ext' => $i18n->getAll('admin/ext'),
198 198
 		);
199 199
 
200
-		return json_encode( $content, JSON_FORCE_OBJECT );
200
+		return json_encode($content, JSON_FORCE_OBJECT);
201 201
 	}
202 202
 
203 203
 
@@ -209,19 +209,19 @@  discard block
 block discarded – undo
209 209
 	 * @return string JSON encoded site item object
210 210
 	 * @throws Exception If no site item was found for the code
211 211
 	 */
212
-	protected function getJsonSiteItem( \Aimeos\MShop\Context\Item\Iface $context, $site )
212
+	protected function getJsonSiteItem(\Aimeos\MShop\Context\Item\Iface $context, $site)
213 213
 	{
214
-		$manager = \Aimeos\MShop\Factory::createManager( $context, 'locale/site' );
214
+		$manager = \Aimeos\MShop\Factory::createManager($context, 'locale/site');
215 215
 
216 216
 		$criteria = $manager->createSearch();
217
-		$criteria->setConditions( $criteria->compare( '==', 'locale.site.code', $site ) );
218
-		$items = $manager->searchItems( $criteria );
217
+		$criteria->setConditions($criteria->compare('==', 'locale.site.code', $site));
218
+		$items = $manager->searchItems($criteria);
219 219
 
220
-		if( ( $item = reset( $items ) ) === false ) {
221
-			throw new \Exception( sprintf( 'No site found for code "%1$s"', $site ) );
220
+		if (($item = reset($items)) === false) {
221
+			throw new \Exception(sprintf('No site found for code "%1$s"', $site));
222 222
 		}
223 223
 
224
-		return json_encode( $item->toArray() );
224
+		return json_encode($item->toArray());
225 225
 	}
226 226
 
227 227
 
@@ -233,17 +233,17 @@  discard block
 block discarded – undo
233 233
 	 * @param string $locale ISO language code, e.g. "en" or "en_GB"
234 234
 	 * @return \Aimeos\MShop\Context\Item\Iface Modified context object
235 235
 	 */
236
-	protected function setLocale( \Aimeos\MShop\Context\Item\Iface $context, $sitecode = 'default', $locale = null )
236
+	protected function setLocale(\Aimeos\MShop\Context\Item\Iface $context, $sitecode = 'default', $locale = null)
237 237
 	{
238
-		$localeManager = \Aimeos\MShop\Factory::createManager( $context, 'locale' );
238
+		$localeManager = \Aimeos\MShop\Factory::createManager($context, 'locale');
239 239
 
240 240
 		try {
241
-			$localeItem = $localeManager->bootstrap( $sitecode, $locale, '', false );
242
-		} catch( \Aimeos\MShop\Locale\Exception $e ) {
241
+			$localeItem = $localeManager->bootstrap($sitecode, $locale, '', false);
242
+		} catch (\Aimeos\MShop\Locale\Exception $e) {
243 243
 			$localeItem = $localeManager->createItem();
244 244
 		}
245 245
 
246
-		$context->setLocale( $localeItem );
246
+		$context->setLocale($localeItem);
247 247
 
248 248
 		return $context;
249 249
 	}
Please login to merge, or discard this patch.