Skip to content

Commit

Permalink
EZP-26391: ez-support-tools factory called on every request (#21)
Browse files Browse the repository at this point in the history
* EZP-26391: ez-support-tools factory called on every request

Part 2, fixes Command by wrapping ezcSystemInfo and exposing magic properties.
  • Loading branch information
glye authored Oct 20, 2016
1 parent c82a872 commit c8283cc
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 47 deletions.
14 changes: 5 additions & 9 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ imports:
parameters:
support_tools.command.dump_info.class: EzSystems\EzSupportToolsBundle\Command\SystemInfoDumpCommand
support_tools.system_info.collector_registry.class: EzSystems\EzSupportToolsBundle\SystemInfo\Registry\IdentifierBased
support_tools.system_info.ezc.factory.class: EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoFactory
support_tools.system_info.ezc.wrapper.class: EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoWrapper
support_tools.system_info.collector.composer.lock_file.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\JsonComposerLockSystemInfoCollector
support_tools.system_info.collector.database.doctrine.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\DoctrineDatabaseSystemInfoCollector
support_tools.system_info.collector.hardware.ezc.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\EzcHardwareSystemInfoCollector
Expand All @@ -22,14 +22,10 @@ services:
support_tools.system_info.collector_registry:
class: "%support_tools.system_info.collector_registry.class%"

support_tools.system_info.ezc:
class: ezcSystemInfo
factory: ["@support_tools.system_info.ezc.factory", buildEzcSystemInfo]
support_tools.system_info.ezc.wrapper:
class: "%support_tools.system_info.ezc.wrapper.class%"
lazy: true

support_tools.system_info.ezc.factory:
class: "%support_tools.system_info.ezc.factory.class%"


# SystemInfoCollectors

Expand All @@ -50,14 +46,14 @@ services:
support_tools.system_info.collector.hardware.ezc:
class: "%support_tools.system_info.collector.hardware.ezc.class%"
arguments:
- "@support_tools.system_info.ezc"
- "@support_tools.system_info.ezc.wrapper"
tags:
- { name: "support_tools.system_info.collector", identifier: "hardware" }

support_tools.system_info.collector.php.ezc:
class: "%support_tools.system_info.collector.php.ezc.class%"
arguments:
- "@support_tools.system_info.ezc"
- "@support_tools.system_info.ezc.wrapper"
tags:
- { name: "support_tools.system_info.collector", identifier: "php" }

Expand Down
8 changes: 3 additions & 5 deletions SystemInfo/Collector/EzcHardwareSystemInfoCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
namespace EzSystems\EzSupportToolsBundle\SystemInfo\Collector;

use ezcSystemInfo;
use EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoWrapper;
use EzSystems\EzSupportToolsBundle\SystemInfo\Value;

/**
Expand All @@ -17,13 +17,11 @@
class EzcHardwareSystemInfoCollector implements SystemInfoCollector
{
/**
* ezcSystemInfo from eZ Components
*
* @var \ezcSystemInfo
* @var \EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoWrapper
*/
private $ezcSystemInfo;

public function __construct(ezcSystemInfo $ezcSystemInfo)
public function __construct(EzcSystemInfoWrapper $ezcSystemInfo)
{
$this->ezcSystemInfo = $ezcSystemInfo;
}
Expand Down
8 changes: 3 additions & 5 deletions SystemInfo/Collector/EzcPhpSystemInfoCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
namespace EzSystems\EzSupportToolsBundle\SystemInfo\Collector;

use ezcSystemInfo;
use EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoWrapper;
use EzSystems\EzSupportToolsBundle\SystemInfo\Value;

/**
Expand All @@ -17,13 +17,11 @@
class EzcPhpSystemInfoCollector implements SystemInfoCollector
{
/**
* ezcSystemInfo from eZ Components
*
* @var \ezcSystemInfo
* @var \EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoWrapper
*/
private $ezcSystemInfo;

public function __construct(ezcSystemInfo $ezcSystemInfo)
public function __construct(EzcSystemInfoWrapper $ezcSystemInfo)
{
$this->ezcSystemInfo = $ezcSystemInfo;
}
Expand Down
22 changes: 0 additions & 22 deletions SystemInfo/EzcSystemInfoFactory.php

This file was deleted.

69 changes: 69 additions & 0 deletions SystemInfo/EzcSystemInfoWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/**
* File containing the EzcSystemInfoWrapper class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzSupportToolsBundle\SystemInfo;

use ezcSystemInfo;
use ezcSystemInfoReaderCantScanOSException;

/**
* This wraps zetacomponents/sysinfo, exposing its magic properties as public properties.
* Used here to allow lazy loading.
*/
class EzcSystemInfoWrapper
{
/** @var string */
public $osType;

/** @var string */
public $osName;

/** @var string */
public $fileSystemType;

/** @var integer */
public $cpuCount;

/** @var string */
public $cpuType;

/** @var float */
public $cpuSpeed;

/** @var integer */
public $memorySize;

/** @var string */
public $lineSeparator;

/** @var string */
public $backupFileName;

/** @var array */
public $phpVersion;

/** @var \ezcSystemInfoAccelerator */
public $phpAccelerator;

/** @var bool */
public $isShellExecution;

public function __construct()
{
try {
$ezcSystemInfo = ezcSystemInfo::getInstance();
} catch(ezcSystemInfoReaderCantScanOSException $e) {
// Leave properties as null: https://github.com/zetacomponents/SystemInformation/pull/9
return;
}

foreach (array_keys(get_object_vars($this)) as $var) {
$this->$var = $ezcSystemInfo->$var;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@

use EzSystems\EzSupportToolsBundle\SystemInfo\Collector\EzcHardwareSystemInfoCollector;
use EzSystems\EzSupportToolsBundle\SystemInfo\Value\HardwareSystemInfo;
use ezcSystemInfo;
use PHPUnit_Framework_TestCase;

class EzcHardwareSystemInfoCollectorTest extends PHPUnit_Framework_TestCase
{
/**
* @var ezcSystemInfo|\PHPUnit_Framework_MockObject_MockObject
* @var \EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoWrapper|\PHPUnit_Framework_MockObject_MockObject
*/
private $ezcSystemInfoMock;

Expand All @@ -27,7 +26,10 @@ class EzcHardwareSystemInfoCollectorTest extends PHPUnit_Framework_TestCase

public function setUp()
{
$this->ezcSystemInfoMock = $this->getMockBuilder('ezcSystemInfo')->disableOriginalConstructor()->getMock();
$this->ezcSystemInfoMock = $this
->getMockBuilder('EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoWrapper')
->disableOriginalConstructor()
->getMock();
$this->ezcSystemInfoMock->cpuType = 'Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz';
$this->ezcSystemInfoMock->cpuSpeed = '2591.9000000000001';
$this->ezcSystemInfoMock->cpuCount = '1';
Expand Down
8 changes: 5 additions & 3 deletions Tests/SystemInfo/Collector/EzcPhpSystemInfoCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@

use EzSystems\EzSupportToolsBundle\SystemInfo\Collector\EzcPhpSystemInfoCollector;
use EzSystems\EzSupportToolsBundle\SystemInfo\Value\PhpSystemInfo;
use ezcSystemInfo;
use PHPUnit_Framework_TestCase;

class EzcPhpSystemInfoCollectorTest extends PHPUnit_Framework_TestCase
{
/**
* @var ezcSystemInfo|\PHPUnit_Framework_MockObject_MockObject
* @var \EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoWrapper|\PHPUnit_Framework_MockObject_MockObject
*/
private $ezcSystemInfoMock;

Expand All @@ -27,7 +26,10 @@ class EzcPhpSystemInfoCollectorTest extends PHPUnit_Framework_TestCase

public function setUp()
{
$this->ezcSystemInfoMock = $this->getMockBuilder('ezcSystemInfo')->disableOriginalConstructor()->getMock();
$this->ezcSystemInfoMock = $this
->getMockBuilder('EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoWrapper')
->disableOriginalConstructor()
->getMock();
$this->ezcSystemInfoMock->phpVersion = phpversion();

$this->ezcSystemInfoMock->phpAccelerator = $this
Expand Down

0 comments on commit c8283cc

Please sign in to comment.