Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Transformation / Transformation / ColumnBasedTableTransformation.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  * Column-based table transformation.
23  *
24  * @author Konstantin Kudryashov <ever.zet@gmail.com>
25  */
26 final class ColumnBasedTableTransformation extends RuntimeCallee implements SimpleArgumentTransformation
27 {
28     const PATTERN_REGEX = '/^table\:(?:\*|[[: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 === 'table:' . implode(',', $argumentValue->getRow(0))
67             || $this->pattern === 'table:*';
68     }
69
70     /**
71      * {@inheritdoc}
72      */
73     public function transformArgument(CallCenter $callCenter, DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
74     {
75         $call = new TransformationCall(
76             $definitionCall->getEnvironment(),
77             $definitionCall->getCallee(),
78             $this,
79             array($argumentValue)
80         );
81
82         $result = $callCenter->makeCall($call);
83
84         if ($result->hasException()) {
85             throw $result->getException();
86         }
87
88         return $result->getReturn();
89     }
90
91     /**
92      * {@inheritdoc}
93      */
94     public function getPriority()
95     {
96         return 50;
97     }
98
99     /**
100      * {@inheritdoc}
101      */
102     public function getPattern()
103     {
104         return $this->pattern;
105     }
106
107     /**
108      * {@inheritdoc}
109      */
110     public function __toString()
111     {
112         return 'ColumnTableTransform ' . $this->pattern;
113     }
114 }