Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Transformation / Transformation / TableRowTransformation.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\Transformation\Transformation;
12
13 use Behat\Behat\Definition\Call\DefinitionCall;
14 use Behat\Behat\Transformation\Call\TransformationCall;
15 use Behat\Behat\Transformation\SimpleArgumentTransformation;
16 use Behat\Gherkin\Node\TableNode;
17 use Behat\Testwork\Call\CallCenter;
18 use Behat\Testwork\Call\RuntimeCallee;
19 use ReflectionMethod;
20
21 /**
22  * Table row transformation.
23  *
24  * @author Konstantin Kudryashov <ever.zet@gmail.com>
25  */
26 final class TableRowTransformation extends RuntimeCallee implements SimpleArgumentTransformation
27 {
28     const PATTERN_REGEX = '/^row\:[[:print:]]+$/';
29
30     /**
31      * @var string
32      */
33     private $pattern;
34
35     /**
36      * {@inheritdoc}
37      */
38     static public function supportsPatternAndMethod($pattern, ReflectionMethod $method)
39     {
40         return 1 === preg_match(self::PATTERN_REGEX, $pattern);
41     }
42
43     /**
44      * Initializes transformation.
45      *
46      * @param string      $pattern
47      * @param callable    $callable
48      * @param null|string $description
49      */
50     public function __construct($pattern, $callable, $description = null)
51     {
52         $this->pattern = $pattern;
53
54         parent::__construct($callable, $description);
55     }
56
57     /**
58      * {@inheritdoc}
59      */
60     public function supportsDefinitionAndArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
61     {
62         if (!$argumentValue instanceof TableNode) {
63             return false;
64         };
65
66         return $this->pattern === 'row:' . implode(',', $argumentValue->getRow(0));
67     }
68
69     /**
70      * {@inheritdoc}
71      */
72     public function transformArgument(CallCenter $callCenter, DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
73     {
74         $rows = array();
75         foreach ($argumentValue as $row) {
76             $call = new TransformationCall(
77                 $definitionCall->getEnvironment(),
78                 $definitionCall->getCallee(),
79                 $this,
80                 array($row)
81             );
82
83             $result = $callCenter->makeCall($call);
84
85             if ($result->hasException()) {
86                 throw $result->getException();
87             }
88
89             $rows[] = $result->getReturn();
90         }
91
92         return $rows;
93     }
94
95     /**
96      * {@inheritdoc}
97      */
98     public function getPriority()
99     {
100         return 50;
101     }
102
103     /**
104      * {@inheritdoc}
105      */
106     public function getPattern()
107     {
108         return $this->pattern;
109     }
110
111     /**
112      * {@inheritdoc}
113      */
114     public function __toString()
115     {
116         return 'TableRowTransform ' . $this->pattern;
117     }
118 }