Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Call / Handler / Exception / ClassNotFoundHandler.php
diff --git a/vendor/behat/behat/src/Behat/Testwork/Call/Handler/Exception/ClassNotFoundHandler.php b/vendor/behat/behat/src/Behat/Testwork/Call/Handler/Exception/ClassNotFoundHandler.php
new file mode 100644 (file)
index 0000000..8d0f488
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+
+/*
+ * This file is part of the Behat Testwork.
+ * (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\Testwork\Call\Handler\Exception;
+
+use Behat\Testwork\Call\Handler\ExceptionHandler;
+use Error;
+
+/**
+ * Handles class not found exceptions.
+ *
+ * @see ExceptionHandler
+ *
+ * @author Konstantin Kudryashov <ever.zet@gmail.com>
+ */
+abstract class ClassNotFoundHandler implements ExceptionHandler
+{
+    const PATTERN = "/^Class '([^']+)' not found$/";
+
+    /**
+     * {@inheritdoc}
+     */
+    final public function supportsException($exception)
+    {
+        if (!$exception instanceof Error) {
+            return false;
+        }
+
+        return null !== $this->extractNonExistentClass($exception);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    final public function handleException($exception)
+    {
+        $this->handleNonExistentClass($this->extractNonExistentClass($exception));
+
+        return $exception;
+    }
+
+    /**
+     * Override to handle non-existent class name.
+     *
+     * @param string $class
+     */
+    abstract public function handleNonExistentClass($class);
+
+    /**
+     * Extracts missing class name from the exception.
+     *
+     * @param Error $exception
+     *
+     * @return null|string
+     */
+    private function extractNonExistentClass(Error $exception)
+    {
+        if (1 === preg_match(self::PATTERN, $exception->getMessage(), $matches)) {
+            return $matches[1];
+        }
+
+        return null;
+    }
+}