-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for multiple service annotations #238
Open
wodka
wants to merge
3
commits into
schmittjoh:master
Choose a base branch
from
wodka:service-multiple
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -10,4 +10,6 @@ | |
*/ | ||
final class AfterSetup | ||
{ | ||
/** @var array */ | ||
public $services; | ||
} |
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,9 @@ | ||
<?php | ||
|
||
namespace JMS\DiExtraBundle\Exception; | ||
|
||
/** | ||
* parent can be invalid if there is more than one service | ||
*/ | ||
class InvalidParentException extends RuntimeException | ||
{} |
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 |
---|---|---|
|
@@ -21,33 +21,140 @@ | |
use Metadata\ClassMetadata as BaseClassMetadata; | ||
|
||
/** | ||
* class metadata | ||
* processed annotations for service creation | ||
*/ | ||
class ClassMetadata extends BaseClassMetadata | ||
{ | ||
/** | ||
* @var string | ||
* @deprecated use addService instead | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @var string | ||
* @deprecated use addService instead | ||
*/ | ||
public $parent; | ||
|
||
/** | ||
* @var string | ||
* @deprecated use addService instead, removed in SF 3.0 | ||
*/ | ||
public $scope; | ||
|
||
/** | ||
* @var bool | ||
* @deprecated use addService instead | ||
*/ | ||
public $public; | ||
|
||
/** | ||
* @var boolean | ||
* @deprecated use addService instead | ||
*/ | ||
public $abstract; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $tags = array(); | ||
|
||
/** | ||
* constructor arguments | ||
* | ||
* @var array | ||
*/ | ||
public $arguments; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $methodCalls = array(); | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $lookupMethods = array(); | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $properties = array(); | ||
/** | ||
* @deprecated since version 1.7, to be removed in 2.0. Use $initMethods instead. | ||
*/ | ||
public $initMethod; | ||
public $initMethods = array(); | ||
|
||
/** | ||
* @deprecated use addService instead | ||
* | ||
* @var string[] | ||
*/ | ||
public $environments = array(); | ||
public $decorates; | ||
public $decoration_inner_name; | ||
public $deprecated; | ||
|
||
/** | ||
* @param string $env | ||
* service definitions | ||
* | ||
* @var array[] | ||
*/ | ||
private $services = array(); | ||
|
||
/** | ||
* on first call also populate legacy fields | ||
* | ||
* @param string[] $service | ||
*/ | ||
public function addService(array $service) | ||
{ | ||
if (empty($this->id)) { | ||
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. IMO we should deprecate all this attributes 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. I added the deprecated annotation to old properties |
||
$this->id = $service['id']; | ||
$this->parent = @$service['parent']; | ||
$this->public = @$service['public']; | ||
$this->scope = @$service['scope']; | ||
$this->abstract = @$service['abstract']; | ||
$this->environments = @$service['environments']; | ||
// TODO update call for other tags (there are several pull requests) | ||
} | ||
|
||
$this->services[$service['id']] = $service; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasServices() | ||
{ | ||
return !empty($this->services); | ||
} | ||
|
||
/** | ||
* get list of defined services, use fallback of original fields | ||
* | ||
* @return array[] | ||
*/ | ||
public function getServices() | ||
{ | ||
// TODO remove fallback for next major version | ||
if (empty($this->services) || !isset($this->services[$this->id])) { | ||
$this->services[] = array( | ||
'id' => $this->id, | ||
'parent' => $this->parent, | ||
'public' => $this->public, | ||
'scope' => $this->scope, | ||
'abstract' => $this->abstract, | ||
'environments' => $this->environments, | ||
); | ||
} | ||
|
||
return $this->services; | ||
} | ||
|
||
/** | ||
* @deprecated this is handled on service level | ||
* | ||
* @param string $env | ||
* @return bool | ||
*/ | ||
public function isLoadedInEnvironment($env) | ||
|
@@ -78,9 +185,7 @@ public function serialize() | |
$this->initMethod, | ||
parent::serialize(), | ||
$this->environments, | ||
$this->decorates, | ||
$this->decoration_inner_name, | ||
$this->deprecated, | ||
$this->services, | ||
)); | ||
} | ||
|
||
|
@@ -106,9 +211,7 @@ public function unserialize($str) | |
$this->initMethod, | ||
$parentStr, | ||
$this->environments, | ||
$this->decorates, | ||
$this->decoration_inner_name, | ||
$this->deprecated, | ||
$this->services, | ||
) = $data; | ||
|
||
parent::unserialize($parentStr); | ||
|
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
Oops, something went wrong.
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.
Is this related?
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.
before the environment check could be done on class level, but since we have now multiple services per class we have to check in there