retrieveRequirement() public static method

Get the requirement matching the name provided
public static retrieveRequirement ( $name, $options = null ) : mixed
$name String Name of requirement
return mixed
Esempio n. 1
0
 /**
  * Load the requirements as validators or filters for a given property,
  * and cache them as validators or filters, respectively.
  *
  * @param String $property Name of property
  * @return boolean whether or not cache was used. 
  */
 public function loadRequirements($property)
 {
     if (isset($this->_validators[$property]) || isset($this->_filters[$property])) {
         return true;
     }
     $validators = new Zend_Validate();
     $filters = new Zend_Filter();
     if (!isset($this->_docRequirements[$property])) {
         $this->_filters[$property] = $filters;
         $this->_validators[$property] = $validators;
         return false;
     }
     foreach ($this->_docRequirements[$property] as $requirement => $options) {
         $req = Shanty_Mongo::retrieveRequirement($requirement, $options);
         if ($req instanceof Zend_Validate_Interface) {
             $validators->addValidator($req);
         } else {
             if ($req instanceof Zend_Filter_Interface) {
                 $filters->addFilter($req);
             }
         }
     }
     $this->_filters[$property] = $filters;
     $this->_validators[$property] = $validators;
     return false;
 }
Esempio n. 2
0
 /**
  * Get all filters attached to a property
  * 
  * @param String $property
  * @return Zend_Filter
  */
 public function getFilters($property)
 {
     $filters = new Zend_Filter();
     // Return if no requirements are set for this property
     if (!array_key_exists($property, $this->_docRequirements)) {
         return $filters;
     }
     foreach ($this->_docRequirements[$property] as $requirement => $options) {
         // continue if requirement does not exist or is not a filter requirement
         $filter = Shanty_Mongo::retrieveRequirement($requirement, $options);
         if (!$filter || !$filter instanceof Zend_Filter_Interface) {
             continue;
         }
         $filters->addFilter($filter);
     }
     return $filters;
 }
Esempio n. 3
0
 /**
  * @depends testRetrieveRequirements
  */
 public function testStoreRequirement()
 {
     $requirement = new Zend_Validate_Hostname();
     Shanty_Mongo::storeRequirement('Validator:Hostname', $requirement);
     $requirement = Shanty_Mongo::retrieveRequirement('Validator:Hostname');
     $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT, $requirement);
     $this->assertEquals('Zend_Validate_Hostname', get_class($requirement));
     // test requirements with options after the same requirement has been stored without options
     $requirement = Shanty_Mongo::retrieveRequirement('Validator:Hostname', Zend_Validate_Hostname::ALLOW_IP);
     $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT, $requirement);
     $this->assertEquals('Zend_Validate_Hostname', get_class($requirement));
     $this->assertFalse($requirement->isValid('shantymongo.org'));
 }