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

Public Member Functions

 computeDataBinding (Array &$data, Array &$parent=null)
 
 render (Stream\IStream\Out $out)
 
 computeValue (Stream\IStream\Out $out=null)
 
 computeTransientValue (Stream\IStream\Out $out=null)
 
 computeAttributeValue ($value, $type=self::ATTRIBUTE_TYPE_UNKNOWN, $name=null)
 
 isLastIteration ()
 
 setVisibility ($visibility)
 
 getVisibility ()
 
- Public Member Functions inherited from Hoa\Xml\Element\Concrete
 __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=[])
 

Public Attributes

const ATTRIBUTE_TYPE_UNKNOWN = 0
 
const ATTRIBUTE_TYPE_NORMAL = 1
 
const ATTRIBUTE_TYPE_ID = 2
 
const ATTRIBUTE_TYPE_CUSTOM = 4
 
const ATTRIBUTE_TYPE_LIST = 8
 
const ATTRIBUTE_TYPE_LINK = 16
 

Protected Member Functions

 selectData ($expression, Array &$bucket)
 
 getCurrentData ()
 
 paint (Stream\IStream\Out $out)
 
 cleanTransientValue ()
 
 formatValue ($value, $name=null)
 
 _formatValue ($value)
 
 computeFromString ($xyl)
 
 getDeclaredAttributes ()
 

Static Protected Member Functions

static _getDeclaredAttributes ()
 

Protected Attributes

 $_visibility = true
 
 $_transientValue = null
 
 $_lastIteration = false
 
- Protected Attributes inherited from Hoa\Xml\Element\Concrete
 $_name = null
 
 $_children = []
 
 $_iterator = []
 
 $abstract = null
 
 $_superRoot = null
 

Static Protected Attributes

static $_attributes
 
- Static Protected Attributes inherited from Hoa\Xml\Element\Concrete
static $_store = []
 
static $_superRoots = []
 
static $_multiton = []
 

Private Member Functions

 firstUpdate ()
 
 update ()
 

Private Attributes

 $_bucket = ['data' => null]
 
 $_attributeBucket = null
 

Additional Inherited Members

- Static Public Member Functions inherited from Hoa\Xml\Element\Concrete
static getAbstractElementId (Element $element)
 
static getConcreteElement (Element $element)
 
static getAbstractElementSuperRootOf (Element $element)
 

Detailed Description

Class .

This class represents the top-XYL-element. It manages data binding, value computing etc.

Definition at line 53 of file Concrete.php.

Member Function Documentation

Hoa\Xyl\Element\Concrete::_formatValue (   $value)
protected

Format value to a specific type.

Parameters
string$valueValue.
Returns
mixed

Definition at line 607 of file Concrete.php.

608  {
609  if (ctype_digit($value)) {
610  $value = intval($value);
611  } elseif (is_numeric($value)) {
612  $value = floatval($value);
613  } elseif ('true' === $value) {
614  $value = true;
615  } elseif ('false' === $value) {
616  $value = false;
617  } elseif ('null' === $value) {
618  $value = null;
619  }
620  // what about constants?
621 
622  return $value;
623  }

Here is the caller graph for this function:

static Hoa\Xyl\Element\Concrete::_getDeclaredAttributes ( )
staticprotected

Get all declared attributes in a trivial way.

Returns
array

Definition at line 687 of file Concrete.php.

688  {
689  $out = [];
690  $parent = get_called_class();
691 
692  do {
693  if (!isset($parent::$_attributes)) {
694  continue;
695  }
696 
697  $out = array_merge($out, $parent::$_attributes);
698  } while (false !== ($parent = get_parent_class($parent)));
699 
700  return $out;
701  }
Hoa\Xyl\Element\Concrete::cleanTransientValue ( )
protected

Clean transient value.

Returns
void

Definition at line 473 of file Concrete.php.

474  {
475  $this->_transientValue = null;
476 
477  return;
478  }
Hoa\Xyl\Element\Concrete::computeAttributeValue (   $value,
  $type = self::ATTRIBUTE_TYPE_UNKNOWN,
  $name = null 
)

Compute attribute value.

Parameters
string$valueAttribute value.
int$typeAttribute type.
string$nameAttribute name.
Returns
string

