Hoa central
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Hoa\Xml\Element\Concrete Class Reference
Inheritance diagram for Hoa\Xml\Element\Concrete:

Public Member Functions

 __construct (Element $abstract, Element $superRoot, Array $rank=[], $namespace=null)
 
 construct ()
 
 getAbstractElement ()
 
 getAbstractElementSuperRoot ()
 
 getName ()
 
 count ()
 
 getIterator ()
 
 __set ($name, Concrete $value)
 
 __get ($name)
 
 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $element)
 
 offsetUnset ($offset)
 
 __call ($name, Array $arguments=[])
 

Static Public Member Functions

static getAbstractElementId (Element $element)
 
static getConcreteElement (Element $element)
 
static getAbstractElementSuperRootOf (Element $element)
 

Protected Attributes

 $_name = null
 
 $_children = []
 
 $_iterator = []
 
 $abstract = null
 
 $_superRoot = null
 

Static Protected Attributes

static $_store = []
 
static $_superRoots = []
 
static $_multiton = []
 

Detailed Description

Class .

This class represents a XML element in a XML tree.

Definition at line 49 of file Concrete.php.

Constructor & Destructor Documentation

Hoa\Xml\Element\Concrete::__construct ( Element  $abstract,
Element  $superRoot,
Array  $rank = [],
  $namespace = null 
)
final

Build a concrete tree.

Parameters
\Hoa\Xml\Element$abstractAbstract element.
\Hoa\Xml\Element$superRootSuper root.
array$rankRank: abstract elements to concrete elements.
string$namespaceNamespace.
Returns
void

Definition at line 119 of file Concrete.php.

124  {
125  self::$_store[] = $abstract;
126  self::$_superRoots[] = $superRoot;
127  self::$_multiton[] = $this;
128 
129  if (null !== $namespace) {
130  $abstract->useNamespace($namespace);
131  }
132 
133  if (null === $this->_name) {
134  $this->_name = strtolower(get_class($this));
135 
136  if (false !== $po = strrpos($this->_name, '\\')) {
137  $this->_name = substr($this->_name, $po + 1);
138  }
139  }
140 
141  $this->abstract = $abstract;
142  $this->_superRoot = $superRoot;
143 
144  if ($this instanceof Model\Phrasing) {
145  $iterator = $abstract->readAsPhrasingModel($namespace);
146  } else {
147  $iterator = $abstract->selectChildElements();
148  }
149 
150  foreach ($iterator as $child) {
151  $name = $child->getName();
152 
153  if (!isset($rank[$name])) {
154  throw new Xml\Exception(
155  'Cannot build the concrete tree because the abstract ' .
156  'element <%s> has no ranked concrete element.',
157  0,
158  $name
159  );
160  }
161 
162  $c = $rank[$name];
163  $h = new $c($child, $superRoot, $rank, $namespace);
164 
165  $this->_children[$h->getName()][] = $h;
166  $this->_iterator[] = $h;
167  }
168 
169  $this->construct();
170 
171  return;
172  }

Here is the call graph for this function:

Member Function Documentation

Hoa\Xml\Element\Concrete::__call (   $name,
Array  $arguments = [] 
)

Redirect unknown call on the abstract element.

Parameters
string$nameName.
array$argumentsArguments.
Returns
mixed

Definition at line 396 of file Concrete.php.

397  {
398  return call_user_func_array(
399  [$this->abstract, $name],
400  $arguments
401  );
402  }
Hoa\Xml\Element\Concrete::__get (   $name)

Get a child.

Parameters
string$nameChild value.
Returns
mixed

Definition at line 307 of file Concrete.php.

308  {
309  if (!isset($this->_children[$name])) {
310  return null;
311  }
312 
313  return $this->_children[$name];
314  }
Hoa\Xml\Element\Concrete::__set (   $name,
Concrete  $value 
)

Set a child.

Parameters
string$nameChild name.
\Hoa\Xml\Element\Concrete$valueValue.
Returns
void

Definition at line 293 of file Concrete.php.

294  {
295  $this->_children[$name][] = $value;
296  $this->_iterator[] = $value;
297 
298  return;
299  }
Hoa\Xml\Element\Concrete::construct ( )

Simplify overloading of the constructor.

Returns
void

Definition at line 179 of file Concrete.php.

180  {
181  return;
182  }

Here is the caller graph for this function:

Hoa\Xml\Element\Concrete::count ( )

Count children number.

Returns
int

Definition at line 271 of file Concrete.php.

272  {
273  return count($this->_iterator);
274  }

Here is the caller graph for this function:

Hoa\Xml\Element\Concrete::getAbstractElement ( )

Get the abstract element.

Returns

Definition at line 200 of file Concrete.php.

201  {
202  return $this->abstract;
203  }
static Hoa\Xml\Element\Concrete::getAbstractElementId ( Element  $element)
static

Get the abstract element ID.

