Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit 3a5f0a4

Browse files
authored
Merge pull request #2 from weierophinney/feature/add-cli-tool-for-config
Refactor of CliTool
2 parents 0a1cbad + 1078e86 commit 3a5f0a4

12 files changed

+576
-163
lines changed

bin/dump-config.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

bin/generate-deps-for-config-factory

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/**
4+
* @link http://github.com/zendframework/zend-servicemanager for the canonical source repository
5+
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com)
6+
* @license http://framework.zend.com/license/new-bsd New BSD License
7+
*/
8+
9+
namespace Zend\ServiceManager;
10+
11+
// Setup/verify autoloading
12+
if (file_exists($a = getcwd() . '/vendor/autoload.php')) {
13+
require $a;
14+
} elseif (file_exists($a = __DIR__ . '/../../../autoload.php')) {
15+
require $a;
16+
} elseif (file_exists($a = __DIR__ . '/../vendor/autoload.php')) {
17+
require $a;
18+
} else {
19+
fwrite(STDERR, 'Cannot locate autoloader; please run "composer install"' . PHP_EOL);
20+
exit(1);
21+
}
22+
23+
$command = new Tool\ConfigDumperCommand($argv[0]);
24+
$status = $command(array_slice($argv, 1));
25+
exit($status);

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@
4343
},
4444
"provide": {
4545
"container-interop/container-interop-implementation": "^1.1"
46-
}
46+
},
47+
"bin": [
48+
"bin/generate-deps-for-config-factory"
49+
]
4750
}

phpcs.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@
99
<!-- inherit rules from: -->
1010
<rule ref="PSR2"/>
1111
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
12+
<rule ref="Generic.Formatting.SpaceAfterNot"/>
13+
<rule ref="Squiz.WhiteSpace.OperatorSpacing">
14+
<properties>
15+
<property name="ignoreNewlines" value="true"/>
16+
</properties>
17+
</rule>
1218
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
1319
<properties>
1420
<property name="ignoreBlankLines" value="false"/>
1521
</properties>
1622
</rule>
1723

1824
<!-- Paths to check -->
25+
<file>bin</file>
1926
<file>src</file>
2027
<file>test</file>
21-
<file>bin</file>
2228
<exclude-pattern>*/test/log/*</exclude-pattern>
2329
</ruleset>

src/AbstractFactory/ConfigAbstractFactory.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class ConfigAbstractFactory implements AbstractFactoryInterface
2222
*/
2323
public function canCreate(\Interop\Container\ContainerInterface $container, $requestedName)
2424
{
25-
if (!$container->has('config') || !array_key_exists(self::class, $container->get('config'))) {
25+
if (! $container->has('config') || ! array_key_exists(self::class, $container->get('config'))) {
2626
return false;
2727
}
2828
$config = $container->get('config');
@@ -36,25 +36,25 @@ public function canCreate(\Interop\Container\ContainerInterface $container, $req
3636
*/
3737
public function __invoke(\Interop\Container\ContainerInterface $container, $requestedName, array $options = null)
3838
{
39-
if (!$container->has('config')) {
39+
if (! $container->has('config')) {
4040
throw new ServiceNotCreatedException('Cannot find a config array in the container');
4141
}
4242

4343
$config = $container->get('config');
4444

45-
if (!is_array($config)) {
45+
if (! is_array($config)) {
4646
throw new ServiceNotCreatedException('Config must be an array');
4747
}
4848

49-
if (!array_key_exists(self::class, $config)) {
49+
if (! array_key_exists(self::class, $config)) {
5050
throw new ServiceNotCreatedException('Cannot find a `' . self::class . '` key in the config array');
5151
}
5252

5353
$dependencies = $config[self::class];
5454

55-
if (!is_array($dependencies)
56-
|| !array_key_exists($requestedName, $dependencies)
57-
|| !is_array($dependencies[$requestedName])
55+
if (! is_array($dependencies)
56+
|| ! array_key_exists($requestedName, $dependencies)
57+
|| ! is_array($dependencies[$requestedName])
5858
) {
5959
throw new ServiceNotCreatedException('Dependencies config must exist and be an array');
6060
}

src/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private function merge(array $a, array $b)
111111
$a[$key] = $value;
112112
}
113113
} else {
114-
if (!$value instanceof MergeRemoveKey) {
114+
if (! $value instanceof MergeRemoveKey) {
115115
$a[$key] = $value;
116116
}
117117
}

src/ServiceManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ private function resolveAbstractFactories(array $abstractFactories)
520520
foreach ($abstractFactories as $abstractFactory) {
521521
if (is_string($abstractFactory) && class_exists($abstractFactory)) {
522522
//Cached string
523-
if (!isset($this->cachedAbstractFactories[$abstractFactory])) {
523+
if (! isset($this->cachedAbstractFactories[$abstractFactory])) {
524524
$this->cachedAbstractFactories[$abstractFactory] = new $abstractFactory();
525525
}
526526

@@ -754,7 +754,7 @@ private function createDelegatorFromName($name, array $options = null)
754754
private function doCreate($resolvedName, array $options = null)
755755
{
756756
try {
757-
if (!isset($this->delegators[$resolvedName])) {
757+
if (! isset($this->delegators[$resolvedName])) {
758758
// Let's create the service by fetching the factory
759759
$factory = $this->getFactory($resolvedName);
760760
$object = $factory($this->creationContext, $resolvedName, $options);
@@ -889,7 +889,7 @@ private function createFactoriesForInvokables(array $invokables)
889889
*/
890890
private function validateOverrides(array $config)
891891
{
892-
if ($this->allowOverride || !$this->configured) {
892+
if ($this->allowOverride || ! $this->configured) {
893893
return;
894894
}
895895

src/Tool/CliTool.php

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)