SearchConstraints.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * This class is an iterator that will iterate only over enabled resources
  24. *
  25. * @category Zend
  26. * @package Zend_Tool
  27. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. */
  30. class Zend_Tool_Project_Profile_Resource_SearchConstraints
  31. {
  32. /**
  33. * @var array
  34. */
  35. protected $_constraints = array();
  36. /**
  37. * __construct()
  38. *
  39. * @param array|string $options
  40. */
  41. public function __construct($options = null)
  42. {
  43. if (is_string($options)) {
  44. $this->addConstraint($options);
  45. } elseif (is_array($options)) {
  46. $this->setOptions($options);
  47. }
  48. }
  49. /**
  50. * setOptions()
  51. *
  52. * @param array $option
  53. * @return Zend_Tool_Project_Profile_Resource_SearchConstraints
  54. */
  55. public function setOptions(Array $option)
  56. {
  57. foreach ($option as $optionName => $optionValue) {
  58. if (is_int($optionName)) {
  59. $this->addConstraint($optionValue);
  60. } elseif (is_string($optionName)) {
  61. $this->addConstraint(array('name' => $optionName, 'params' => $optionValue));
  62. }
  63. }
  64. return $this;
  65. }
  66. /**
  67. * addConstraint()
  68. *
  69. * @param string|array $constraint
  70. * @return Zend_Tool_Project_Profile_Resource_SearchConstraints
  71. */
  72. public function addConstraint($constraint)
  73. {
  74. if (is_string($constraint)) {
  75. $name = $constraint;
  76. $params = array();
  77. } elseif (is_array($constraint)) {
  78. $name = $constraint['name'];
  79. $params = $constraint['params'];
  80. }
  81. $constraint = $this->_makeConstraint($name, $params);
  82. array_push($this->_constraints, $constraint);
  83. return $this;
  84. }
  85. /**
  86. * getConstraint()
  87. *
  88. * @return ArrayObject
  89. */
  90. public function getConstraint()
  91. {
  92. return array_shift($this->_constraints);
  93. }
  94. /**
  95. * _makeConstraint
  96. *
  97. * @param string $name
  98. * @param mixed $params
  99. * @return ArrayObject
  100. */
  101. protected function _makeConstraint($name, $params)
  102. {
  103. $value = array('name' => $name, 'params' => $params);
  104. return new ArrayObject($value, ArrayObject::ARRAY_AS_PROPS);
  105. }
  106. }