示例#1
0
 /**
  * Set captcha
  *
  * @param  array|ZendCaptcha\AdapterInterface $captcha
  * @return Captcha
  */
 public function setCaptcha($captcha)
 {
     if (is_array($captcha) || $captcha instanceof Traversable) {
         $captcha = ZendCaptcha\Factory::factory($captcha);
     } elseif (!$captcha instanceof ZendCaptcha\AdapterInterface) {
         throw new Exception\InvalidArgumentException(sprintf('%s expects either a Zend\\Captcha\\AdapterInterface or specification to pass to Zend\\Captcha\\Factory; received "%s"', __METHOD__, is_object($captcha) ? get_class($captcha) : gettype($captcha)));
     }
     $this->captcha = $captcha;
     return $this;
 }
 public function createService(ServiceLocatorInterface $services)
 {
     $config = $services->get('config');
     if ($config instanceof Traversable) {
         $config = ArrayUtils::iteratorToArray($config);
     }
     $spec = $config['phly_contact']['captcha'];
     $captcha = CaptchaFactory::factory($spec);
     return $captcha;
 }
示例#3
0
 public function testOptionsArePassedToCaptchaAdapter()
 {
     $captcha = Captcha\Factory::factory(array('class' => 'ZendTest\\Captcha\\TestAsset\\MockCaptcha', 'options' => array('foo' => 'bar')));
     $this->assertEquals(array('foo' => 'bar'), $captcha->options);
 }
示例#4
0
 /**
  * {@inheritDoc}
  *
  * @return AdapterInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     return Factory::factory($this->getOptions($serviceLocator));
 }