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