src/Eccube/Form/Type/Admin/LogType.php line 25

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\Form\Type\Admin;
  13. use Eccube\Common\EccubeConfig;
  14. use Symfony\Component\Finder\Finder;
  15. use Symfony\Component\Form\AbstractType;
  16. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  17. use Symfony\Component\Form\Extension\Core\Type\TextType;
  18. use Symfony\Component\Form\FormBuilderInterface;
  19. use Symfony\Component\HttpKernel\KernelInterface;
  20. use Symfony\Component\Validator\Constraints as Assert;
  21. class LogType extends AbstractType
  22. {
  23.     /**
  24.      * @var EccubeConfig
  25.      */
  26.     protected $eccubeConfig;
  27.     /**
  28.      * @var KernelInterface
  29.      */
  30.     protected $kernel;
  31.     /**
  32.      * LogType constructor.
  33.      *
  34.      * @param EccubeConfig $eccubeConfig
  35.      * @param KernelInterface $kernel
  36.      */
  37.     public function __construct(EccubeConfig $eccubeConfigKernelInterface $kernel)
  38.     {
  39.         $this->eccubeConfig $eccubeConfig;
  40.         $this->kernel $kernel;
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     public function buildForm(FormBuilderInterface $builder, array $options)
  46.     {
  47.         $files = [];
  48.         $finder = new Finder();
  49.         $finder->name('*.log')
  50.             ->depth('== 0')
  51.             ->sort(function (\SplFileInfo $a, \SplFileInfo $b) {
  52.                 return strcmp($b->getMTime(), $a->getMTime());
  53.             });
  54.         $dirs $this->kernel->getLogDir().DIRECTORY_SEPARATOR.$this->kernel->getEnvironment();
  55.         foreach ($finder->in($dirs) as $file) {
  56.             $files[$file->getFilename()] = $file->getFilename();
  57.         }
  58.         $builder
  59.             ->add('files'ChoiceType::class, [
  60.                 'choices' => array_flip($files),
  61.                 'data' => 'site_'.date('Y-m-d').'.log',
  62.                 'expanded' => false,
  63.                 'multiple' => false,
  64.                 'constraints' => [
  65.                     new Assert\NotBlank(),
  66.                 ],
  67.             ])
  68.             ->add('line_max'TextType::class, [
  69.                 'data' => '50',
  70.                 'attr' => [
  71.                     'maxlength' => 5,
  72.                 ],
  73.                 'constraints' => [
  74.                     new Assert\NotBlank(),
  75.                     new Assert\Range(['min' => 1'max' => 50000]),
  76.                 ],
  77.             ]);
  78.     }
  79.     /**
  80.      * {@inheritdoc}
  81.      */
  82.     public function getBlockPrefix()
  83.     {
  84.         return 'admin_system_log';
  85.     }
  86. }