diff --git a/Resources/config/services.yml b/Resources/config/services.yml index ee71d4df..95918691 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -6,6 +6,7 @@ parameters: support_tools.info_collectors.database.doctrine.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\DoctrineDatabaseSystemInfoCollector support_tools.info_collectors.hardware.ezc.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\EzcHardwareSystemInfoCollector support_tools.info_collectors.php.ezc.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\EzcPhpSystemInfoCollector + support_tools.info_collectors.symfony.kernel.config.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\ConfigurationSymfonyKernelSystemInfoCollector services: support_tools.info_collector.system_info.ezc: @@ -31,3 +32,9 @@ services: class: %support_tools.info_collectors.php.ezc.class% arguments: - @support_tools.info_collector.system_info.ezc + + support_tools.info_collectors.symfony.kernel.config: + class: %support_tools.info_collectors.symfony.kernel.config.class% + arguments: + - @kernel + - %kernel.bundles% diff --git a/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php b/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php new file mode 100644 index 00000000..0e9bfb83 --- /dev/null +++ b/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php @@ -0,0 +1,68 @@ + 'AppBundle\\AppBundle', + * 'AsseticBundle' => 'Symfony\\Bundle\\AsseticBundle\\AsseticBundle', + * ) + * + * @var array + */ + private $bundles; + + public function __construct(Kernel $kernel, array $bundles) + { + $this->kernel = $kernel; + $this->bundles = $bundles; + } + + /** + * Collects information about the Symfony kernel. + * + * @return Value\SymfonyKernelSystemInfo + */ + public function collect() + { + ksort($this->bundles, SORT_FLAG_CASE | SORT_STRING); + + return new Value\SymfonyKernelSystemInfo([ + 'environment' => $this->kernel->getEnvironment(), + 'debugMode' => $this->kernel->isDebug(), + 'version' => Kernel::VERSION, + 'bundles' => $this->bundles, + 'rootDir' => $this->kernel->getRootDir(), + 'name' => $this->kernel->getName(), + 'cacheDir' => $this->kernel->getCacheDir(), + 'logDir' => $this->kernel->getLogDir(), + 'charset' => $this->kernel->getCharset(), + ]); + } +} diff --git a/SystemInfo/Value/SymfonyKernelSystemInfo.php b/SystemInfo/Value/SymfonyKernelSystemInfo.php new file mode 100644 index 00000000..790d7df0 --- /dev/null +++ b/SystemInfo/Value/SymfonyKernelSystemInfo.php @@ -0,0 +1,102 @@ + 'AppBundle\\AppBundle', + * 'AsseticBundle' => 'Symfony\\Bundle\\AsseticBundle\\AsseticBundle', + * ) + * + * @var array + */ + public $bundles; + + /** + * Root directory. + * + * Example: /srv/www/ezpublish-platform/app + * + * @var string + */ + public $rootDir; + + /** + * Name. + * + * Example: app + * + * @var string + */ + public $name; + + /** + * Cache directory. + * + * Example: /srv/www/ezpublish-platform/app/cache/prod + * + * @var string + */ + public $cacheDir; + + /** + * Log file directory. + * + * Example: /srv/www/ezpublish-platform/app/logs + * + * @var string + */ + public $logDir; + + /** + * Character set. + * + * Example: UTF-8 + * + * @var string + */ + public $charset; +} diff --git a/Tests/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollectorTest.php b/Tests/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollectorTest.php new file mode 100644 index 00000000..5eaac66a --- /dev/null +++ b/Tests/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollectorTest.php @@ -0,0 +1,91 @@ + 'dev', + 'debugMode' => true, + 'version' => Kernel::VERSION, + 'bundles' => [ + 'AppBundle' => 'AppBundle\\AppBundle', + 'DoctrineBundle' => 'Doctrine\\Bundle\\DoctrineBundle\\DoctrineBundle', + 'eZPlatformUIBundle' => 'EzSystems\\PlatformUIBundle\\EzSystemsPlatformUIBundle', + 'EzPublishCoreBundle' => 'eZ\\Bundle\\EzPublishCoreBundle\\EzPublishCoreBundle', + 'EzSystemsEzSupportToolsBundle' => 'EzSystems\\EzSupportToolsBundle\\EzSystemsEzSupportToolsBundle', + ], + 'rootDir' => '/srv/www/ezpublish-platform/app', + 'name' => 'app', + 'cacheDir' => '/srv/www/ezpublish-platform/app/cache/prod', + 'logDir' => '/srv/www/ezpublish-platform/app/logs', + 'charset' => 'UTF-8', + ]); + + $kernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\Kernel') + ->setConstructorArgs([$expected->environment, $expected->debugMode]) + ->getMock(); + + $kernelMock + ->expects($this->once()) + ->method('getEnvironment') + ->will($this->returnValue($expected->environment)); + + $kernelMock + ->expects($this->once()) + ->method('isDebug') + ->will($this->returnValue($expected->debugMode)); + + $kernelMock + ->expects($this->once()) + ->method('getRootDir') + ->will($this->returnValue($expected->rootDir)); + + $kernelMock + ->expects($this->once()) + ->method('getName') + ->will($this->returnValue($expected->name)); + + $kernelMock + ->expects($this->once()) + ->method('getCacheDir') + ->will($this->returnValue($expected->cacheDir)); + + $kernelMock + ->expects($this->once()) + ->method('getLogDir') + ->will($this->returnValue($expected->logDir)); + + $kernelMock + ->expects($this->once()) + ->method('getCharset') + ->will($this->returnValue($expected->charset)); + + $symfonyCollector = new ConfigurationSymfonyKernelSystemInfoCollector( + $kernelMock, + $expected->bundles + ); + + $value = $symfonyCollector->collect(); + + self::assertInstanceOf('EzSystems\EzSupportToolsBundle\SystemInfo\Value\SymfonyKernelSystemInfo', $value); + + self::assertEquals($expected, $value); + } +}