HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/magento.bikenow.co/vendor/laminas/laminas-captcha/src/Factory.php
<?php // phpcs:disable Generic.NamingConventions.ConstructorName.OldStyle,WebimpressCodingStandard.NamingConventions.AbstractClass.Prefix

/**
 * @see       https://github.com/laminas/laminas-captcha for the canonical source repository
 * @copyright https://github.com/laminas/laminas-captcha/blob/master/COPYRIGHT.md
 * @license   https://github.com/laminas/laminas-captcha/blob/master/LICENSE.md New BSD License
 */

namespace Laminas\Captcha;

use Laminas\Captcha\Dumb;
use Laminas\Captcha\Figlet;
use Laminas\Captcha\Image;
use Laminas\Captcha\ReCaptcha;
use Laminas\Stdlib\ArrayUtils;
use Traversable;

use function class_exists;
use function get_class;
use function gettype;
use function is_array;
use function is_object;
use function sprintf;
use function strtolower;

abstract class Factory
{
    /** @var array Known captcha types */
    protected static $classMap = [
        'dumb'      => Dumb::class,
        'figlet'    => Figlet::class,
        'image'     => Image::class,
        'recaptcha' => ReCaptcha::class,
    ];

    /**
     * Create a captcha adapter instance
     *
     * @param  array|Traversable $options
     * @return AdapterInterface
     * @throws Exception\InvalidArgumentException For a non-array, non-Traversable $options.
     * @throws Exception\DomainException If class is missing or invalid.
     */
    public static function factory($options)
    {
        if ($options instanceof Traversable) {
            $options = ArrayUtils::iteratorToArray($options);
        }

        if (! is_array($options)) {
            throw new Exception\InvalidArgumentException(sprintf(
                '%s expects an array or Traversable argument; received "%s"',
                __METHOD__,
                is_object($options) ? get_class($options) : gettype($options)
            ));
        }

        if (! isset($options['class'])) {
            throw new Exception\DomainException(sprintf(
                '%s expects a "class" attribute in the options; none provided',
                __METHOD__
            ));
        }

        $class = $options['class'];
        if (isset(static::$classMap[strtolower($class)])) {
            $class = static::$classMap[strtolower($class)];
        }
        if (! class_exists($class)) {
            throw new Exception\DomainException(sprintf(
                '%s expects the "class" attribute to resolve to an existing class; received "%s"',
                __METHOD__,
                $class
            ));
        }

        unset($options['class']);

        if (isset($options['options'])) {
            $options = $options['options'];
        }
        $captcha = new $class($options);

        if (! $captcha instanceof AdapterInterface) {
            throw new Exception\DomainException(sprintf(
                '%s expects the "class" attribute to resolve to a valid %s instance; received "%s"',
                __METHOD__,
                AdapterInterface::class,
                $class
            ));
        }

        return $captcha;
    }
}