-
-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to use `$current` variable outside of the identity context and more peticuliarly allow to use expressions such as `@user$current`. Closes #761
- Loading branch information
Showing
12 changed files
with
211 additions
and
7 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
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
70 changes: 70 additions & 0 deletions
70
...eBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/VariableReferenceTokenParser.php
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,70 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Alice package. | ||
* | ||
* (c) Nelmio <hello@nelm.io> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Parser\TokenParser\Chainable; | ||
|
||
use InvalidArgumentException; | ||
use Nelmio\Alice\Definition\Value\FixtureReferenceValue; | ||
use Nelmio\Alice\Definition\Value\FunctionCallValue; | ||
use Nelmio\Alice\Definition\Value\ListValue; | ||
use Nelmio\Alice\Definition\Value\ValueForCurrentValue; | ||
use Nelmio\Alice\Definition\Value\VariableValue; | ||
use Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Parser\ChainableTokenParserInterface; | ||
use Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Token; | ||
use Nelmio\Alice\FixtureBuilder\ExpressionLanguage\TokenType; | ||
use Nelmio\Alice\IsAServiceTrait; | ||
use Nelmio\Alice\Throwable\Exception\FixtureBuilder\ExpressionLanguage\ExpressionLanguageExceptionFactory; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class VariableReferenceTokenParser implements ChainableTokenParserInterface | ||
{ | ||
use IsAServiceTrait; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function canParse(Token $token): bool | ||
{ | ||
return $token->getType() === TokenType::VARIABLE_REFERENCE_TYPE; | ||
} | ||
|
||
/** | ||
* Parses expressions such as "@user$foo". | ||
* | ||
* {@inheritdoc} | ||
*/ | ||
public function parse(Token $token): FixtureReferenceValue | ||
{ | ||
$parts = explode('$', $token->getValue()); | ||
|
||
$variable = $parts[1]; | ||
|
||
try { | ||
return new FixtureReferenceValue( | ||
new ListValue([ | ||
substr($parts[0], 1), | ||
'current' === $variable | ||
? new FunctionCallValue( | ||
'current', | ||
[new ValueForCurrentValue()] | ||
) | ||
: new VariableValue($variable) | ||
]) | ||
); | ||
} catch (InvalidArgumentException $exception) { | ||
throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token, 0, $exception); | ||
} | ||
} | ||
} |
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
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