Hoa central
Aggregate.php
Go to the documentation of this file.
1 <?php
2 
38 
47 class Aggregate implements Autocompleter
48 {
54  protected $_autocompleters = null;
55 
56 
57 
64  public function __construct(Array $autocompleters)
65  {
66  $this->setAutocompleters($autocompleters);
67 
68  return;
69  }
70 
78  public function complete(&$prefix)
79  {
80  foreach ($this->getAutocompleters() as $autocompleter) {
81  $preg = preg_match(
82  '#(' . $autocompleter->getWordDefinition() . ')$#u',
83  $prefix,
84  $match
85  );
86 
87  if (0 === $preg) {
88  continue;
89  }
90 
91  $_prefix = $match[0];
92 
93  if (null === $out = $autocompleter->complete($_prefix)) {
94  continue;
95  }
96 
97  $prefix = $_prefix;
98 
99  return $out;
100  }
101 
102  return null;
103  }
104 
111  protected function setAutocompleters(Array $autocompleters)
112  {
113  $old = $this->_autocompleters;
114  $this->_autocompleters = new \ArrayObject($autocompleters);
115 
116  return $old;
117  }
118 
124  public function getAutocompleters()
125  {
126  return $this->_autocompleters;
127  }
128 
134  public function getWordDefinition()
135  {
136  return '.*';
137  }
138 }