Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Application often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Application, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
52 | class Application extends \Silex\Application |
||
|
|||
53 | { |
||
54 | use \Silex\Application\FormTrait; |
||
55 | use \Silex\Application\UrlGeneratorTrait; |
||
56 | use \Silex\Application\MonologTrait; |
||
57 | use \Silex\Application\SwiftmailerTrait; |
||
58 | use \Silex\Application\SecurityTrait; |
||
59 | use \Silex\Application\TranslationTrait; |
||
60 | use \Eccube\Application\ApplicationTrait; |
||
61 | use \Eccube\Application\SecurityTrait; |
||
62 | use \Eccube\Application\TwigTrait; |
||
63 | |||
64 | protected static $instance; |
||
65 | |||
66 | protected $initialized = false; |
||
67 | protected $initializedPlugin = false; |
||
68 | protected $testMode = false; |
||
69 | |||
70 | 1104 | public static function getInstance(array $values = array()) |
|
71 | { |
||
72 | 1104 | if (!is_object(self::$instance)) { |
|
73 | 1104 | self::$instance = new Application($values); |
|
74 | } |
||
75 | |||
76 | 1104 | return self::$instance; |
|
77 | } |
||
78 | |||
79 | 1104 | public static function clearInstance() |
|
80 | { |
||
81 | 1104 | self::$instance = null; |
|
82 | } |
||
83 | |||
84 | final public function __clone() |
||
85 | { |
||
86 | throw new \Exception('Clone is not allowed against '.get_class($this)); |
||
87 | } |
||
88 | |||
89 | 1105 | public function __construct(array $values = array()) |
|
90 | { |
||
91 | 1105 | parent::__construct($values); |
|
92 | |||
93 | 1105 | if (is_null(self::$instance)) { |
|
94 | 1105 | self::$instance = $this; |
|
95 | } |
||
96 | |||
97 | // load config |
||
98 | 1105 | $this->initConfig(); |
|
99 | |||
100 | // init monolog |
||
101 | 1105 | $this->initLogger(); |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * Application::runが実行されているか親クラスのプロパティから判定 |
||
106 | * |
||
107 | * @return bool |
||
108 | */ |
||
109 | 1104 | public function isBooted() |
|
110 | { |
||
111 | 1104 | return $this->booted; |
|
112 | } |
||
113 | |||
114 | 1105 | public function initConfig() |
|
115 | { |
||
116 | // load .env |
||
117 | 1105 | $envFile = __DIR__.'/../../.env'; |
|
118 | 1105 | if (file_exists($envFile)) { |
|
119 | (new Dotenv())->load($envFile); |
||
120 | } |
||
121 | |||
122 | // load config |
||
123 | $this['config'] = function() { |
||
124 | 1105 | $configAll = array(); |
|
125 | 1105 | $this->parseConfig('constant', $configAll) |
|
126 | 1105 | ->parseConfig('path', $configAll) |
|
127 | 1105 | ->parseConfig('config', $configAll) |
|
128 | 1105 | ->parseConfig('database', $configAll) |
|
129 | 1105 | ->parseConfig('mail', $configAll) |
|
130 | 1105 | ->parseConfig('log', $configAll) |
|
131 | 1105 | ->parseConfig('nav', $configAll, true) |
|
132 | 1105 | ->parseConfig('doctrine_cache', $configAll) |
|
133 | 1105 | ->parseConfig('http_cache', $configAll) |
|
134 | 1105 | ->parseConfig('session_handler', $configAll); |
|
135 | |||
136 | 1105 | return $configAll; |
|
137 | }; |
||
138 | } |
||
139 | |||
140 | 1105 | public function initLogger() |
|
141 | { |
||
142 | 1105 | $app = $this; |
|
143 | 1105 | $this->register(new ServiceProvider\LogServiceProvider($app)); |
|
144 | } |
||
145 | |||
146 | 1104 | public function initialize() |
|
147 | { |
||
148 | 1104 | if ($this->initialized) { |
|
149 | 2 | return; |
|
150 | } |
||
151 | |||
152 | // init locale |
||
153 | 1104 | $this->initLocale(); |
|
154 | |||
155 | // init session |
||
156 | 1104 | if (!$this->isSessionStarted()) { |
|
157 | 1104 | $this->initSession(); |
|
158 | } |
||
159 | |||
160 | // init twig |
||
161 | 1104 | $this->initRendering(); |
|
162 | |||
163 | // init provider |
||
164 | 1104 | $this->register(new \Silex\Provider\HttpCacheServiceProvider(), array( |
|
165 | 1104 | 'http_cache.cache_dir' => __DIR__.'/../../app/cache/http/', |
|
166 | )); |
||
167 | 1104 | $this->register(new \Silex\Provider\HttpFragmentServiceProvider()); |
|
168 | 1104 | $this->register(new \Silex\Provider\FormServiceProvider()); |
|
169 | 1104 | $this->register(new \Silex\Provider\SerializerServiceProvider()); |
|
170 | 1104 | $this->register(new \Silex\Provider\ValidatorServiceProvider()); |
|
171 | 1104 | $this->register(new \Saxulum\Validator\Provider\SaxulumValidatorProvider()); |
|
172 | 1104 | $this->register(new MobileDetectServiceProvider()); |
|
173 | |||
174 | $this->error(function (\Exception $e, Request $request, $code) { |
||
175 | 23 | if ($this['debug']) { |
|
176 | 23 | return; |
|
177 | } |
||
178 | |||
179 | switch ($code) { |
||
180 | case 403: |
||
181 | $title = 'アクセスできません。'; |
||
182 | $message = 'お探しのページはアクセスができない状況にあるか、移動もしくは削除された可能性があります。'; |
||
183 | break; |
||
184 | case 404: |
||
185 | $title = 'ページがみつかりません。'; |
||
186 | $message = 'URLに間違いがないかご確認ください。'; |
||
187 | break; |
||
188 | default: |
||
189 | $title = 'システムエラーが発生しました。'; |
||
190 | $message = '大変お手数ですが、サイト管理者までご連絡ください。'; |
||
191 | break; |
||
192 | } |
||
193 | |||
194 | return $this->render('error.twig', array( |
||
195 | 'error_title' => $title, |
||
196 | 'error_message' => $message, |
||
197 | )); |
||
198 | 1104 | }); |
|
199 | |||
200 | // init mailer |
||
201 | 1104 | $this->initMailer(); |
|
202 | |||
203 | 1104 | $this->register(new \Sergiors\Silex\Provider\DoctrineCacheServiceProvider()); |
|
204 | 1104 | $this->register(new \Sergiors\Silex\Provider\AnnotationsServiceProvider(), [ |
|
205 | 1104 | 'annotations.debug' => $this['debug'], |
|
206 | 'annotations.options' => [ |
||
207 | 1104 | 'cache_driver' => $this['debug'] ? 'array' : 'filesystem', |
|
208 | 1104 | 'cache_dir' => $this['debug'] ? null : __DIR__.'/../../app/cache/annotation' |
|
209 | ] |
||
210 | ]); |
||
211 | |||
212 | // init doctrine orm |
||
213 | 1104 | $this->initDoctrine(); |
|
214 | |||
215 | // Set up the DBAL connection now to check for a proper connection to the database. |
||
216 | 1104 | $this->checkDatabaseConnection(); |
|
217 | |||
218 | // init security |
||
219 | 1104 | $this->initSecurity(); |
|
220 | |||
221 | 1104 | $this->register(new \Sergiors\Silex\Provider\RoutingServiceProvider(), [ |
|
222 | 1104 | 'routing.cache_dir' => $this['debug'] ? null : __DIR__.'/../../app/cache/routing' |
|
223 | ]); |
||
224 | 1104 | $this->register(new \Sergiors\Silex\Provider\TemplatingServiceProvider()); |
|
225 | 1104 | $this->register(new \Sergiors\Silex\Provider\SensioFrameworkExtraServiceProvider(), [ |
|
226 | 1104 | 'request' => [ |
|
227 | 'auto_convert' => true |
||
228 | ] |
||
229 | ]); |
||
230 | // init proxy |
||
231 | 1104 | $this->initProxy(); |
|
232 | |||
233 | // init ec-cube service provider |
||
234 | 1104 | $this->register(new DiServiceProvider(), [ |
|
235 | 'eccube.di.dirs' => [ |
||
236 | 1104 | $this['config']['root_dir'].'/app/Acme/Controller', |
|
237 | 1104 | $this['config']['root_dir'].'/src/Eccube/Repository', |
|
238 | 1104 | $this['config']['root_dir'].'/src/Eccube/Form/Type', |
|
239 | 1104 | $this['config']['root_dir'].'/src/Eccube/Form/Extension', |
|
240 | 1104 | $this['config']['root_dir'].'/src/Eccube/Service', |
|
241 | 1104 | $this['config']['root_dir'].'/src/Eccube/Controller', |
|
242 | ], |
||
243 | 1104 | 'eccube.di.generator.dir' => $this['config']['root_dir'].'/app/cache/provider' |
|
244 | ]); |
||
245 | |||
246 | 1104 | $this->register(new CompatRepositoryProvider()); |
|
247 | 1104 | $this->register(new CompatServiceProvider()); |
|
248 | 1104 | $this->register(new ServiceProvider\EccubeServiceProvider()); |
|
249 | |||
250 | 1104 | $this->register(new \Silex\Provider\ServiceControllerServiceProvider()); |
|
251 | 1104 | Request::enableHttpMethodParameterOverride(); // PUTやDELETEできるようにする |
|
252 | |||
253 | // ルーティングの設定 |
||
254 | // TODO EccubeRoutingServiceProviderに移植する. |
||
255 | 1104 | $app = $this; |
|
256 | $this['eccube.router'] = $this->protect(function($resoure, $cachePrefix) use ($app) { |
||
257 | $options = [ |
||
258 | 1104 | 'debug' => $app['debug'], |
|
259 | 1104 | 'cache_dir' => $app['routing.cache_dir'], |
|
260 | 1104 | 'matcher_base_class' => $app['request_matcher_class'], |
|
261 | 1104 | 'matcher_class' => $app['request_matcher_class'], |
|
262 | 1104 | 'matcher_cache_class' => $cachePrefix.'UrlMatcher', |
|
263 | 1104 | 'generator_cache_class' => $cachePrefix.'UrlGenerator' |
|
264 | ]; |
||
265 | 1104 | $router = new EccubeRouter( |
|
266 | 1104 | $app['routing.loader'], |
|
267 | 1104 | $resoure, |
|
268 | 1104 | $options, |
|
269 | 1104 | $app['request_context'], |
|
270 | 1104 | $app['logger'] |
|
271 | ); |
||
272 | |||
273 | 1104 | $router->setAdminPrefix($app['config']['admin_route']); |
|
274 | 1104 | $router->setUserDataPrefix($app['config']['user_data_route']); |
|
275 | 1104 | $router->setRequireHttps($app['config']['force_ssl']); |
|
276 | |||
277 | 1104 | return $router; |
|
278 | 1104 | }); |
|
279 | |||
280 | $this['eccube.router.origin'] = function ($app) { |
||
281 | 1104 | $resource = __DIR__.'/Controller'; |
|
282 | 1104 | $cachePrefix = 'Origin'; |
|
283 | |||
284 | 1104 | return $app['eccube.router']($resource, $cachePrefix); |
|
285 | }; |
||
286 | |||
287 | $this['eccube.routers.plugin'] = function ($app) { |
||
288 | // TODO 有効なプラグインを対象とする必要がある. |
||
289 | 1104 | $dirs = Finder::create() |
|
290 | 1104 | ->in($app['config']['root_dir'].'/app/Plugin') |
|
291 | 1104 | ->name('Controller') |
|
292 | 1104 | ->directories(); |
|
293 | |||
294 | 1104 | $routers = []; |
|
295 | 1104 | foreach ($dirs as $dir) { |
|
296 | 1104 | $realPath = $dir->getRealPath(); |
|
297 | 1104 | $pluginCode = basename(dirname($realPath)); |
|
298 | 1104 | $routers[] = $app['eccube.router']($realPath, 'Plugin'.$pluginCode); |
|
299 | } |
||
300 | |||
301 | 1104 | return $routers; |
|
302 | }; |
||
303 | |||
304 | $this['eccube.router.extend'] = function ($app) { |
||
305 | // TODO ディレクトリ名は暫定 |
||
306 | 1104 | $resource = $app['config']['root_dir'].'/app/Acme/Controller'; |
|
307 | 1104 | $cachePrefix = 'Extend'; |
|
308 | |||
309 | 1104 | $router = $app['eccube.router']($resource, $cachePrefix); |
|
310 | |||
311 | 1104 | return $router; |
|
312 | }; |
||
313 | |||
314 | View Code Duplication | $this->extend('request_matcher', function ($matcher, $app) { |
|
315 | 1104 | $matchers = []; |
|
316 | 1104 | $matchers[] = $app['eccube.router.extend']; |
|
317 | 1104 | foreach ($app['eccube.routers.plugin'] as $router) { |
|
318 | 1104 | $matchers[] = $router; |
|
319 | }; |
||
320 | 1104 | $matchers[] = $app['eccube.router.origin']; |
|
321 | 1104 | $matchers[] = $matcher; |
|
322 | |||
323 | 1104 | return new ChainUrlMatcher($matchers, $app['request_context']); |
|
324 | 1104 | }); |
|
325 | |||
326 | View Code Duplication | $this->extend('url_generator', function ($generator, $app) { |
|
327 | 1104 | $generators = []; |
|
328 | 1104 | $generators[] = $app['eccube.router.extend']; |
|
329 | 1104 | foreach ($app['eccube.routers.plugin'] as $router) { |
|
330 | 1104 | $generators[] = $router; |
|
331 | }; |
||
332 | 1104 | $generators[] = $app['eccube.router.origin']; |
|
333 | 1104 | $generators[] = $generator; |
|
334 | |||
335 | 1104 | return new ChainUrlGenerator($generators, $app['request_context']); |
|
336 | 1104 | }); |
|
337 | |||
338 | // Route CollectionにEC-CUBEで定義したルーティングを追加(debug tool barに出力するため) |
||
339 | $this->extend('routes', function ($routes, $app) { |
||
340 | 1104 | $routes->addCollection($app['eccube.router.extend']->getRouteCollection()); |
|
341 | 1104 | foreach ($app['eccube.routers.plugin'] as $router) { |
|
342 | 1104 | $routes->addCollection($router->getRouteCollection()); |
|
343 | }; |
||
344 | 1104 | $routes->addCollection($app['eccube.router.origin']->getRouteCollection()); |
|
345 | |||
346 | 1104 | return $routes; |
|
347 | 1104 | }); |
|
348 | |||
349 | // init http cache |
||
350 | 1104 | $this->initCacheRequest(); |
|
351 | |||
352 | 1104 | $this->initialized = true; |
|
353 | } |
||
354 | |||
355 | 1104 | public function initLocale() |
|
356 | { |
||
357 | // locale |
||
358 | 1104 | if (!empty($this['config']['locale'])) { |
|
359 | 1104 | \Locale::setDefault($this['config']['locale']); |
|
360 | }; |
||
361 | |||
362 | // timezone |
||
363 | 1104 | if (!empty($this['config']['timezone'])) { |
|
364 | 1104 | date_default_timezone_set($this['config']['timezone']); |
|
365 | } |
||
366 | |||
367 | 1104 | $this->register(new \Silex\Provider\TranslationServiceProvider(), array( |
|
368 | 1104 | 'locale' => $this['config']['locale'], |
|
369 | 1104 | 'translator.cache_dir' => $this['debug'] ? null : $this['config']['root_dir'].'/app/cache/translator', |
|
370 | 'locale_fallbacks' => ['ja', 'en'], |
||
371 | )); |
||
372 | $this->extend('translator', function ($translator, \Silex\Application $app) { |
||
373 | 1104 | $translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader()); |
|
374 | |||
375 | 1104 | $file = __DIR__.'/Resource/locale/validator.'.$app['locale'].'.yml'; |
|
376 | 1104 | if (file_exists($file)) { |
|
377 | 1104 | $translator->addResource('yaml', $file, $app['locale'], 'validators'); |
|
378 | } |
||
379 | |||
380 | 1104 | $file = __DIR__.'/Resource/locale/message.'.$app['locale'].'.yml'; |
|
381 | 1104 | if (file_exists($file)) { |
|
382 | 1104 | $translator->addResource('yaml', $file, $app['locale']); |
|
383 | } |
||
384 | |||
385 | 1104 | return $translator; |
|
386 | 1104 | }); |
|
387 | } |
||
388 | |||
389 | 1104 | public function initSession() |
|
390 | { |
||
391 | 1104 | $this->register(new \Silex\Provider\SessionServiceProvider(), array( |
|
392 | 1104 | 'session.storage.save_path' => $this['config']['root_dir'].'/app/cache/eccube/session', |
|
393 | 'session.storage.options' => array( |
||
394 | 1104 | 'name' => $this['config']['cookie_name'], |
|
395 | 1104 | 'cookie_path' => $this['config']['root_urlpath'] ?: '/', |
|
396 | 1104 | 'cookie_secure' => $this['config']['force_ssl'], |
|
397 | 1104 | 'cookie_lifetime' => $this['config']['cookie_lifetime'], |
|
398 | 'cookie_httponly' => true, |
||
399 | // cookie_domainは指定しない |
||
400 | // http://blog.tokumaru.org/2011/10/cookiedomain.html |
||
401 | ), |
||
402 | )); |
||
403 | |||
404 | 1104 | $options = $this['config']['session_handler']; |
|
405 | |||
406 | 1104 | if ($options['enabled']) { |
|
407 | // @see http://silex.sensiolabs.org/doc/providers/session.html#custom-session-configurations |
||
408 | $this['session.storage.handler'] = null; |
||
409 | ini_set('session.save_handler', $options['save_handler']); |
||
410 | ini_set('session.save_path', $options['save_path']); |
||
411 | } |
||
412 | } |
||
413 | |||
414 | 1104 | public function initRendering() |
|
415 | { |
||
416 | 1104 | $this->register(new \Silex\Provider\TwigServiceProvider(), array( |
|
417 | 1104 | 'twig.form.templates' => array('Form/form_layout.twig'), |
|
418 | )); |
||
419 | $this->extend('twig', function (\Twig_Environment $twig, \Silex\Application $app) { |
||
420 | 1104 | $twig->addExtension(new \Eccube\Twig\Extension\EccubeExtension($app)); |
|
421 | 1104 | $twig->addExtension(new \Twig_Extension_StringLoader()); |
|
422 | |||
423 | 1104 | return $twig; |
|
424 | 1104 | }); |
|
425 | |||
426 | $this->before(function (Request $request, \Silex\Application $app) { |
||
427 | 317 | $app['admin'] = $app['front'] = false; |
|
428 | 317 | $pathinfo = rawurldecode($request->getPathInfo()); |
|
429 | 317 | if (strpos($pathinfo, '/'.trim($app['config']['admin_route'], '/').'/') === 0) { |
|
430 | 220 | $app['admin'] = true; |
|
431 | } else { |
||
432 | 97 | $app['front'] = true; |
|
433 | } |
||
434 | |||
435 | // フロント or 管理画面ごとにtwigの探索パスを切り替える. |
||
436 | 317 | if ($app->isAdminRequest()) { |
|
437 | 220 | if (file_exists(__DIR__.'/../../app/template/admin')) { |
|
438 | 220 | $paths[] = __DIR__.'/../../app/template/admin'; |
|
439 | } |
||
440 | 220 | $paths[] = $app['config']['template_admin_realdir']; |
|
441 | 220 | $paths[] = __DIR__.'/../../app/Plugin'; |
|
442 | 220 | $cacheDir = __DIR__.'/../../app/cache/twig/admin'; |
|
443 | } else { |
||
444 | // モバイル端末時、smartphoneディレクトリを探索パスに追加する. |
||
445 | 97 | if ($app['mobile_detect.device_type'] == \Eccube\Entity\Master\DeviceType::DEVICE_TYPE_SP) { |
|
446 | if (file_exists(__DIR__.'/../../app/template/smartphone')) { |
||
447 | $paths[] = __DIR__.'/../../app/template/smartphone'; |
||
448 | } |
||
449 | $paths[] = __DIR__.'/Resource/template/smartphone'; |
||
450 | } |
||
451 | |||
452 | 97 | if (file_exists($app['config']['template_realdir'])) { |
|
453 | 97 | $paths[] = $app['config']['template_realdir']; |
|
454 | } |
||
455 | 97 | $paths[] = $app['config']['template_default_realdir']; |
|
456 | 97 | $paths[] = __DIR__.'/../../app/Plugin'; |
|
457 | 97 | $cacheDir = __DIR__.'/../../app/cache/twig/'.$app['config']['template_code']; |
|
458 | } |
||
459 | 317 | $app['twig']->setCache($app['debug'] ? null : $cacheDir); |
|
460 | 317 | $app['twig.loader']->addLoader(new \Twig_Loader_Filesystem($paths)); |
|
461 | |||
462 | // 管理画面のIP制限チェック. |
||
463 | 317 | if ($app->isAdminRequest()) { |
|
464 | // IP制限チェック |
||
465 | 220 | $allowHost = $app['config']['admin_allow_host']; |
|
466 | 220 | if (count($allowHost) > 0) { |
|
467 | if (array_search($app['request_stack']->getCurrentRequest()->getClientIp(), $allowHost) === false) { |
||
468 | throw new \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException(); |
||
469 | } |
||
470 | } |
||
471 | } |
||
472 | 1104 | }, self::EARLY_EVENT); |
|
473 | |||
474 | // twigのグローバル変数を定義. |
||
475 | $this->on(\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER, function (\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event) { |
||
476 | // 未ログイン時にマイページや管理画面以下にアクセスするとSubRequestで実行されるため, |
||
477 | // $event->isMasterRequest()ではなく、グローバル変数が初期化済かどうかの判定を行う |
||
478 | 315 | if (isset($this['twig_global_initialized']) && $this['twig_global_initialized'] === true) { |
|
479 | 45 | return; |
|
480 | } |
||
481 | // ショップ基本情報 |
||
482 | 315 | $this['twig']->addGlobal('BaseInfo', $this[BaseInfo::class]); |
|
483 | |||
484 | 315 | if ($this->isAdminRequest()) { |
|
485 | // 管理画面 |
||
486 | // 管理画面メニュー |
||
487 | 220 | $menus = array('', '', ''); |
|
488 | 220 | $this['twig']->addGlobal('menus', $menus); |
|
489 | |||
490 | 220 | $Member = $this->user(); |
|
491 | 220 | if (is_object($Member)) { |
|
492 | // ログインしていれば管理者のロールを取得 |
||
493 | 217 | $AuthorityRoles = $this['eccube.repository.authority_role']->findBy(array('Authority' => $Member->getAuthority())); |
|
494 | |||
495 | 217 | $roles = array(); |
|
496 | 217 | $request = $event->getRequest(); |
|
497 | 217 | foreach ($AuthorityRoles as $AuthorityRole) { |
|
498 | // 管理画面でメニュー制御するため相対パス全てをセット |
||
499 | 3 | $roles[] = $request->getBaseUrl().'/'.$this['config']['admin_route'].$AuthorityRole->getDenyUrl(); |
|
500 | } |
||
501 | |||
502 | 220 | $this['twig']->addGlobal('AuthorityRoles', $roles); |
|
503 | } |
||
504 | |||
505 | } else { |
||
506 | // フロント画面 |
||
507 | 95 | $request = $event->getRequest(); |
|
508 | 95 | $route = $request->attributes->get('_route'); |
|
509 | |||
510 | // ユーザ作成画面 |
||
511 | 95 | if ($route === 'user_data') { |
|
512 | 2 | $params = $request->attributes->get('_route_params'); |
|
513 | 2 | $route = $params['route']; |
|
514 | // プレビュー画面 |
||
515 | 93 | } elseif ($request->get('preview')) { |
|
516 | $route = 'preview'; |
||
517 | } |
||
518 | |||
519 | try { |
||
520 | 95 | $device_type_id = $this['mobile_detect.device_type']; |
|
521 | |||
522 | // TODO デバッグ用 |
||
523 | 95 | if ($request->query->has('device_type_id')) { |
|
524 | $device_type_id = $request->get('device_type_id', \Eccube\Entity\Master\DeviceType::DEVICE_TYPE_PC); |
||
525 | } |
||
526 | |||
527 | 95 | $DeviceType = $this['eccube.repository.master.device_type'] |
|
528 | 95 | ->find($device_type_id); |
|
529 | 95 | $qb = $this['eccube.repository.page_layout']->createQueryBuilder('p'); |
|
530 | 95 | $PageLayout = $qb->select('p, pll,l, bp, b') |
|
531 | 95 | ->leftJoin('p.PageLayoutLayouts', 'pll') |
|
532 | 95 | ->leftJoin('pll.Layout', 'l') |
|
533 | 95 | ->leftJoin('l.BlockPositions', 'bp') |
|
534 | 95 | ->leftJoin('bp.Block', 'b') |
|
535 | 95 | ->where('p.url = :route') |
|
536 | 95 | ->andWhere('l.DeviceType = :DeviceType') |
|
537 | 95 | ->orderBy('bp.block_row', 'ASC') |
|
538 | 95 | ->setParameter('route', $route) |
|
539 | 95 | ->setParameter('DeviceType', $DeviceType) |
|
540 | 95 | ->getQuery() |
|
541 | 95 | ->getSingleResult(); |
|
542 | 33 | } catch (\Doctrine\ORM\NoResultException $e) { |
|
543 | 33 | $PageLayout = $this['eccube.repository.page_layout']->newPageLayout($DeviceType); |
|
544 | } |
||
545 | |||
546 | 95 | $this['twig']->addGlobal('PageLayout', $PageLayout); |
|
547 | 95 | $this['twig']->addGlobal('title', $PageLayout->getName()); |
|
548 | } |
||
549 | |||
550 | 315 | $this['twig_global_initialized'] = true; |
|
551 | 1104 | }); |
|
552 | } |
||
553 | |||
554 | 1104 | public function initMailer() |
|
583 | |||
584 | 1104 | public function initDoctrine() |
|
754 | |||
755 | 1104 | public function initSecurity() |
|
854 | |||
855 | /** |
||
856 | * ロードバランサー、プロキシサーバの設定を行う |
||
857 | */ |
||
858 | 1104 | public function initProxy() |
|
870 | |||
871 | 1102 | public function initializePlugin() |
|
886 | |||
887 | /** |
||
888 | * PHPUnit を実行中かどうかを設定する. |
||
889 | * |
||
890 | * @param boolean $testMode PHPUnit を実行中の場合 true |
||
891 | */ |
||
892 | 1094 | public function setTestMode($testMode) |
|
896 | |||
897 | /** |
||
898 | * PHPUnit を実行中かどうか. |
||
899 | * |
||
900 | * @return boolean PHPUnit を実行中の場合 true |
||
901 | */ |
||
902 | 317 | public function isTestMode() |
|
906 | |||
907 | /** |
||
908 | * |
||
909 | * データベースの接続を確認 |
||
910 | * 成功 : trueを返却 |
||
911 | * 失敗 : \Doctrine\DBAL\DBALExceptionエラーが発生( 接続に失敗した場合 )、エラー画面を表示しdie() |
||
912 | * 備考 : app['debug']がtrueの際は処理を行わない |
||
913 | * |
||
914 | * @return boolean true |
||
915 | * |
||
916 | */ |
||
917 | 1104 | protected function checkDatabaseConnection() |
|
941 | |||
942 | /** |
||
943 | * Config ファイルをパースし、連想配列を返します. |
||
944 | * |
||
945 | * $config_name.yml ファイルをパースし、連想配列を返します. |
||
946 | * $config_name.php が存在する場合は、 PHP ファイルに記述された連想配列を使用します。 |
||
947 | * |
||
948 | * @param string $config_name Config 名称 |
||
949 | * @param array $configAll Config の連想配列 |
||
950 | * @param boolean $wrap_key Config の連想配列に config_name のキーを生成する場合 true, デフォルト false |
||
951 | * @param string $ymlPath config yaml を格納したディレクトリ |
||
952 | * @param string $distPath config yaml dist を格納したディレクトリ |
||
953 | * @return Application |
||
954 | */ |
||
955 | 1105 | public function parseConfig($config_name, array &$configAll, $wrap_key = false, $ymlPath = null, $distPath = null) |
|
1002 | |||
1003 | /** |
||
1004 | * セッションが開始されているかどうか. |
||
1005 | * |
||
1006 | * @return boolean セッションが開始済みの場合 true |
||
1007 | * @link http://php.net/manual/ja/function.session-status.php#113468 |
||
1008 | */ |
||
1009 | 1104 | protected function isSessionStarted() |
|
1021 | |||
1022 | /** |
||
1023 | * Http Cache対応 |
||
1024 | */ |
||
1025 | 1104 | protected function initCacheRequest() |
|
1088 | } |
||
1089 |