Skip to content

Commit

Permalink
Merge the non-intrusive bits from PR #81
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Nov 20, 2016
1 parent 6a7fc9a commit 6a717d8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion API/ReferenceBagInterface.php
Expand Up @@ -12,8 +12,9 @@ interface ReferenceBagInterface
*
* @param string $identifier The identifier of the reference
* @param mixed $value The value of the reference
* @param bool $overwrite do overwrite the existing ref if it exist without raising an exception
* @return bool true if the reference is accepted by this resolver, otherwise false
* @throws \Exception When there is a reference with the specified $identifier already.
*/
public function addReference($identifier, $value);
public function addReference($identifier, $value, $overwrite = false);
}
5 changes: 3 additions & 2 deletions Core/ReferenceResolver/ChainResolver.php
Expand Up @@ -73,13 +73,14 @@ public function resolveReference($stringIdentifier)
*
* @param string $identifier
* @param mixed $value
* @param bool $overwrite do overwrite the existing ref if it exist without raising an exception
* @return bool
*/
public function addReference($identifier, $value)
public function addReference($identifier, $value, $overwrite = false)
{
foreach ($this->resolvers as $resolver) {
if ($resolver instanceof ReferenceBagInterface) {
if ($resolver->addReference($identifier, $value)) {
if ($resolver->addReference($identifier, $value, $overwrite)) {
return true;
}
}
Expand Down
5 changes: 3 additions & 2 deletions Core/ReferenceResolver/CustomReferenceResolver.php
Expand Up @@ -43,12 +43,13 @@ public function getReferenceValue($identifier)
*
* @param string $identifier The identifier of the reference
* @param mixed $value The value of the reference
* @param bool $overwrite do overwrite the existing ref if it exist without raising an exception
* @return bool true if the reference is accepted by this resolver, otherwise false
* @throws \Exception When there is a reference with the specified $identifier already.
*/
public function addReference($identifier, $value)
public function addReference($identifier, $value, $overwrite = false)
{
if (array_key_exists($identifier, $this->references)) {
if (array_key_exists($identifier, $this->references) && !$overwrite) {
throw new \Exception("A reference with identifier '$identifier' already exists");
}

Expand Down

0 comments on commit 6a717d8

Please sign in to comment.