4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\Transformation\Transformation;
13 use Behat\Behat\Definition\Call\DefinitionCall;
14 use Behat\Behat\Transformation\Call\TransformationCall;
15 use Behat\Behat\Transformation\SimpleArgumentTransformation;
16 use Behat\Testwork\Call\CallCenter;
17 use Behat\Testwork\Call\RuntimeCallee;
21 * Token name based transformation.
23 * @author Konstantin Kudryashov <ever.zet@gmail.com>
25 final class TokenNameTransformation extends RuntimeCallee implements SimpleArgumentTransformation
27 const PATTERN_REGEX = '/^\:\w+$/';
38 static public function supportsPatternAndMethod($pattern, ReflectionMethod $method)
40 return 1 === preg_match(self::PATTERN_REGEX, $pattern);
44 * Initializes transformation.
46 * @param string $pattern
47 * @param callable $callable
48 * @param null|string $description
50 public function __construct($pattern, $callable, $description = null)
52 $this->pattern = $pattern;
54 parent::__construct($callable, $description);
60 public function supportsDefinitionAndArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
62 return ':' . $argumentIndex === $this->pattern;
68 public function transformArgument(CallCenter $callCenter, DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
70 $call = new TransformationCall(
71 $definitionCall->getEnvironment(),
72 $definitionCall->getCallee(),
77 $result = $callCenter->makeCall($call);
79 if ($result->hasException()) {
80 throw $result->getException();
83 return $result->getReturn();
89 public function getPriority()
97 public function getPattern()
99 return $this->pattern;
105 public function __toString()
107 return 'TokenNameTransform ' . $this->pattern;