Definition at line 488 of file Concrete.php.

492  {
493  /*
494  // (!variable).
495  $value = preg_replace_callback(
496  '#\(\!([^\)]+)\)#',
497  function ( Array $matches ) use ( &$variables ) {
498 
499  if(!isset($variables[$matches[1]]))
500  return '';
501 
502  return $variables[$matches[1]];
503  },
504  $value
505  );
506  */
507 
508  // (?inner-bind).
509  if (null !== $this->_attributeBucket ||
510  !empty($this->_bucket['data'])) {
511  if (null === $this->_attributeBucket) {
512  $handle = &$this->_bucket;
513  $data = $handle['data'][$handle['current']];
514  } else {
515  $handle = &$this->_attributeBucket;
516  $data = $handle['data'][$handle['current']][$handle['branche']];
517  }
518 
519  if (is_array($data) && isset($data[0])) {
520  $data = $data[0];
521  }
522 
523  $value = preg_replace_callback(
524  '#\(\?(?:p(?:ath)?:)?([^\)]+)\)#',
525  function (Array $matches) use (&$data) {
526  if (!is_array($data) || !isset($data[$matches[1]])) {
527  return '';
528  }
529 
530  return $data[$matches[1]];
531  },
532  $value
533  );
534  }
535 
536  // Link.
537  if (self::ATTRIBUTE_TYPE_LINK === $type ||
538  self::ATTRIBUTE_TYPE_UNKNOWN === $type) {
539  $value = $this->getAbstractElementSuperRoot()->computeLink($value);
540  }
541 
542  // Formatter.
543  if (null !== $name &&
544  true === $this->abstract->attributeExists($name . '-formatter')) {
545  $value = $this->formatValue($value, $name . '-');
546  }
547 
548  return $value;
549  }
formatValue($value, $name=null)
Definition: Concrete.php:563

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Xyl\Element\Concrete::computeDataBinding ( Array &  $data,
Array &  $parent = null 
)

Distribute data into the XYL tree. Data are linked to element through a reference to the data bucket in the super root.

Parameters
array&$dataData.
array&$parentParent.
Returns
void

Definition at line 162 of file Concrete.php.

163  {
164  $executable = $this instanceof Executable;
165  $bindable = $this->abstract->attributeExists('bind');
166 
167  if (false === $bindable) {
168  foreach (static::getDeclaredAttributes() as $attribute => $type) {
169  $bindable |=
170  0 !== preg_match(
171  '#\(\?[^\)]+\)#',
172  $this->abstract->readAttribute($attribute)
173  );
174  }
175 
176  $bindable = (bool) $bindable;
177  }
178 
179  // Propagate binding.
180  if (false === $bindable) {
181  $executable and $this->preExecute();
182 
183  foreach ($this as $element) {
184  $element->computeDataBinding($data, $parent);
185  }
186 
187  $executable and $this->postExecute();
188 
189  return;
190  }
191 
192  // Inner-binding.
193  if (false === $this->abstract->attributeExists('bind')) {
194  if (null === $parent) {
195  $parent = [
196  'parent' => null,
197  'current' => 0,
198  'branche' => '_',
199  'data' => [[
200  '_' => $data
201  ]]
202  ];
203  }
204 
205  $this->_attributeBucket = &$parent;
206  $executable and $this->preExecute();
207 
208  foreach ($this as $element) {
209  $element->computeDataBinding($data, $parent);
210  }
211 
212  $executable and $this->postExecute();
213 
214  return;
215  }
216 
217  // Binding.
218  $this->_bucket['parent'] = &$parent;
219  $this->_bucket['current'] = 0;
220  $this->_bucket['branche'] = $bind = $this->selectData(
221  $this->abstract->readAttribute('bind'),
222  $data
223  );
224 
225  if (null === $parent) {
226  $this->_bucket['data'] = $data;
227  }
228 
229  $bindable and $this->_attributeBucket = &$parent;
230  $executable and $this->preExecute();
231 
232  if (isset($data[0][$bind])) {
233  if (is_string($data[0][$bind])) {
234  return;
235  }
236 
237  foreach ($this as $element) {
238  $element->computeDataBinding($data[0][$bind], $this->_bucket);
239  }
240  }
241 
242  $executable and $this->postExecute();
243 
244  return;
245  }
selectData($expression, Array &$bucket)
Definition: Concrete.php:257

