Ejemplo n.º 1
0
 /**
  * Apply the preset to the given component.
  *
  * @param Component $component
  */
 function apply(Component $component)
 {
     if ($this->props) {
         $component->props->applyDefaults($this->props);
     }
     if ($this->unset) {
         foreach ($this->unset as $prop) {
             unset($component->props->{$prop});
         }
     }
     if ($this->content) {
         $component->removeChildren();
         Metadata::compile($this->content, $component);
     }
     if ($this->prepend) {
         Metadata::compile($this->prepend, $component, true);
     }
     if ($this->append) {
         Metadata::compile($this->append, $component);
     }
 }
Ejemplo n.º 2
0
 /**
  * Returns the value converted to a the data type required by the specified property.
  *
  * @param string $name
  * @param mixed  $v
  * @return bool|float|int|null|string|\Traversable
  * @throws ComponentException
  */
 function typecastPropertyValue($name, $v)
 {
     if ($this->isScalar($name) && $this->isEnum($name)) {
         $this->validateEnum($name, $v);
     }
     $type = $this->getTypeOf($name);
     if ($type && !type::validate($type, $v)) {
         throw new ComponentException($this->component, sprintf("%s is not a valid value for the <kbd>{$name}</kbd> property, which is of type <kbd>%s</kbd>", is_scalar($v) ? sprintf("The %s<kbd>%s</kbd>", typeOf($v), var_export($v, true)) : sprintf("A value of PHP type <kbd>%s</kbd>", typeOf($v)), type::getNameOf($type)));
     }
     // A special case for content type properties:
     // Convert a content property specified as attribute=string to a format equivalent to the one generated by
     // <subtag>string</subtag>
     if ($type == type::content && is_string($v)) {
         $content = new Metadata($this->component->context, $name, type::metadata);
         $content->setChildren([Text::from($this->component->context, $v)]);
         return $content;
     }
     return type::typecast($type, $v);
 }
 function getDefaultValue($name)
 {
     if (!$this->macroInstance) {
         $this->noMacro();
     }
     $param = $this->macroInstance->getParameter($name, $found);
     if (!$found) {
         throw new ComponentException($this->component, "Undefined macro parameter <kbd>{$name}</kbd>.\n<p>Available parameters: <b>" . implode(', ', $this->component->props->getPropertyNames()) . '</b>');
     }
     $v = $param->getComputedPropValue('default');
     if (isset($v) && $v !== '' && $param->props->type == 'content') {
         $meta = new Metadata($this->macroInstance->context, ucfirst($name), type::content);
         $meta->attachTo($this->component);
         $meta->addChild(Text::from($this->macroInstance->context, $v));
         return $meta;
     }
     return $v;
 }
Ejemplo n.º 4
0
 private function subtag_createSlotSubcontent($name, $tagName, array $attributes = null, array $bindings = null)
 {
     $param = $this->current;
     $this->current = $subparam = new Metadata($param->context, $tagName, $this->metadataContainer->type, $attributes);
     $subparam->setBindings($bindings);
     $param->addChild($subparam);
 }