/** * Creates a navigation from the given * config * * @param XmlElement $config */ public function __construct(XmlElement $config) { $this->setDomTag(self::UL_TAG); $this->setDomStr(self::UL_STR); $this->config = $config; // Apply config data foreach ($this->config->getChildren() as $child) { $this->pages[] = $this->getPageByConfig($child); } $this->setChildren($this->pages); }
/** * Init a form (with a given xml config) * * @param \Fewlines\Core\Xml\Tree\Element|null $config */ public function __construct(\Fewlines\Core\Xml\Tree\Element $config = null) { // Set dom relevant flags $this->setDomStr(self::FORM_STR); $this->setDomTag(self::FORM_TAG); // Create result to store all validations $this->result = new Result(); // Add config by xml if (true == $config instanceof \Fewlines\Core\Xml\Tree\Element) { $this->config = $config; // Add own attributes (of the form element) $this->setFormAttributesByConfig(); // Add global validation for all inputs (if exists) $validation = $this->config->getChildByName('validation', false); if ($validation instanceof \Fewlines\Core\Xml\Tree\Element) { $this->validation = new Validation($validation->getChildByName('errors', false)); } // Get form items defined in the xml config $elements = $this->config->getChildren(); // Add the form elements from the config as element if (false != $elements && $elements > 0) { $this->addElementsByXmlConfig($elements); } } }
/** * @param array|XmlElement $errors * @param array|XmlElement $options * @param array|XmlElement $defaultErrors */ public function __construct($errors = array(), $options = array(), $defaultErrors = array()) { /** * Use xml object to set the errors * Otherwise use an array (Manually) */ if ($errors instanceof XmlElement) { foreach ($errors->getChildren() as $child) { $this->addError($child->getName(), $child->getContent()); } } else { if (true == is_array($errors)) { foreach ($errors as $type => $message) { $this->addError($type, $message); } } } /** * Use xml object to set the options * of the validation * Otherwise use an array (Manually) */ if ($options instanceof XmlElement) { foreach ($options->getAttributes() as $type => $value) { $this->addOption($type, $value); } } else { if (true == is_array($options)) { foreach ($options as $type => $value) { $this->addOption($type, $value); } } } /** * Set default errors as fallback */ if ($defaultErrors instanceof XmlElement) { foreach ($defaultErrors->getChildren() as $child) { $this->addError($child->getName(), $child->getContent(), true); } } else { if (true == is_array($defaultErrors)) { foreach ($defaultErrors as $type => $message) { if ($message instanceof Error) { $this->defaultErrors[] = $message; continue; } $this->addError($type, $message, true); } } } /** * Prepeare the result and * parse the errors */ $this->result = new Validation\Result($this->errors, $this->defaultErrors); }
/** * Adding the route to the collection (recursive). * All subroutes will be flattenend and also added * to this collection, to save the parent element in * which they are nested in it will given to the * route * * @param XmlElement $element * @param Routes\Route $parent */ public function addRouteByElement(XmlElement $element, Routes\Route $parent = null) { $name = strtolower($element->getName()); // Add route to parent if (true == preg_match(HTTP_METHODS_PATTERN, $name)) { $route = static::createRoute($name, $element->getAttribute('from'), $element->getAttribute('to')); // Add optional attributes if ($element->hasAttribute('id')) { $route->setId($element->getAttribute('id')); } $this->add($route); if (!is_null($parent)) { $route->setParent($parent); } // Add children if ($element->hasChildren()) { foreach ($element->getChildren() as $child) { $this->addRouteByElement($child, $route); } } } }