Here is the call graph for this function:

Hoa\Xyl\Element\Concrete::computeFromString (   $xyl)
protected

Compute from strings, directly on the output stream.

Returns
void

Definition at line 630 of file Concrete.php.

631  {
632  if (0 < count($this)) {
633  return null;
634  }
635 
636  $stringBuffer = new Stringbuffer\ReadWrite();
637  $stringBuffer->initializeWith(
638  '<?xml version="1.0" encoding="utf-8"?>' .
639  '<fragment xmlns="' . \Hoa\Xyl::NAMESPACE_ID . '">' .
640  '<snippet id="h"><yield>' . $xyl . '</yield></snippet>' .
641  '</fragment>'
642  );
643 
644  $root = $this->getAbstractElementSuperRoot();
645  $fragment = $root->open($stringBuffer->getStreamName());
646  $fragment->render($fragment->getSnippet('h'));
647 
648  return;
649  }
const NAMESPACE_ID
Definition: Xyl.php:66

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Xyl\Element\Concrete::computeTransientValue ( Stream\IStream\Out  $out = null)

Get transient value, i.e. get the last compute value if exists (if no exists, compute right now).

Parameters
\Hoa\Stream\IStream\Out$outOutput stream. If null, we return the result.
Returns
string

Definition at line 451 of file Concrete.php.

452  {
453  $data = $this->_transientValue;
454 
455  if (null === $data) {
456  return $this->computeValue($out);
457  }
458 
459  if (null === $out) {
460  return $data;
461  }
462 
463  $out->writeAll($data);
464 
465  return;
466  }
computeValue(Stream\IStream\Out $out=null)
Definition: Concrete.php:410

Here is the call graph for this function:

Hoa\Xyl\Element\Concrete::computeValue ( Stream\IStream\Out  $out = null)

Compute value. If the attribute exists, compute the current data, else compute the abstract element casted as string if no child is present, else rendering all children.

Parameters
\Hoa\Stream\IStream\Out$outOutput stream. If null, we return the result.
Returns
string

Definition at line 410 of file Concrete.php.

