/** * @return RokCommon_XMLElement */ public function getJoinedXml() { foreach ($this->files as $priority => $filegroup) { foreach ($filegroup as $file) { $this->logger->debug(rc__('Adding file %s.', $file)); $file_xml = RokCommon_Utils_XMLHelper::getXML($file); self::mergeNodes($this->xml, $file_xml); } } foreach ($this->sections as $identifier => &$section) { $this->logger->debug(rc__('Adding options section %s.', $identifier)); $section_xml = $section->getXML(); self::mergeNodes($this->xml, $section_xml); } $this->xml = self::sortFields($this->xml); return $this->xml; }
/** * @param $parent_identifier * @param $file * * @param null $xml * * @throws \RokCommon_Config_Exception */ protected function __construct($parent_identifier, $file = null, $xml = null) { $this->parent_identifier = $parent_identifier; $this->joined_xml = new RokCommon_XMLElement('<config/>'); $this->container = RokCommon_Service::getContainer(); $this->root_file = $file; if (empty($xml)) { $xml = RokCommon_Utils_XMLHelper::getXML($file); } $this->initialize($xml); $this->process(); }
/** * @return RokCommon_XMLElement * @throws RokCommon_Config_Exception */ public function getXml() { $context = RokCommon_Composite::get(self::CONTEXT_PREFIX . $this->identifier); if ($context) { if ($this->searchMode == self::SEARCH_MODE_BASEDIRS) { $ret = $context->getAll($this->filename); } elseif ($this->searchMode == self::SEARCH_MODE_CHILDIRS) { $ret = $context->getAllSubFiles($this->filename); } else { throw new RokCommon_Config_Exception(rc__('Unknown mode of %s on config', $this->searchMode)); } ksort($ret, SORT_NUMERIC); foreach ($ret as $priority => $files) { foreach ($files as $file) { $file_xml = RokCommon_Utils_XMLHelper::getXML($file, true); RokCommon_Options::mergeNodes($this->xml, $file_xml); } } } return $this->xml; }
/** * Method to set a field XML element to the form definition. If the replace flag is set then * the field will be set whether it already exists or not. If it isn't set, then the field * will not be replaced if it already exists. * * @param object &$element The XML element object representation of the form field. * @param string $group The optional dot-separated form group path on which to set the field. * @param boolean $replace True to replace an existing field if one already exists. * * @return boolean True on success. * * @since 11.1 */ public function setField(&$element, $group = null, $replace = true) { // Make sure there is a valid RokCommon_Form XML document. if (!$this->xml instanceof SimpleXMLElement) { // TODO: throw exception. return false; } // Make sure the element to set is valid. if (!$element instanceof SimpleXMLElement) { // TODO: throw exception. return false; } // Find the form field element from the definition. $old =& $this->findField((string) $element['name'], $group); // If an existing field is found and replace flag is false do nothing and return true. if (!$replace && !empty($old)) { return true; } // If an existing field is found and replace flag is true remove the old field. if ($replace && !empty($old) && $old instanceof SimpleXMLElement) { $dom = dom_import_simplexml($old); $dom->parentNode->removeChild($dom); } // If no existing field is found find a group element and add the field as a child of it. if ($group) { // Get the fields elements for a given group. $fields =& $this->findGroup($group); // If an appropriate fields element was found for the group, add the element. if (isset($fields[0]) && $fields[0] instanceof SimpleXMLElement) { RokCommon_Utils_XMLHelper::addNode($fields[0], $element); } } else { // Set the new field to the form. RokCommon_Utils_XMLHelper::addNode($this->xml, $element); } // Synchronize any paths found in the load. $this->syncPaths(); return true; }
/** * Method to load the form description from an XML file. * * The reset option works on a group basis. If the XML file references * groups that have already been created they will be replaced with the * fields in the new XML file unless the $reset parameter has been set * to false. * * @param string $file The filesystem path of an XML file. * @param string $reset Flag to toggle whether form fields should be replaced if a field * already exists with the same group/name. * @param string $xpath An optional xpath to search for the fields. * * @return boolean True on success, false otherwise. * * @since 11.1 */ public function loadFile($file, $reset = true, $xpath = false) { // Check to see if the path is an absolute path. if (!is_file($file)) { $file = RokCommon_Composite::get(self::FORM_PATH_PACKAGE)->get($file . '.xml'); // If unable to find the file return false. if (!$file) { return false; } } // Attempt to load the XML file. $xml = RokCommon_Utils_XMLHelper::getXML($file, true); return $this->load($xml, $reset, $xpath); }