Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into rfc/escaper
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 22 changed files with 902 additions and 711 deletions.
76 changes: 22 additions & 54 deletions src/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,45 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Captcha;

use Traversable,
Zend\Config\Config;
use Traversable;
use Zend\Validator\AbstractValidator;

/**
* Base class for Captcha adapters
*
* Provides some utility functionality to build on
*
* @uses Zend\Captcha\Adapter
* @uses Zend\Validator\AbstractValidator
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class AbstractAdapter extends \Zend\Validator\AbstractValidator implements Adapter
abstract class AbstractAdapter extends AbstractValidator implements AdapterInterface
{
/**
* Element name
* Captcha name
*
* Useful to generate/check form fields
*
* @var string
*/
protected $_name;
protected $name;

/**
* Captcha options
*
* @var array
*/
protected $_options = array();
protected $options = array();

/**
* Options to skip when processing options
* @var array
*/
protected $_skipOptions = array(
protected $skipOptions = array(
'options',
'config',
);
Expand All @@ -74,7 +69,7 @@ abstract class AbstractAdapter extends \Zend\Validator\AbstractValidator impleme
*/
public function getName()
{
return $this->_name;
return $this->name;
}

/**
Expand All @@ -84,48 +79,32 @@ public function getName()
*/
public function setName($name)
{
$this->_name = $name;
$this->name = $name;
return $this;
}

/**
* Constructor
*
* @param array|Zend\Config\Config $options
* @return void
*/
public function __construct($options = null)
{
// Set options
if (is_array($options)) {
$this->setOptions($options);
} else if ($options instanceof Config) {
$this->setConfig($options);
}
}

/**
* Set single option for the object
*
* @param string $key
* @param string $value
* @return Zend_Form_Element
* @param string $key
* @param string $value
* @return AbstractAdapter
*/
public function setOption($key, $value)
{
if (in_array(strtolower($key), $this->_skipOptions)) {
if (in_array(strtolower($key), $this->skipOptions)) {
return $this;
}

$method = 'set' . ucfirst ($key);
if (method_exists ($this, $method)) {
// Setter exists; use it
$this->$method ($value);
$this->_options[$key] = $value;
$this->options[$key] = $value;
} elseif (property_exists($this, $key)) {
// Assume it's metadata
$this->$key = $value;
$this->_options[$key] = $value;
$this->options[$key] = $value;
}
return $this;
}
Expand All @@ -134,7 +113,7 @@ public function setOption($key, $value)
* Set object state from options array
*
* @param array|Traversable $options
* @return Zend_Form_Element
* @return AbstractAdapter
*/
public function setOptions($options = array())
{
Expand All @@ -155,29 +134,18 @@ public function setOptions($options = array())
*/
public function getOptions()
{
return $this->_options;
}

/**
* Set object state from config object
*
* @param Zend\Config\Config $config
* @return Zend\Captcha\AbstractAdapter
*/
public function setConfig(Config $config)
{
return $this->setOptions($config->toArray());
return $this->options;
}

/**
* Get optional decorator
* Get helper name used to render captcha
*
* By default, return null, indicating no extra decorator needed.
* By default, return empty string, indicating no helper needed.
*
* @return null
* @return string
*/
public function getDecorator()
public function getHelperName()
{
return null;
return '';
}
}
25 changes: 7 additions & 18 deletions src/Adapter.php → src/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,22 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Captcha;

use Zend\Validator\ValidatorInterface;

/**
* Generic Captcha adapter interface
*
* Each specific captcha implementation should implement this interface
*
* @uses Zend\Validator\Validator
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Adapter extends \Zend\Validator\Validator
interface AdapterInterface extends ValidatorInterface
{
/**
* Generate a new captcha
Expand All @@ -45,20 +43,11 @@ interface Adapter extends \Zend\Validator\Validator
*/
public function generate();

/**
* Display the captcha
*
* @param \Zend\View\Renderer $view
* @param mixed $element
* @return string
*/
public function render(\Zend\View\Renderer $view = null, $element = null);

/**
* Set captcha name
*
* @param string $name
* @return \Zend\Captcha\Adapter
* @return AdapterInterface
*/
public function setName($name);

Expand All @@ -70,9 +59,9 @@ public function setName($name);
public function getName();

/**
* Get optional private decorator for this captcha type
* Get helper name to use when rendering this captcha type
*
* @return \Zend\Form\Decorator|string
* @return string
*/
public function getDecorator();
public function getHelperName();
}
41 changes: 29 additions & 12 deletions src/Dumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Captcha;

/**
* Example dumb word-based captcha
*
* Note that only rendering is necessary for word-based captcha
*
* @uses Zend\Captcha\Word
* @todo This likely needs its own validation since it expects the word entered to be the strrev of the word stored.
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
Expand All @@ -39,16 +36,36 @@
class Dumb extends Word
{
/**
* Render the captcha
*
* @param \Zend\View\Renderer $view
* @param mixed $element
* CAPTCHA label
* @type string
*/
protected $label = 'Please type this word backwards';

/**
* Set the label for the CAPTCHA
* @param string $label
*/
public function setLabel($label)
{
$this->label = $label;
}

/**
* Retrieve the label for the CAPTCHA
* @return string
*/
public function getLabel()
{
return $this->label;
}

/**
* Retrieve optional view helper name to use when rendering this captcha
*
* @return string
*/
public function render(\Zend\View\Renderer $view = null, $element = null)
public function getHelperName()
{
return 'Please type this word backwards: <b>'
. strrev($this->getWord())
. '</b>';
return 'captcha/dumb';
}
}
33 changes: 33 additions & 0 deletions src/Exception/DomainException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Captcha
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Captcha\Exception;

/**
* @category Zend
* @package Zend_Captcha
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class DomainException extends \DomainException implements ExceptionInterface
{
}
10 changes: 4 additions & 6 deletions src/Exception.php → src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,22 @@
*
* @category Zend
* @package Zend_Captcha
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Captcha;
namespace Zend\Captcha\Exception;

/**
* Exception for Zend_Form component.
*
* @uses Zend\Exception
* @category Zend
* @package Zend_Captcha
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Exception
interface ExceptionInterface
{
}
14 changes: 4 additions & 10 deletions src/Exception/ExtensionNotLoadedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,22 @@
*
* @category Zend
* @package Zend_Captcha
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id$
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Captcha\Exception;
use Zend\Captcha\Exception;

/**
* Exception for Zend_Form component.
*
* @uses Zend\Exception
* @category Zend
* @package Zend_Captcha
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class ExtensionNotLoadedException
extends \RuntimeException
implements Exception
class ExtensionNotLoadedException extends RuntimeException
{
}
}
Loading

0 comments on commit 89056c3

Please sign in to comment.