This repository has been archived by the owner on Feb 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
Generate deps ignoring unresolved dependencies #176
Closed
thomasvargiu
wants to merge
1
commit into
zendframework:develop
from
thomasvargiu:feature/generate-deps-ignoring-unresolved
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
namespace Zend\ServiceManager\Tool; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use ReflectionClass; | ||
use ReflectionParameter; | ||
use Traversable; | ||
|
@@ -25,13 +26,35 @@ class ConfigDumper | |
return %s; | ||
EOC; | ||
|
||
/** | ||
* @var ContainerInterface | ||
*/ | ||
protected $container; | ||
|
||
/** | ||
* @param ContainerInterface $container | ||
*/ | ||
public function __construct(ContainerInterface $container = null) | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* @param ContainerInterface $container | ||
*/ | ||
public function setContainer(ContainerInterface $container) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this setter really necessary? If it is, then use it from |
||
{ | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* @param array $config | ||
* @param string $className | ||
* @param bool $ignoreUnresolved | ||
* @return array | ||
* @throws InvalidArgumentException for invalid $className | ||
*/ | ||
public function createDependencyConfig(array $config, $className) | ||
public function createDependencyConfig(array $config, $className, $ignoreUnresolved = false) | ||
{ | ||
$this->validateClassName($className); | ||
|
||
|
@@ -60,22 +83,32 @@ function (ReflectionParameter $argument) { | |
return $this->createInvokable($config, $className); | ||
} | ||
|
||
$config[ConfigAbstractFactory::class][$className] = []; | ||
$classConfig = []; | ||
|
||
foreach ($constructorArguments as $constructorArgument) { | ||
$argumentType = $constructorArgument->getClass(); | ||
if (is_null($argumentType)) { | ||
if ($ignoreUnresolved) { | ||
// don't throw an exception, just return the previous config | ||
return $config; | ||
} | ||
// don't throw an exception if the class is an already defined service | ||
if ($this->container && $this->container->has($className)) { | ||
return $config; | ||
} | ||
throw new InvalidArgumentException(sprintf( | ||
'Cannot create config for constructor argument "%s", ' | ||
. 'it has no type hint, or non-class/interface type hint', | ||
$constructorArgument->getName() | ||
)); | ||
} | ||
$argumentName = $argumentType->getName(); | ||
$config = $this->createDependencyConfig($config, $argumentName); | ||
$config[ConfigAbstractFactory::class][$className][] = $argumentName; | ||
$config = $this->createDependencyConfig($config, $argumentName, $ignoreUnresolved); | ||
$classConfig[] = $argumentName; | ||
} | ||
|
||
$config[ConfigAbstractFactory::class][$className] = $classConfig; | ||
|
||
return $config; | ||
} | ||
|
||
|
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,15 @@ | ||
<?php | ||
/** | ||
* @link http://github.com/zendframework/zend-servicemanager for the canonical source repository | ||
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2017, not 2016. 😄 |
||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\ServiceManager\TestAsset; | ||
|
||
class ObjectWithObjectScalarDependency | ||
{ | ||
public function __construct(SimpleDependencyObject $simpleDependencyObject, ObjectWithScalarDependency $dependency) | ||
{ | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private
visibility, please.