Parameters
\Hoa\Xml\Element$elementAbstract element.
Returns
mixed

Definition at line 190 of file Concrete.php.

191  {
192  return array_search($element, self::$_store);
193  }
Hoa\Xml\Element\Concrete::getAbstractElementSuperRoot ( )

Get the super-root of the abstract element.

Returns

Definition at line 230 of file Concrete.php.

231  {
232  return $this->_superRoot;
233  }

Here is the caller graph for this function:

static Hoa\Xml\Element\Concrete::getAbstractElementSuperRootOf ( Element  $element)
static

Get the super-root of an abstract element.

Parameters
\Hoa\Xml\Element$elementAbstract element.
Returns
Exceptions

Definition at line 242 of file Concrete.php.

243  {
244  if (false === $id = self::getAbstractElementId($element)) {
245  throw new Xml\Exception(
246  'The concrete element %s has no concrete equivalent and we ' .
247  'cannot retrieve the super-root.',
248  2,
249  $element->getName()
250  );
251  }
252 
253  return self::$_superRoots[$id];
254  }
static Hoa\Xml\Element\Concrete::getConcreteElement ( Element  $element)
static

Get the associated concrete element of an abstract element.

Parameters
\Hoa\Xml\Element$elementAbstract element.
Returns
Exceptions

Definition at line 212 of file Concrete.php.

213  {
214  if (false === $id = self::getAbstractElementId($element)) {
215  throw new Xml\Exception(
216  'The basic element %s has no concrete equivalent.',
217  1,
218  $element->getName()
219  );
220  }
221 
222  return self::$_multiton[$id];
223  }

Here is the caller graph for this function:

Hoa\Xml\Element\Concrete::getIterator ( )

Get the iterator.

Returns

Definition at line 281 of file Concrete.php.

282  {
283  return new \ArrayIterator($this->_iterator);
284  }
Hoa\Xml\Element\Concrete::getName ( )

Get the name of the concrete element.

Returns
string

Definition at line 261 of file Concrete.php.

262  {
263  return $this->_name;
264  }
Hoa\Xml\Element\Concrete::offsetExists (   $offset)

Check if an element exists.

Parameters
int$offsetElement index.
Returns
bool

Definition at line 322 of file Concrete.php.

323  {
324  return isset($this->_iterator[$offset]);
325  }

Here is the caller graph for this function:

Hoa\Xml\Element\Concrete::offsetGet (   $offset)

Get an element.

Parameters
int$offsetElement index.
Returns

Definition at line 333 of file Concrete.php.

334  {
335  if (false === $this->offsetExists($offset)) {
336  return null;
337  }
338 
339  return $this->_iterator[$offset];
340  }

Here is the call graph for this function:

Hoa\Xml\Element\Concrete::offsetSet (   $offset,
  $element 
)

Set an element to an index.

Parameters
string$offsetElement index.
\Hoa\Xyl\Element\Concrete$valueElement.
Returns
void

Definition at line 349 of file Concrete.php.

350  {
351  if (is_string($element)) {
352  $name = $element;
353  } else {
354  $name = $element->getName();
355  }
356 
357  if (!isset($this->_children[$name])) {
358  $this->_children[$name] = [];
359  }
360 
361  $this->_children[$name][$offset] = $element;
362  $this->_iterator[$offset] = $element;
363 
364  return;
365  }
Hoa\Xml\Element\Concrete::offsetUnset (   $offset)

Remove an element.

Parameters
string$offsetElement index.
Returns
void

Definition at line 373 of file Concrete.php.

374  {
375  if (!isset($this->_iterator[$offset])) {
376  return;
377  }
378 
379  $element = $this->_iterator[$offset];
380  $name = $element->getName();
381  $i = array_search($element, $this->_children[$name]);
382 
383  unset($this->_children[$name][$i]);
384  unset($this->_iterator[$offset]);
385 
386  return;
387  }

Member Data Documentation

Hoa\Xml\Element\Concrete::$_children = []
protected

Definition at line 84 of file Concrete.php.

Hoa\Xml\Element\Concrete::$_iterator = []
protected

Definition at line 91 of file Concrete.php.

Hoa\Xml\Element\Concrete::$_multiton = []
staticprotected

Definition at line 70 of file Concrete.php.

Hoa\Xml\Element\Concrete::$_name = null
protected

Definition at line 77 of file Concrete.php.

Hoa\Xml\Element\Concrete::$_store = []
staticprotected

Definition at line 56 of file Concrete.php.

Hoa\Xml\Element\Concrete::$_superRoot = null
protected

Definition at line 105 of file Concrete.php.

Hoa\Xml\Element\Concrete::$_superRoots = []
staticprotected

Definition at line 63 of file Concrete.php.

Hoa\Xml\Element\Concrete::$abstract = null
protected

Definition at line 98 of file Concrete.php.


The documentation for this class was generated from the following file: