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\Context\Annotation;
13 use Behat\Behat\Context\Annotation\AnnotationReader;
14 use Behat\Behat\Transformation\Transformation\PatternTransformation;
15 use Behat\Behat\Transformation\Transformation;
19 * Step transformation annotation reader.
21 * Reads step transformations from a context method annotation.
23 * @author Konstantin Kudryashov <ever.zet@gmail.com>
25 class TransformationAnnotationReader implements AnnotationReader
30 private static $regex = '/^\@transform\s*+(.*+)$/i';
33 * Loads step callees (if exist) associated with specific method.
35 * @param string $contextClass
36 * @param ReflectionMethod $method
37 * @param string $docLine
38 * @param string $description
40 * @return null|Transformation
42 public function readCallee($contextClass, ReflectionMethod $method, $docLine, $description)
44 if (!preg_match(self::$regex, $docLine, $match)) {
49 $callable = array($contextClass, $method->getName());
51 foreach ($this->simpleTransformations() as $transformation) {
52 if ($transformation::supportsPatternAndMethod($pattern, $method)) {
53 return new $transformation($pattern, $callable, $description);
57 return new PatternTransformation($pattern, $callable, $description);
61 * Returns list of default transformations.
65 private function simpleTransformations()
67 $transformations = array();
68 $transformations[] = 'Behat\Behat\Transformation\Transformation\RowBasedTableTransformation';
69 $transformations[] = 'Behat\Behat\Transformation\Transformation\ColumnBasedTableTransformation';
70 $transformations[] = 'Behat\Behat\Transformation\Transformation\TableRowTransformation';
72 if (PHP_VERSION_ID >= 70000) {
73 $transformations[] = 'Behat\Behat\Transformation\Transformation\TokenNameAndReturnTypeTransformation';
74 $transformations[] = 'Behat\Behat\Transformation\Transformation\ReturnTypeTransformation';
77 $transformations[] = 'Behat\Behat\Transformation\Transformation\TokenNameTransformation';
79 return $transformations;