diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:15:42 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:44:51 +0100 |
commit | a1789ddde42033f1b05cc4929491214ee6e79383 (patch) | |
tree | 63615735c4ddffaaabf2428946bb26f90899f7bf /vendor/ruflin/elastica/lib/Elastica/Filter/AbstractMulti.php | |
parent | 9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff) |
Update to MediaWiki 1.26.0
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Filter/AbstractMulti.php')
-rw-r--r-- | vendor/ruflin/elastica/lib/Elastica/Filter/AbstractMulti.php | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Filter/AbstractMulti.php b/vendor/ruflin/elastica/lib/Elastica/Filter/AbstractMulti.php new file mode 100644 index 00000000..06f6daea --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Filter/AbstractMulti.php @@ -0,0 +1,89 @@ +<?php +namespace Elastica\Filter; + +/** + * Multi Abstract filter object. Should be extended by filter types composed of an array of sub filters. + * + * @author Nicolas Ruflin <spam@ruflin.com> + */ +abstract class AbstractMulti extends AbstractFilter +{ + /** + * Filters. + * + * @var array + */ + protected $_filters = array(); + + /** + * @param \Elastica\Filter\AbstractFilter $filters + */ + public function __construct(array $filters = array()) + { + if (!empty($filters)) { + $this->setFilters($filters); + } + } + + /** + * Add filter. + * + * @param \Elastica\Filter\AbstractFilter $filter + * + * @return $this + */ + public function addFilter(AbstractFilter $filter) + { + $this->_filters[] = $filter->toArray(); + + return $this; + } + + /** + * Set filters. + * + * @param array $filters + * + * @return $this + */ + public function setFilters(array $filters) + { + $this->_filters = array(); + + foreach ($filters as $filter) { + $this->addFilter($filter); + } + + return $this; + } + + /** + * @return array Filters + */ + public function getFilters() + { + return $this->_filters; + } + + /** + * @see \Elastica\Param::toArray() + * + * @return array + */ + public function toArray() + { + $data = parent::toArray(); + $name = $this->_getBaseName(); + $filterData = $data[$name]; + + if (empty($filterData)) { + $filterData = $this->_filters; + } else { + $filterData['filters'] = $this->_filters; + } + + $data[$name] = $filterData; + + return $data; + } +} |