-
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.
EZP-26549: Output pretty JSON in dump-info command (#23)
EZP-26549: Output pretty JSON in dump-info command
- Loading branch information
João Inácio
authored
Nov 23, 2016
1 parent
c8283cc
commit 0eb6620
Showing
7 changed files
with
200 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/** | ||
* File containing the OutputFormatPass 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 OutputFormatPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* Registers the OutputFormat tagged services into the output format registry. | ||
* | ||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->has('support_tools.system_info.output_registry')) { | ||
return; | ||
} | ||
|
||
$outputFormattersTagged = $container->findTaggedServiceIds('support_tools.system_info.output_format'); | ||
|
||
$outputFormatters = []; | ||
foreach ($outputFormattersTagged as $id => $tags) { | ||
foreach ($tags as $attributes) { | ||
$outputFormatters[$attributes['format']] = new Reference($id); | ||
} | ||
} | ||
|
||
$outputFormatRegistryDef = $container->findDefinition('support_tools.system_info.output_registry'); | ||
$outputFormatRegistryDef->setArguments([$outputFormatters]); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
/** | ||
* File containing the OutputFormat 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; | ||
|
||
interface OutputFormat | ||
{ | ||
/** | ||
* Format an array of collected information data, and return it as string | ||
* | ||
* @param array $collectedInfo | ||
* @return string | ||
*/ | ||
public function format(array $collectedInfo); | ||
} |
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,22 @@ | ||
<?php | ||
|
||
/** | ||
* File containing the JsonOutputFormat 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\OutputFormat; | ||
|
||
use EzSystems\EzSupportToolsBundle\SystemInfo\OutputFormat as SystemInfoOutputFormat; | ||
|
||
/** | ||
* Implements the JSON output format. | ||
*/ | ||
class JsonOutputFormat implements SystemInfoOutputFormat | ||
{ | ||
public function format(array $collectedInfo) | ||
{ | ||
return json_encode( $collectedInfo, JSON_PRETTY_PRINT); | ||
} | ||
} |
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,56 @@ | ||
<?php | ||
|
||
/** | ||
* File containing the OutputFormatRegistry 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 eZ\Publish\Core\Base\Exceptions\NotFoundException; | ||
|
||
/** | ||
* A registry of OutputFormats. | ||
*/ | ||
class OutputFormatRegistry | ||
{ | ||
/** @var \EzSystems\EzSupportToolsBundle\SystemInfo\OutputFormat[] */ | ||
private $registry = []; | ||
|
||
/** | ||
* @param \EzSystems\EzSupportToolsBundle\SystemInfo\OutputFormat[] $items Hash of OutputFormats, with identifier string as key. | ||
*/ | ||
public function __construct(array $items = []) | ||
{ | ||
$this->registry = $items; | ||
} | ||
|
||
/** | ||
* Returns the OutputFormat matching the argument. | ||
* | ||
* @param string $identifier An identifier string. | ||
* | ||
* @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException If no OutputFormat exists with this identifier | ||
* | ||
* @return \EzSystems\EzSupportToolsBundle\SystemInfo\Collector\OutputFormat The OutputFormat given by the identifier. | ||
*/ | ||
public function getItem($identifier) | ||
{ | ||
if (isset($this->registry[$identifier])) { | ||
return $this->registry[$identifier]; | ||
} | ||
|
||
throw new NotFoundException("A SystemInfo output format could not be found.", $identifier); | ||
} | ||
|
||
/** | ||
* Returns the identifiers of all registered OutputFormats. | ||
* | ||
* @return string[] Array of identifier strings. | ||
*/ | ||
public function getIdentifiers() | ||
{ | ||
return array_keys($this->registry); | ||
} | ||
} |