File indexing completed on 2024-12-29 05:28:09

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Tool
0017  * @subpackage Framework
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * This class is an iterator that will iterate only over enabled resources
0025  *
0026  * @category   Zend
0027  * @package    Zend_Tool
0028  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0029  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0030  */
0031 class Zend_Tool_Project_Profile_Resource_SearchConstraints
0032 {
0033 
0034     /**
0035      * @var array
0036      */
0037     protected $_constraints = array();
0038 
0039     /**
0040      * __construct()
0041      *
0042      * @param array|string $options
0043      */
0044     public function __construct($options = null)
0045     {
0046         if (is_string($options)) {
0047             $this->addConstraint($options);
0048         } elseif (is_array($options)) {
0049             $this->setOptions($options);
0050         }
0051     }
0052 
0053     /**
0054      * setOptions()
0055      *
0056      * @param array $option
0057      * @return Zend_Tool_Project_Profile_Resource_SearchConstraints
0058      */
0059     public function setOptions(Array $option)
0060     {
0061         foreach ($option as $optionName => $optionValue) {
0062             if (is_int($optionName)) {
0063                 $this->addConstraint($optionValue);
0064             } elseif (is_string($optionName)) {
0065                 $this->addConstraint(array('name' => $optionName, 'params' => $optionValue));
0066             }
0067         }
0068 
0069         return $this;
0070     }
0071 
0072     /**
0073      * addConstraint()
0074      *
0075      * @param string|array $constraint
0076      * @return Zend_Tool_Project_Profile_Resource_SearchConstraints
0077      */
0078     public function addConstraint($constraint)
0079     {
0080         if (is_string($constraint)) {
0081             $name   = $constraint;
0082             $params = array();
0083         } elseif (is_array($constraint)) {
0084             $name   = $constraint['name'];
0085             $params = $constraint['params'];
0086         }
0087 
0088         $constraint = $this->_makeConstraint($name, $params);
0089 
0090         array_push($this->_constraints, $constraint);
0091         return $this;
0092     }
0093 
0094     /**
0095      * getConstraint()
0096      *
0097      * @return ArrayObject
0098      */
0099     public function getConstraint()
0100     {
0101         return array_shift($this->_constraints);
0102     }
0103 
0104     /**
0105      * _makeConstraint
0106      *
0107      * @param string $name
0108      * @param mixed $params
0109      * @return ArrayObject
0110      */
0111     protected function _makeConstraint($name, $params)
0112     {
0113         $value = array('name' => $name, 'params' => $params);
0114         return new ArrayObject($value, ArrayObject::ARRAY_AS_PROPS);
0115     }
0116 
0117 }