X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FDefinition%2FPattern%2FPatternTransformer.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FDefinition%2FPattern%2FPatternTransformer.php;h=6af5bacd6b76dbbda891317a57a08eec5b584f4f;hp=0000000000000000000000000000000000000000;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68 diff --git a/vendor/behat/behat/src/Behat/Behat/Definition/Pattern/PatternTransformer.php b/vendor/behat/behat/src/Behat/Behat/Definition/Pattern/PatternTransformer.php new file mode 100644 index 000000000..6af5bacd6 --- /dev/null +++ b/vendor/behat/behat/src/Behat/Behat/Definition/Pattern/PatternTransformer.php @@ -0,0 +1,79 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Behat\Behat\Definition\Pattern; + +use Behat\Behat\Definition\Exception\UnknownPatternException; +use Behat\Behat\Definition\Exception\UnsupportedPatternTypeException; +use Behat\Behat\Definition\Pattern\Policy\PatternPolicy; + +/** + * Transforms patterns using registered policies. + * + * @author Konstantin Kudryashov + */ +final class PatternTransformer +{ + /** + * @var PatternPolicy[] + */ + private $policies = array(); + + /** + * Registers pattern policy. + * + * @param PatternPolicy $policy + */ + public function registerPatternPolicy(PatternPolicy $policy) + { + $this->policies[] = $policy; + } + + /** + * Generates pattern. + * + * @param string $type + * @param string $stepText + * + * @return Pattern + * + * @throws UnsupportedPatternTypeException + */ + public function generatePattern($type, $stepText) + { + foreach ($this->policies as $policy) { + if ($policy->supportsPatternType($type)) { + return $policy->generatePattern($stepText); + } + } + + throw new UnsupportedPatternTypeException(sprintf('Can not find policy for a pattern type `%s`.', $type), $type); + } + + /** + * Transforms pattern string to regex. + * + * @param string $pattern + * + * @return string + * + * @throws UnknownPatternException + */ + public function transformPatternToRegex($pattern) + { + foreach ($this->policies as $policy) { + if ($policy->supportsPattern($pattern)) { + return $policy->transformPatternToRegex($pattern); + } + } + + throw new UnknownPatternException(sprintf('Can not find policy for a pattern `%s`.', $pattern), $pattern); + } +}