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

Commit

Permalink
Merge remote-tracking branch 'weierophinney/feature/forms'
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 21 changed files with 730 additions and 633 deletions.
1 change: 1 addition & 0 deletions .travis/skipped-components
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Zend/Amf
Zend/Date
Zend/Dojo
Zend/Queue
Zend/Service
Zend/Test
Expand Down
55 changes: 19 additions & 36 deletions src/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
namespace Zend\Captcha;

use Traversable;
use Zend\Stdlib\ArrayUtils;
use Zend\Validator\AbstractValidator;

/**
Expand All @@ -39,26 +38,26 @@
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 @@ -70,7 +69,7 @@ abstract class AbstractAdapter extends AbstractValidator implements AdapterInter
*/
public function getName()
{
return $this->_name;
return $this->name;
}

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

/**
* Constructor
*
* @param array|Traversable $options
*/
public function __construct($options = null)
{
// Set options
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
if (is_array($options)) {
$this->setOptions($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 @@ -130,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 @@ -151,18 +134,18 @@ public function setOptions($options = array())
*/
public function getOptions()
{
return $this->_options;
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 '';
}
}
16 changes: 3 additions & 13 deletions src/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
namespace Zend\Captcha;

use Zend\Validator\ValidatorInterface;
use Zend\View\Renderer\RendererInterface as Renderer;

/**
* Generic Captcha adapter interface
Expand All @@ -44,15 +43,6 @@ interface AdapterInterface extends ValidatorInterface
*/
public function generate();

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

/**
* Set captcha name
*
Expand All @@ -69,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();
}
21 changes: 8 additions & 13 deletions src/Dumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@

namespace Zend\Captcha;

use Zend\View\Renderer\RendererInterface as Renderer;

/**
* Example dumb word-based captcha
*
* Note that only rendering is necessary for word-based captcha
*
* @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 @@ -40,15 +39,15 @@ class Dumb extends Word
* CAPTCHA label
* @type string
*/
protected $_label = 'Please type this word backwards';
protected $label = 'Please type this word backwards';

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

/**
Expand All @@ -57,20 +56,16 @@ public function setLabel($label)
*/
public function getLabel()
{
return $this->_label;
return $this->label;
}

/**
* Render the captcha
*
* @param Renderer $view
* @param mixed $element
* Retrieve optional view helper name to use when rendering this captcha
*
* @return string
*/
public function render(Renderer $view = null, $element = null)
public function getHelperName()
{
return $this->getLabel() . ': <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
{
}
2 changes: 2 additions & 0 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
* @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
*/
Expand All @@ -25,6 +26,7 @@
*
* @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
*/
Expand Down
9 changes: 5 additions & 4 deletions src/Exception/ExtensionNotLoadedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@
*
* @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 Zend\Captcha\Exception;

use RuntimeException;

/**
* Exception for Zend_Form component.
*
* @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 ExceptionInterface
class ExtensionNotLoadedException extends RuntimeException implements ExceptionInterface
{
}
9 changes: 5 additions & 4 deletions src/Exception/ImageNotLoadableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@
*
* @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 Zend\Captcha\Exception;

use RuntimeException;

/**
* Exception for Zend_Form component.
*
* @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 ImageNotLoadableException
extends \RuntimeException
implements ExceptionInterface
class ImageNotLoadableException extends RuntimeException implements ExceptionInterface
{
}
7 changes: 3 additions & 4 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@
*
* @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 InvalidArgumentException
extends \InvalidArgumentException
implements ExceptionInterface
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}
7 changes: 3 additions & 4 deletions src/Exception/NoFontProvidedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*
* @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
*/

Expand All @@ -26,11 +26,10 @@
*
* @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 NoFontProvidedException
extends \InvalidArgumentException
implements ExceptionInterface
class NoFontProvidedException extends InvalidArgumentException
{
}
Loading

0 comments on commit 6aae974

Please sign in to comment.