src/Eccube/DataCollector/EccubeDataCollector.php line 109

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\DataCollector;
  13. use Eccube\Common\Constant;
  14. use Eccube\Entity\Plugin;
  15. use Eccube\Repository\PluginRepository;
  16. use Symfony\Component\DependencyInjection\ContainerInterface;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpFoundation\Response;
  19. use Symfony\Component\HttpKernel\DataCollector\DataCollector;
  20. /**
  21.  * EccubeDataCollector.
  22.  *
  23.  * @see https://github.com/Sylius/SyliusCoreBundle/blob/master/Collector/SyliusCollector.php
  24.  */
  25. class EccubeDataCollector extends DataCollector
  26. {
  27.     /**
  28.      * @var ContainerInterface
  29.      */
  30.     protected $container;
  31.     /**
  32.      * @var PluginRepository
  33.      */
  34.     protected $pluginRepository;
  35.     /**
  36.      * @param ContainerInterface $container
  37.      */
  38.     public function __construct(ContainerInterface $containerPluginRepository $pluginRepository)
  39.     {
  40.         $this->data = [
  41.             'version' => Constant::VERSION,
  42.             'base_currency_code' => null,
  43.             'currency_code' => null,
  44.             'default_locale_code' => null,
  45.             'locale_code' => null,
  46.             'plugins' => [],
  47.         ];
  48.         $this->container $container;
  49.         $this->pluginRepository $pluginRepository;
  50.     }
  51.     /**
  52.      * @return string
  53.      */
  54.     public function getVersion()
  55.     {
  56.         return $this->data['version'];
  57.     }
  58.     /**
  59.      * @return array
  60.      */
  61.     public function getPlugins()
  62.     {
  63.         return $this->data['plugins'];
  64.     }
  65.     /**
  66.      * @return string
  67.      */
  68.     public function getCurrencyCode()
  69.     {
  70.         return $this->data['currency_code'];
  71.     }
  72.     /**
  73.      * @return string
  74.      */
  75.     public function getLocaleCode()
  76.     {
  77.         return $this->data['locale_code'];
  78.     }
  79.     /**
  80.      * @return string
  81.      */
  82.     public function getDefaultCurrencyCode()
  83.     {
  84.         return $this->data['base_currency_code'];
  85.     }
  86.     /**
  87.      * @return string
  88.      */
  89.     public function getDefaultLocaleCode()
  90.     {
  91.         return $this->data['default_locale_code'];
  92.     }
  93.     /**
  94.      * {@inheritdoc}
  95.      */
  96.     public function collect(Request $requestResponse $response\Throwable $exception null)
  97.     {
  98.         $this->data['base_currency_code'] = $this->container->getParameter('currency');
  99.         $this->data['currency_code'] = $this->container->getParameter('currency');
  100.         try {
  101.             $this->data['locale_code'] = $this->container->getParameter('locale');
  102.         } catch (\Exception $exception) {
  103.         }
  104.         try {
  105.             $enabled $this->container->getParameter('eccube.plugins.enabled');
  106.             $disabled $this->container->getParameter('eccube.plugins.disabled');
  107.             $Plugins $this->pluginRepository->findAll();
  108.             foreach (array_merge($enabled$disabled) as $code) {
  109.                 $Plugin null;
  110.                 /* @var Plugin $Plugin */
  111.                 foreach ($Plugins as $p) {
  112.                     if ($code == $p->getCode()) {
  113.                         $Plugin $p;
  114.                         break;
  115.                     }
  116.                 }
  117.                 if (!$Plugin) {
  118.                     $Plugin = new Plugin();
  119.                     $Plugin->setCode($code);
  120.                     $Plugin->setName($code);
  121.                     $Plugin->setEnabled(false);
  122.                 }
  123.                 $this->data['plugins'][$code] = $Plugin->toArray();
  124.             }
  125.         } catch (\Exception $exception) {
  126.         }
  127.     }
  128.     public function reset()
  129.     {
  130.         $this->data = [];
  131.     }
  132.     /**
  133.      * {@inheritdoc}
  134.      */
  135.     public function getName()
  136.     {
  137.         return 'eccube_core';
  138.     }
  139. }