Standardize path validators according to Zend's validators

refs #8415
This commit is contained in:
Johannes Meyer 2015-02-12 09:05:40 +01:00
parent a2f3e7d4f7
commit aa473fb8cf
2 changed files with 18 additions and 18 deletions

View File

@ -13,6 +13,9 @@ use Zend_Validate_Abstract;
*/ */
class ReadablePathValidator extends Zend_Validate_Abstract class ReadablePathValidator extends Zend_Validate_Abstract
{ {
const NOT_READABLE = 'notReadable';
const DOES_NOT_EXIST = 'doesNotExist';
/** /**
* The messages to write on different error states * The messages to write on different error states
* *
@ -20,18 +23,10 @@ class ReadablePathValidator extends Zend_Validate_Abstract
* *
* @see Zend_Validate_Abstract::$_messageTemplates * @see Zend_Validate_Abstract::$_messageTemplates
*/ */
protected $_messageTemplates; protected $_messageTemplates = array(
self::NOT_READABLE => 'Path is not readable',
/** self::DOES_NOT_EXIST => 'Path does not exist'
* Initialize this validator
*/
public function __construct()
{
$this->_messageTemplates = array(
'NOT_READABLE' => t('Path is not readable'),
'DOES_NOT_EXIST' => t('Path does not exist')
); );
}
/** /**
* Check whether the given value is a readable filepath * Check whether the given value is a readable filepath
@ -44,12 +39,13 @@ class ReadablePathValidator extends Zend_Validate_Abstract
public function isValid($value, $context = null) public function isValid($value, $context = null)
{ {
if (false === file_exists($value)) { if (false === file_exists($value)) {
$this->_error('DOES_NOT_EXIST'); $this->_error(self::DOES_NOT_EXIST);
return false; return false;
} }
if (false === is_readable($value)) { if (false === is_readable($value)) {
$this->_error('NOT_READABLE'); $this->_error(self::NOT_READABLE);
return false;
} }
return true; return true;

View File

@ -10,6 +10,9 @@ use Zend_Validate_Abstract;
*/ */
class WritablePathValidator extends Zend_Validate_Abstract class WritablePathValidator extends Zend_Validate_Abstract
{ {
const NOT_WRITABLE = 'notWritable';
const DOES_NOT_EXIST = 'doesNotExist';
/** /**
* The messages to write on differen error states * The messages to write on differen error states
* *
@ -18,8 +21,8 @@ class WritablePathValidator extends Zend_Validate_Abstract
* @see Zend_Validate_Abstract::$_messageTemplates * @see Zend_Validate_Abstract::$_messageTemplates
*/ */
protected $_messageTemplates = array( protected $_messageTemplates = array(
'NOT_WRITABLE' => 'Path is not writable', self::NOT_WRITABLE => 'Path is not writable',
'DOES_NOT_EXIST' => 'Path does not exist' self::DOES_NOT_EXIST => 'Path does not exist'
); );
/** /**
@ -53,7 +56,7 @@ class WritablePathValidator extends Zend_Validate_Abstract
$this->_setValue($value); $this->_setValue($value);
if ($this->requireExistence && !file_exists($value)) { if ($this->requireExistence && !file_exists($value)) {
$this->_error('DOES_NOT_EXIST'); $this->_error(self::DOES_NOT_EXIST);
return false; return false;
} }
@ -62,7 +65,8 @@ class WritablePathValidator extends Zend_Validate_Abstract
) { ) {
return true; return true;
} }
$this->_error('NOT_WRITABLE');
$this->_error(self::NOT_WRITABLE);
return false; return false;
} }
} }