fix calendar css, take 2. (#213)
[openemr.git] / interface / modules / zend_modules / library / Zend / Captcha / Factory.php
blobff7e6b825a30a72ad6fd148fe84d66f37119ec50
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Captcha;
12 use Traversable;
13 use Zend\Stdlib\ArrayUtils;
15 abstract class Factory
17 /**
18 * @var array Known captcha types
20 protected static $classMap = array(
21 'dumb' => 'Zend\Captcha\Dumb',
22 'figlet' => 'Zend\Captcha\Figlet',
23 'image' => 'Zend\Captcha\Image',
24 'recaptcha' => 'Zend\Captcha\ReCaptcha',
27 /**
28 * Create a captcha adapter instance
30 * @param array|Traversable $options
31 * @return AdapterInterface
32 * @throws Exception\InvalidArgumentException for a non-array, non-Traversable $options
33 * @throws Exception\DomainException if class is missing or invalid
35 public static function factory($options)
37 if ($options instanceof Traversable) {
38 $options = ArrayUtils::iteratorToArray($options);
41 if (!is_array($options)) {
42 throw new Exception\InvalidArgumentException(sprintf(
43 '%s expects an array or Traversable argument; received "%s"',
44 __METHOD__,
45 (is_object($options) ? get_class($options) : gettype($options))
46 ));
49 if (!isset($options['class'])) {
50 throw new Exception\DomainException(sprintf(
51 '%s expects a "class" attribute in the options; none provided',
52 __METHOD__
53 ));
56 $class = $options['class'];
57 if (isset(static::$classMap[strtolower($class)])) {
58 $class = static::$classMap[strtolower($class)];
60 if (!class_exists($class)) {
61 throw new Exception\DomainException(sprintf(
62 '%s expects the "class" attribute to resolve to an existing class; received "%s"',
63 __METHOD__,
64 $class
65 ));
68 unset($options['class']);
70 if (isset($options['options'])) {
71 $options = $options['options'];
73 $captcha = new $class($options);
75 if (!$captcha instanceof AdapterInterface) {
76 throw new Exception\DomainException(sprintf(
77 '%s expects the "class" attribute to resolve to a valid Zend\Captcha\AdapterInterface instance; received "%s"',
78 __METHOD__,
79 $class
80 ));
83 return $captcha;