Hoa central
Translate.php
Go to the documentation of this file.
1 <?php
2 
38 
39 use Hoa\Stream;
40 use Hoa\Xyl;
41 
51 {
57  protected static $_attributes = [
58  'n' => self::ATTRIBUTE_TYPE_NORMAL,
59  'with' => self::ATTRIBUTE_TYPE_CUSTOM
60  ];
61 
62 
63 
70  public function paint(Stream\IStream\Out $out)
71  {
72  $root = $this->getAbstractElementSuperRoot();
73  $value = $this->computeValue();
74  $with = '__main__';
75 
76  if (true === $this->abstract->attributeExists('with')) {
77  $with = $this->abstract->readAttribute('with');
78  }
79 
80 
81  $translation = $root->getTranslation($with);
82 
83  if (null === $translation) {
84  $out->writeAll($value);
85 
86  return;
87  }
88 
89  $callable = null;
90  $arguments = [$value];
91 
92  if (true === $this->abstract->attributeExists('n')) {
93  $callable = xcallable($translation, '_n');
94  $arguments[] = $this->abstract->readAttribute('n');
95  } else {
96  $callable = xcallable($translation, '_');
97  }
98 
99  $with = $this->abstract->readCustomAttributes('with');
100 
101  if (!empty($with)) {
102  foreach ($with as $w) {
103  $arguments[] = $this->computeAttributeValue($w);
104  }
105  }
106 
107  $result = $callable->distributeArguments($arguments);
108 
109  if (false !== strpos($result, '<')) {
110  $this->computeFromString($result);
111  } else {
112  $out->writeAll($result);
113  }
114 
115  return;
116  }
117 }
static paint(Stream\IStream\Out $out)
Definition: Translate.php:70
computeValue(Stream\IStream\Out $out=null)
Definition: Concrete.php:410
computeAttributeValue($value, $type=self::ATTRIBUTE_TYPE_UNKNOWN, $name=null)
Definition: Concrete.php:488