private function parseRequestParameter(AgaviXmlConfigDomElement $validator) { $parameter = array(); $parameter["required"] = $validator->getAttribute("required"); $parameter["type"] = $validator->getAttribute("class"); $validationParameters = null; $ae = self::$NsEnvelope["key"]; foreach ($validator->childNodes as $subEntry) { switch ($subEntry->nodeName) { case 'argument': $parameter["argument"] = $subEntry->nodeValue; break; case 'arguments': $parameter["argument"] = array("base" => $subEntry->getAttribute("base"), "arguments" => array()); foreach ($subEntry->childNodes as $argument) { if (trim($argument->nodeValue)) { $parameter["argument"]["arguments"][] = trim($argument->nodeValue); } } break; case $ae . ':parameter': case $ae . ':parameters': $validationParameters = $subEntry; } } if ($validationParameters) { $parameter["parameters"] = $validationParameters->getAgaviParameters(); } return array_unique($parameter); }
private function getXmlConfiguration(AgaviXmlConfigDomElement $cfg, $tuple_element, $item_element, &$store) { if ($cfg->has($tuple_element)) { foreach ($cfg->get($tuple_element) as $item) { if ($item->hasAgaviParameters()) { $store[$item->getAttribute('name')] = $item->getAgaviParameters(); } } return true; } }
/** * Collect resource files * * @param string resource * @param string resource suffix * @param AgaviXmlConfigDomElement resource config * * @return array files * * @author Eric Lippmann <*****@*****.**> * @since 1.5.0 */ protected function collectResource($resource, $sfx, AgaviXmlConfigDomElement $cfg) { $resources = array(); foreach ($cfg->getChildren($resource, null, false) as $rcfg) { $_resources = array(); foreach ($rcfg->getAgaviParameters() as $r) { if (is_dir($r)) { $_resources = array_merge($_resources, array_keys(iterator_to_array(AppKitIteratorUtil::RegexRecursiveDirectoryIterator($r, sprintf('/^[^.].+\\%s$/i', $sfx))))); } else { $_resources[] = $r; } } $resources = array_merge($resources, $_resources); } return $resources; }
/** * Converts an AgaviXmlConfigDomElement into an array. * * @param AgaviXmlConfigDomElement The configuration element to convert. * @param bool Whether this is a top level element. * * @return array The configuration values as an array. * * @author Dominik del Bondio <*****@*****.**> * @author David Zülke <*****@*****.**> * @since 0.11.0 */ protected function convertToArray(AgaviXmlConfigDomElement $item, $topLevel = false) { $idAttribute = $this->getParameter('id_attribute', 'name'); $valueKey = $this->getParameter('value_key', 'value'); $forceArrayValues = $this->getParameter('force_array_values', false); $attributePrefix = $this->getParameter('attribute_prefix', ''); $literalize = $this->getParameter('literalize', true); $singularParentName = AgaviInflector::singularize($item->getName()); $data = array(); $attribs = $item->getAttributes(); $numAttribs = count($attribs); if ($idAttribute && $item->hasAttribute($idAttribute)) { $numAttribs--; } foreach ($item->getAttributes() as $name => $value) { if ($topLevel && in_array($name, array('context', 'environment')) || $name == $idAttribute) { continue; } if ($literalize) { $value = AgaviToolkit::literalize($value); } if (!isset($data[$name])) { $data[$attributePrefix . $name] = $value; } } if (!(int) $item->ownerDocument->getXpath()->evaluate(sprintf('count(*[namespace-uri() = "%s"])', $item->ownerDocument->getDefaultNamespaceUri()), $item)) { if ($literalize) { $val = $item->getLiteralValue(); } else { $val = $item->getValue(); } if ($val === null) { $val = ''; } if (!$topLevel && ($numAttribs || $forceArrayValues)) { $data[$valueKey] = $val; } elseif (!$topLevel) { $data = $val; } } else { $names = array(); $children = $item->ownerDocument->getXpath()->query(sprintf('*[namespace-uri() = "%s"]', $item->ownerDocument->getDefaultNamespaceUri()), $item); foreach ($children as $child) { $names[] = $child->getName(); } $dupes = array(); foreach (array_unique(array_diff_assoc($names, array_unique($names))) as $name) { $dupes[] = $name; } foreach ($children as $key => $child) { $hasId = $idAttribute && $child->hasAttribute($idAttribute); $isDupe = in_array($child->getName(), $dupes); $hasParent = $child->getName() == $singularParentName && $item->getName() != $singularParentName; if (($hasId || $isDupe) && !$hasParent) { // it's one of multiple tags in this level without the respective plural form as the parent node if (!isset($data[$idx = AgaviInflector::pluralize($child->getName())])) { $data[$idx] = array(); } $hasParent = true; $to =& $data[$idx]; } else { $to =& $data; } if ($hasId) { $key = $child->getAttribute($idAttribute); if ($literalize) { // no literalize, just constants! $key = AgaviToolkit::expandDirectives($key); } $to[$key] = $this->convertToArray($child); } elseif ($hasParent) { $to[] = $this->convertToArray($child); } else { $to[$child->getName()] = $this->convertToArray($child); } } } return $data; }
/** * Retrieve all of the Agavi error elements associated with this * element. * * @param AgaviXmlConfigDomElement The value holder of this validator. * @param array An array of existing errors. * * @return array The complete array of errors. * * @author Jan Schütze <*****@*****.**> * @author Steffen Gransow <*****@*****.**> * * @since 1.0.8 */ public function getAgaviErrors(AgaviXmlConfigDomElement $node, array $existing = array()) { $result = $existing; $elements = $node->get('errors', self::XML_NAMESPACE); foreach ($elements as $element) { $key = ''; if ($element->hasAttribute('for')) { $key = $element->getAttribute('for'); } $result[$key] = $element->getValue(); } return $result; }