411  {
412  $data = false;
413 
414  if (true === $this->abstract->attributeExists('bind')) {
415  $data = $this->_transientValue = $this->getCurrentData();
416  }
417 
418  if (null === $out) {
419  if (false !== $data) {
420  return $data;
421  } else {
422  return $data = $this->_transientValue = $this->abstract->readAll();
423  }
424  }
425 
426  if (0 === count($this)) {
427  if (false !== $data) {
428  $out->writeAll($data);
429  } else {
430  $out->writeAll($this->abstract->readAll());
431  }
432 
433  return;
434  }
435 
436  foreach ($this as $child) {
437  $child->render($out);
438  }
439 
440  return;
441  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Xyl\Element\Concrete::firstUpdate ( )
private

First update for iterate data bucket.

Returns
void

Definition at line 322 of file Concrete.php.

323  {
324  if (!isset($this->_bucket['parent'])) {
325  return;
326  }
327 
328  $parent = &$this->_bucket['parent'];
329  $this->_bucket['data'] = &$parent['data'][$parent['current']][$parent['branche']];
330  reset($this->_bucket['data']);
331  $this->_bucket['current'] = 0;
332 
333  if (!isset($this->_bucket['data'][0])) {
334  unset($this->_bucket['data']);
335  $this->_bucket['data'] = [
336  &$parent['data'][$parent['current']][$parent['branche']]
337  ];
338  }
339 
340  return;
341  }

Here is the caller graph for this function:

Hoa\Xyl\Element\Concrete::formatValue (   $value,
  $name = null 
)
protected

Format an attribute value. Formatter is of the form: -formatter="functionName" Arguments of functionName are declared as: -formatter-argumentName="argumentValue"

Parameters
string$valueValue.
string$nameName.
Returns
string

Definition at line 563 of file Concrete.php.

564  {
565  $_formatter = $name . 'formatter';
566  $formatter = $this->abstract->readAttribute($_formatter);
567  $arguments = $this->abstract->readCustomAttributes($_formatter);
568 
569  foreach ($arguments as &$argument) {
570  $argument = $this->_formatValue(
571  $this->computeAttributeValue($argument)
572  );
573  }
574 
575  $reflection = xcallable($formatter)->getReflection();
576  $distribution = [];
577  $placeholder = $this->_formatValue($value);
578 
579  foreach ($reflection->getParameters() as $parameter) {
580  $name = strtolower($parameter->getName());
581 
582  if (true === array_key_exists($name, $arguments)) {
583  $distribution[$name] = $arguments[$name];
584 
585  continue;
586  } elseif (null !== $placeholder) {
587  $distribution[$name] = $placeholder;
588  $placeholder = null;
589  }
590  }
591 
592  if ($reflection instanceof \ReflectionMethod) {
593  $value = $reflection->invokeArgs(null, $distribution);
594  } else {
595  $value = $reflection->invokeArgs($distribution);
596  }
597 
598  return $value;
599  }
computeAttributeValue($value, $type=self::ATTRIBUTE_TYPE_UNKNOWN, $name=null)
Definition: Concrete.php:488

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Xyl\Element\Concrete::getCurrentData ( )
protected

Get current data of this element.

Returns
mixed

Definition at line 302 of file Concrete.php.

303  {
304  if (empty($this->_bucket['data'])) {
305  return;
306  }
307 
308  $current = $this->_bucket['data'][$this->_bucket['current']];
309 
310  if (!isset($current[$this->_bucket['branche']])) {
311  return null;
312  }
313 
314  return $current[$this->_bucket['branche']];
315  }

Here is the caller graph for this function:

Hoa\Xyl\Element\Concrete::getDeclaredAttributes ( )
protected

Get all declared attributes.

Returns
array

Definition at line 666 of file Concrete.php.

667  {
668  $out = static::_getDeclaredAttributes();
670 
671  foreach ($out as $attr => $type) {
672  if (self::ATTRIBUTE_TYPE_CUSTOM === $type) {
673  foreach ($abstract->readCustomAttributes($attr) as $a => $_) {
674  $out[$attr . '-' . $a] = self::ATTRIBUTE_TYPE_UNKNOWN;
675  }
676  }
677  }
678 
679  return $out;
680  }
Hoa\Xyl\Element\Concrete::getVisibility ( )

Get visibility.

Returns
bool

Definition at line 722 of file Concrete.php.

723  {
724  return $this->_visibility;
725  }

Here is the caller graph for this function:

Hoa\Xyl\Element\Concrete::isLastIteration ( )

Check if this is the last iteration or not.

Returns
bool

Definition at line 656 of file Concrete.php.

657  {
658  return $this->_lastIteration;
659  }

Here is the caller graph for this function:

Hoa\Xyl\Element\Concrete::paint ( Stream\IStream\Out  $out)
abstractprotected

Paint the element.

Parameters
\Hoa\Stream\IStream\Out$outOut stream.
Returns
void

Here is the caller graph for this function:

Hoa\Xyl\Element\Concrete::render ( Stream\IStream\Out  $out)

Make the render of the XYL tree.

Parameters
\Hoa\Stream\IStream\Out$outOut stream.
Returns
void

Definition at line 366 of file Concrete.php.

367  {
368  if (false === $this->getVisibility()) {
369  return;
370  }
371 
372  $this->firstUpdate();
373 
374  if (isset($this->_bucket['branche']) &&
375  (empty($this->_bucket['data']) ||
376  empty($this->_bucket['data'][$this->_bucket['current']][$this->_bucket['branche']]))) {
377  return;
378  }
379 
380  $data = &$this->_bucket['data'];
381 
382  do {
383  $next = is_array($data) ? next($data) : false;
384  $this->_lastIteration = false === $next;
385 
386  $this->paint($out);
387  $next = $next && $this->update();
388  } while (false !== $next);
389 
390  return;
391  }
paint(Stream\IStream\Out $out)

Here is the call graph for this function:

Hoa\Xyl\Element\Concrete::selectData (   $expression,
Array &  $bucket 
)
protected

Select data according to an expression into a bucket. Move pointer into bucket or fill a new bucket and return the last reachable branche.

Parameters
string$expressionExpression (please, see inline comments to study all cases).
array&$bucketBucket.
Returns
string

Definition at line 257 of file Concrete.php.

258  {
259  switch (Xyl::getSelector($expression, $matches)) {
260  case Xyl::SELECTOR_PATH:
261  $split = preg_split(
262  '#(?<!\\\)\/#',
263  $matches[1]
264  );
265 
266  foreach ($split as &$s) {
267  $s = str_replace('\/', '/', $s);
268  }
269 
270  $branche = array_pop($split);
271  $handle = &$bucket;
272 
273  foreach ($split as $part) {
274  $handle = &$bucket[0][$part];
275  }
276 
277  $bucket = $handle;
278 
279  return $branche;
280 
281  case Xyl::SELECTOR_QUERY:
282  var_dump('*** QUERY');
283  var_dump($matches);
284 
285  break;
286 
287  case Xyl::SELECTOR_XPATH:
288  var_dump('*** XPATH');
289  var_dump($matches);
290 
291  break;
292  }
293 
294  return null;
295  }
static getSelector($selector, &$matches=false)
Definition: Xyl.php:1819
const SELECTOR_QUERY
Definition: Xyl.php:108
const SELECTOR_PATH
Definition: Xyl.php:101
const SELECTOR_XPATH
Definition: Xyl.php:115

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Xyl\Element\Concrete::setVisibility (   $visibility)

Set visibility.

Parameters
bool$visibilityVisibility.
Returns
bool

Definition at line 709 of file Concrete.php.

710  {
711  $old = $this->_visibility;
712  $this->_visibility = $visibility;
713 
714  return $old;
715  }
Hoa\Xyl\Element\Concrete::update ( )
private

Continue to update the data bucket while iterating.

Returns
bool

Definition at line 348 of file Concrete.php.

349  {
350  if (!is_array($this->_bucket['data'])) {
351  return false;
352  }
353 
354  $this->_bucket['current'] = key($this->_bucket['data']);
355  $handle = current($this->_bucket['data']);
356 
357  return isset($handle[$this->_bucket['branche']]);
358  }

Here is the caller graph for this function:

Member Data Documentation

Hoa\Xyl\Element\Concrete::$_attributeBucket = null
private

Definition at line 109 of file Concrete.php.

Hoa\Xyl\Element\Concrete::$_attributes
staticprotected
Initial value:
= [
'id' => self::ATTRIBUTE_TYPE_ID

Definition at line 132 of file Concrete.php.

Hoa\Xyl\Element\Concrete::$_bucket = ['data' => null]
private

Definition at line 102 of file Concrete.php.

Hoa\Xyl\Element\Concrete::$_lastIteration = false
protected

Definition at line 150 of file Concrete.php.

Hoa\Xyl\Element\Concrete::$_transientValue = null
protected

Definition at line 123 of file Concrete.php.

Hoa\Xyl\Element\Concrete::$_visibility = true
protected

Definition at line 116 of file Concrete.php.

const Hoa\Xyl\Element\Concrete::ATTRIBUTE_TYPE_CUSTOM = 4

Attribute type: custom (e.g. data-*).

int

Definition at line 81 of file Concrete.php.

const Hoa\Xyl\Element\Concrete::ATTRIBUTE_TYPE_ID = 2

Attribute type: id (if it represents an ID).

int

Definition at line 74 of file Concrete.php.

const Hoa\Xyl\Element\Concrete::ATTRIBUTE_TYPE_LINK = 16

Attribute type: link (if it is a link).

int

Definition at line 95 of file Concrete.php.

const Hoa\Xyl\Element\Concrete::ATTRIBUTE_TYPE_LIST = 8

Attribute type: list (e.g. the class attribute).

int

Definition at line 88 of file Concrete.php.

const Hoa\Xyl\Element\Concrete::ATTRIBUTE_TYPE_NORMAL = 1

Attribute type: normal.

int

Definition at line 67 of file Concrete.php.

const Hoa\Xyl\Element\Concrete::ATTRIBUTE_TYPE_UNKNOWN = 0

Attribute type: unknown.

int

Definition at line 60 of file Concrete.php.


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