Beispiel #1
0
 /**
  * Finder method to be able to find resources by context name
  * and attributes.  Example usage:
  *
  * <code>
  *
  * </code>
  *
  * @param Zend_Tool_Project_Profile_Resource_SearchConstraints|string|array $searchParameters
  * @return Zend_Tool_Project_Profile_Resource
  */
 public function search($matchSearchConstraints, $nonMatchSearchConstraints = null)
 {
     if (!$matchSearchConstraints instanceof Zend_Tool_Project_Profile_Resource_SearchConstraints) {
         $matchSearchConstraints = new Zend_Tool_Project_Profile_Resource_SearchConstraints($matchSearchConstraints);
     }
     $this->rewind();
     /**
      * @todo This should be re-written with better support for a filter iterator, its the way to go
      */
     if ($nonMatchSearchConstraints) {
         $filterIterator = new Zend_Tool_Project_Profile_Iterator_ContextFilter($this, array('denyNames' => $nonMatchSearchConstraints));
         $riIterator = new RecursiveIteratorIterator($filterIterator, RecursiveIteratorIterator::SELF_FIRST);
     } else {
         $riIterator = new RecursiveIteratorIterator($this, RecursiveIteratorIterator::SELF_FIRST);
     }
     $foundResource = false;
     $currentConstraint = $matchSearchConstraints->getConstraint();
     $foundDepth = 0;
     foreach ($riIterator as $currentResource) {
         // if current depth is less than found depth, end
         if ($riIterator->getDepth() < $foundDepth) {
             break;
         }
         if (strtolower($currentResource->getName()) == strtolower($currentConstraint->name)) {
             $paramsMatch = true;
             // @todo check to ensure params match (perhaps)
             if (count($currentConstraint->params) > 0) {
                 $currentResourceAttributes = $currentResource->getAttributes();
                 if (!is_array($currentConstraint->params)) {
                     require_once 'Zend/Tool/Project/Profile/Exception.php';
                     throw new Zend_Tool_Project_Profile_Exception('Search parameter specifics must be in the form of an array for key "' . $currentConstraint->name . '"');
                 }
                 foreach ($currentConstraint->params as $paramName => $paramValue) {
                     if (!isset($currentResourceAttributes[$paramName]) || $currentResourceAttributes[$paramName] != $paramValue) {
                         $paramsMatch = false;
                         break;
                     }
                 }
             }
             if ($paramsMatch) {
                 $foundDepth = $riIterator->getDepth();
                 if (($currentConstraint = $matchSearchConstraints->getConstraint()) == null) {
                     $foundResource = $currentResource;
                     break;
                 }
             }
         }
     }
     return $foundResource;
 }
Beispiel #2
0
 /**
  * Finder method to be able to find resources by context name
  * and attributes.  Example usage:
  * 
  * <code>
  * 
  * </code>
  *
  * @param Zend_Tool_Project_Profile_Resource_SearchConstraints|string|array $searchParameters
  * @return Zend_Tool_Project_Profile_Resource
  */
 public function search($searchConstraints)
 {
     if (!$searchConstraints instanceof Zend_Tool_Project_Profile_Resource_SearchConstraints) {
         $searchConstraints = new Zend_Tool_Project_Profile_Resource_SearchConstraints($searchConstraints);
     }
     $this->rewind();
     $riIterator = new RecursiveIteratorIterator($this, RecursiveIteratorIterator::SELF_FIRST);
     $foundResource = false;
     $currentConstraint = $searchConstraints->getConstraint();
     $foundDepth = 0;
     while ($currentResource = $riIterator->current()) {
         // if current depth is less than found depth, end
         if ($riIterator->getDepth() < $foundDepth) {
             break;
         }
         if (strtolower($currentResource->getName()) == strtolower($currentConstraint->name)) {
             $paramsMatch = true;
             // @todo check to ensure params match (perhaps)
             if (count($currentConstraint->params) > 0) {
                 $currentResourceAttributes = $currentResource->getAttributes();
                 foreach ($currentConstraint->params as $paramName => $paramValue) {
                     if (!isset($currentResourceAttributes[$paramName]) || $currentResourceAttributes[$paramName] != $paramValue) {
                         $paramsMatch = false;
                         break;
                     }
                 }
             }
             if ($paramsMatch) {
                 $foundDepth = $riIterator->getDepth();
                 if (($currentConstraint = $searchConstraints->getConstraint()) == null) {
                     $foundResource = $currentResource;
                     break;
                 }
             }
         }
         $riIterator->next();
     }
     return $foundResource;
 }