-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from ezsystems/ezp-25598_infocollector_registry
Fix EZP-25598: eZSupportTools infocollector registry
- Loading branch information
Showing
12 changed files
with
393 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/** | ||
* File containing the SystemInfoCollectorPass 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\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class SystemInfoCollectorPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* Registers the SystemInfoCollector into the system info collector registry. | ||
* | ||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->has('support_tools.system_info.collector_registry')) { | ||
return; | ||
} | ||
|
||
$infoCollectorsTagged = $container->findTaggedServiceIds('support_tools.system_info.collector'); | ||
|
||
$infoCollectors = []; | ||
foreach ($infoCollectorsTagged as $id => $tags) { | ||
foreach ($tags as $attributes) { | ||
$infoCollectors[$attributes['identifier']] = new Reference($id); | ||
} | ||
} | ||
|
||
$infoCollectorRegistryDef = $container->findDefinition('support_tools.system_info.collector_registry'); | ||
$infoCollectorRegistryDef->setArguments([$infoCollectors]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* File containing the IdentifierBased 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\Registry; | ||
|
||
use eZ\Publish\Core\Base\Exceptions\NotFoundException; | ||
use EzSystems\EzSupportToolsBundle\SystemInfo\SystemInfoCollectorRegistry; | ||
|
||
/** | ||
* A registry of SystemInfoCollectors that uses an identifier string to identify the collector. | ||
*/ | ||
class IdentifierBased implements SystemInfoCollectorRegistry | ||
{ | ||
/** @var \EzSystems\EzSupportToolsBundle\SystemInfo\Collector\SystemInfoCollector[] */ | ||
private $registry = []; | ||
|
||
/** | ||
* @param \EzSystems\EzSupportToolsBundle\SystemInfo\Collector\SystemInfoCollector[] $items Hash of SystemInfoCollectors, with identifier string as key. | ||
*/ | ||
public function __construct(array $items = []) | ||
{ | ||
$this->registry = $items; | ||
} | ||
|
||
/** | ||
* Returns the SystemInfoCollector matching the argument. | ||
* | ||
* @param string $identifier An identifier string. | ||
* | ||
* @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException If no SystemInfoCollector exists with this identifier | ||
* | ||
* @return \EzSystems\EzSupportToolsBundle\SystemInfo\Collector\SystemInfoCollector The SystemInfoCollector given by the identifier. | ||
*/ | ||
public function getItem($identifier) | ||
{ | ||
if (isset($this->registry[$identifier])) { | ||
return $this->registry[$identifier]; | ||
} | ||
|
||
throw new NotFoundException("A SystemInfo collector could not be found.", $identifier); | ||
} | ||
|
||
/** | ||
* Returns the identifiers of all registered SystemInfoCollectors. | ||
* | ||
* @return string[] Array of identifier strings. | ||
*/ | ||
public function getIdentifiers() | ||
{ | ||
return array_keys($this->registry); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/** | ||
* File containing the SystemInfoCollectorRegistry interface. | ||
* | ||
* @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; | ||
|
||
/** | ||
* A registry of SystemInfoCollectors. | ||
*/ | ||
interface SystemInfoCollectorRegistry | ||
{ | ||
/** | ||
* @param \EzSystems\EzSupportToolsBundle\SystemInfo\Collector\SystemInfoCollector[] $items Hash of SystemInfoCollectors, with identifier string as key. | ||
*/ | ||
public function __construct(array $items = []); | ||
|
||
/** | ||
* Returns the SystemInfoCollector matching the argument. | ||
* | ||
* @param string $identifier An identifier string. | ||
* | ||
* @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException If no SystemInfoCollector exists with this identifier | ||
* | ||
* @return \EzSystems\EzSupportToolsBundle\SystemInfo\Collector\SystemInfoCollector The SystemInfoCollector given by the identifier. | ||
*/ | ||
public function getItem($identifier); | ||
|
||
/** | ||
* Returns the identifiers of all registered SystemInfoCollectors. | ||
* | ||
* @return string[] Array of identifier strings. | ||
*/ | ||
public function getIdentifiers(); | ||
} |
Oops, something went wrong.