web/Zend/Tool/Project/Profile/Resource/SearchConstraints.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Tool
       
    17  * @subpackage Framework
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: SearchConstraints.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /**
       
    24  * This class is an iterator that will iterate only over enabled resources
       
    25  *
       
    26  * @category   Zend
       
    27  * @package    Zend_Tool
       
    28  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    29  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    30  */
       
    31 class Zend_Tool_Project_Profile_Resource_SearchConstraints
       
    32 {
       
    33 
       
    34     /**
       
    35      * @var array
       
    36      */
       
    37     protected $_constraints = array();
       
    38 
       
    39     /**
       
    40      * __construct()
       
    41      *
       
    42      * @param array|string $options
       
    43      */
       
    44     public function __construct($options = null)
       
    45     {
       
    46         if (is_string($options)) {
       
    47             $this->addConstraint($options);
       
    48         } elseif (is_array($options)) {
       
    49             $this->setOptions($options);
       
    50         }
       
    51     }
       
    52 
       
    53     /**
       
    54      * setOptions()
       
    55      *
       
    56      * @param array $option
       
    57      * @return Zend_Tool_Project_Profile_Resource_SearchConstraints
       
    58      */
       
    59     public function setOptions(Array $option)
       
    60     {
       
    61         foreach ($option as $optionName => $optionValue) {
       
    62             if (is_int($optionName)) {
       
    63                 $this->addConstraint($optionValue);
       
    64             } elseif (is_string($optionName)) {
       
    65                 $this->addConstraint(array('name' => $optionName, 'params' => $optionValue));
       
    66             }
       
    67         }
       
    68 
       
    69         return $this;
       
    70     }
       
    71 
       
    72     /**
       
    73      * addConstraint()
       
    74      *
       
    75      * @param string|array $constraint
       
    76      * @return Zend_Tool_Project_Profile_Resource_SearchConstraints
       
    77      */
       
    78     public function addConstraint($constraint)
       
    79     {
       
    80         if (is_string($constraint)) {
       
    81             $name   = $constraint;
       
    82             $params = array();
       
    83         } elseif (is_array($constraint)) {
       
    84             $name   = $constraint['name'];
       
    85             $params = $constraint['params'];
       
    86         }
       
    87 
       
    88         $constraint = $this->_makeConstraint($name, $params);
       
    89 
       
    90         array_push($this->_constraints, $constraint);
       
    91         return $this;
       
    92     }
       
    93 
       
    94     /**
       
    95      * getConstraint()
       
    96      *
       
    97      * @return ArrayObject
       
    98      */
       
    99     public function getConstraint()
       
   100     {
       
   101         return array_shift($this->_constraints);
       
   102     }
       
   103 
       
   104     /**
       
   105      * _makeConstraint
       
   106      *
       
   107      * @param string $name
       
   108      * @param mixed $params
       
   109      * @return ArrayObject
       
   110      */
       
   111     protected function _makeConstraint($name, $params)
       
   112     {
       
   113         $value = array('name' => $name, 'params' => $params);
       
   114         return new ArrayObject($value, ArrayObject::ARRAY_AS_PROPS);
       
   115     }
       
   116 
       
   117 }