Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Definition / Translator / DefinitionTranslator.php
diff --git a/vendor/behat/behat/src/Behat/Behat/Definition/Translator/DefinitionTranslator.php b/vendor/behat/behat/src/Behat/Behat/Definition/Translator/DefinitionTranslator.php
new file mode 100644 (file)
index 0000000..3192a3d
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+
+/*
+ * This file is part of the Behat.
+ * (c) Konstantin Kudryashov <ever.zet@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Behat\Behat\Definition\Translator;
+
+use Behat\Behat\Definition\Definition;
+use Behat\Testwork\Suite\Suite;
+use Symfony\Component\Translation\TranslatorInterface;
+
+/**
+ * Translates definitions using translator component.
+ *
+ * @author Konstantin Kudryashov <ever.zet@gmail.com>
+ */
+final class DefinitionTranslator
+{
+    /**
+     * @var TranslatorInterface
+     */
+    private $translator;
+
+    /**
+     * Initialises definition translator.
+     *
+     * @param TranslatorInterface $translator
+     */
+    public function __construct(TranslatorInterface $translator)
+    {
+        $this->translator = $translator;
+    }
+
+    /**
+     * Attempts to translate definition using translator and produce translated one on success.
+     *
+     * @param Suite       $suite
+     * @param Definition  $definition
+     * @param null|string $language
+     *
+     * @return Definition|TranslatedDefinition
+     */
+    public function translateDefinition(Suite $suite, Definition $definition, $language = null)
+    {
+        $assetsId = $suite->getName();
+        $pattern = $definition->getPattern();
+
+        $translatedPattern = $this->translator->trans($pattern, array(), $assetsId, $language);
+        if ($pattern != $translatedPattern) {
+            return new TranslatedDefinition($definition, $translatedPattern, $language);
+        }
+
+        return $definition;
+    }
+
+    public function getLocale()
+    {
+        return $this->translator->getLocale();
+    }
+}