function AdminLayoutObjectInfo() { $xml = new XmlReader(CMS_XML_PATH . 'layout.xml'); $layout_node = $xml->selectNodes('layout'); $cDefault = 0; for ($i = 0; $i < count($layout_node); $i++) { $child = $xml->getChildren($layout_node[$i]); $name = $xml->getValue($child[0]); $template = $xml->getValue($child[1]); $output_name = $xml->getValue($child[2]); $css_name = $xml->getValue($child[3]); $css_file = $xml->getValue($child[4]); $default = $xml->getValue($child[5]); if ($default == 1) { $this->_layoutObject = new AdminLayoutObject($name, $template, $output_name, $css_name, $css_file); $cDefault++; } } if ($cDefault > 1) { new ErrorHandler(get_class($this), "constructor", "", "DEFAULT LAYOUT", "There is mor than ONE default layout set!"); } if ($cDefault == 0) { new ErrorHandler(get_class($this), "constructor", "", "DEFAULT LAYOUT", "There is NO default layout set!"); } $this->setFrames($xml, $this->_layoutObject->getName()); }
/** * @dataProvider provideNodes */ public function testNodes($seek, $expectedDump) { while ($seek--) { $this->reader->read(); } $this->assertDumpMatchesFormat($expectedDump, $this->reader); }
function AdminPageObjectInfo() { $xml = new XmlReader(CMS_XML_PATH . 'pages.xml'); $page_node = $xml->selectNodes('page'); $cPrimaryPage = 0; $cSecondaryPage = 0; for ($i = 0; $i < count($page_node); $i++) { $child = $xml->getChildren($page_node[$i]); $pageName = $xml->getValue($child[0]); $pageTemplate = $xml->getValue($child[1]); $pageTitle = $xml->getValue($child[2]); $pageOrder = $xml->getValue($child[3]); $shortName = $xml->getValue($child[4]); $mainBlock = $xml->getValue($child[5]); if ($pageOrder == 1) { $this->_primaryPage = $pageName; $cPrimaryPage++; } if ($pageOrder == 2) { $this->_secondaryPage = $pageName; $cSecondaryPage++; } $page = new AdminPageObject($pageName, $pageTemplate, $pageTitle, $shortName, $mainBlock); $this->_pagesArray[$i][0] = $pageName; $this->_pagesArray[$i][1] = $page; } }
public static function castXmlReader(\XmlReader $reader, array $a, Stub $stub, $isNested) { $props = Caster::PREFIX_VIRTUAL . 'parserProperties'; $info = array('localName' => $reader->localName, 'prefix' => $reader->prefix, 'nodeType' => new ConstStub(self::$nodeTypes[$reader->nodeType], $reader->nodeType), 'depth' => $reader->depth, 'isDefault' => $reader->isDefault, 'isEmptyElement' => \XmlReader::NONE === $reader->nodeType ? null : $reader->isEmptyElement, 'xmlLang' => $reader->xmlLang, 'attributeCount' => $reader->attributeCount, 'value' => $reader->value, 'namespaceURI' => $reader->namespaceURI, 'baseURI' => $reader->baseURI, $props => array('LOADDTD' => $reader->getParserProperty(\XmlReader::LOADDTD), 'DEFAULTATTRS' => $reader->getParserProperty(\XmlReader::DEFAULTATTRS), 'VALIDATE' => $reader->getParserProperty(\XmlReader::VALIDATE), 'SUBST_ENTITIES' => $reader->getParserProperty(\XmlReader::SUBST_ENTITIES))); if ($info[$props] = Caster::filter($info[$props], Caster::EXCLUDE_EMPTY, array(), $count)) { $info[$props] = new EnumStub($info[$props]); $info[$props]->cut = $count; } $info = Caster::filter($info, Caster::EXCLUDE_EMPTY, array(), $count); // +2 because hasValue and hasAttributes are always filtered $stub->cut += $count + 2; return $a + $info; }
protected function buildMsisdnFormat(XmlReader $xml, $country) { $formats = array(); $prefix = null; $nationalDialingPrefix = null; $exampleMobile = null; $missingAttributeMessage = "No msisdn '%s' attribute found for country node '{$country}' in configuration file '" . self::$msisdnFormatConfigFilename . "'"; // save the prefix if (!$xml->moveToAttribute('prefix')) { throw new MissingFormatConfigurationException(sprintf($missingAttributeMessage, 'prefix')); } $prefix = $xml->value; // save the national dialing prefix if (!$xml->moveToAttribute('nationalDialingPrefix')) { throw new MissingFormatConfigurationException(sprintf($missingAttributeMessage, 'nationalDialingPrefix')); } $nationalDialingPrefix = $xml->value; // save the example mobile number if (!$xml->moveToAttribute('exampleMobile')) { throw new MissingFormatConfigurationException(sprintf($missingAttributeMessage, 'exampleMobile')); } $exampleMobile = $xml->value; if ('' === trim($exampleMobile)) { throw new MissingFormatConfigurationException("Attribute 'exampleMobile was blank for country ndoe '{$country}' in configuration file '" . self::$msisdnFormatConfigFilename . "'"); } // read everything, stopping at the format entities while ($xml->read()) { // we found a format entity if (XMLReader::ELEMENT === $xml->nodeType && 'format' === $xml->name) { // grab the regular expression $xml->moveToAttribute('expression'); $formats[] = '/^' . $xml->value . '$/'; continue; } // break to outer loop if we've advanced beyond the current country if ('country' === $xml->name) { break; } } if (!count($formats)) { throw new MissingFormatConfigurationException("No 'format' node(s) present for country node for '{$country}' within configuration file '" . self::$msisdnFormatConfigFilename . "'."); } $msisdnFormat = new MsisdnFormat(); $msisdnFormat->setCountry($country); $msisdnFormat->setInternationalPrefix($prefix); $msisdnFormat->setNationalDialingPrefix($nationalDialingPrefix); $msisdnFormat->setExampleMobile($exampleMobile); $msisdnFormat->setFormats($formats); return $msisdnFormat; }
/** * reads the xml file dbproperties.xml and puts the data in several Arrays[] * this class can have several database connections * if another database connection is needed, you can put these data in the dbproperties.xml * and create new function like get_postgresconn(), offcourse there must be a class postgres_db * constructor * @return ctrl_db * @access public */ function CtrlDb() { #create a new instance of xml_reader $xml = new XmlReader('dbproperties.xml'); #select the nodes which you want to read out => dbproperties $root = $xml->selectNodes('dbproperties'); for ($i = 0; $i < count($root); $i++) { #select all the childrens of the "dbproperties" node $db = $xml->getChildren($root[$i]); for ($j = 0; $j < count($db); $j++) { #select all the childrens of $db #get all the children nodes values and put it in arrays[] $data = $xml->getChildren($db[$j]); $this->dbname[$j] = $xml->getValue($data[0]); $this->user[$j] = $xml->getValue($data[1]); $this->pass[$j] = $xml->getValue($data[2]); $this->host[$j] = $xml->getValue($data[3]); $this->port[$j] = $xml->getValue($data[4]); } } }
/** * Learn XML file * * Learn the automaton from an XML file * * @param string $file * @return void */ public function learnFile($file) { $reader = new XmlReader(); $reader->open($file); $this->traverse($reader); $reader->close(); unset($reader); }
public function readXml(\XmlReader $xml, $class) { $xml->read(); return $this->_readObject($xml, $class, true); // TODO check end of file? }
public function generateSql($xmlDump, $sqlOutput = false) { if ($sqlOutput) { if (file_exists($sqlOutput)) { throw new \Exception('SQL output file exists'); } $output = fopen($sqlOutput, 'w'); if (!$output) { throw new \Exception('Unable to create SQL output file'); } } else { $output = false; } // Load the XML file for reading and advance to the first element. $xmlReader = new \XmlReader(); $xmlReader->open($xmlDump); $xmlReader->read(); /** * If the dump is properly formed, the first element should be a * mysqldump node. */ if ($xmlReader->name != 'mysqldump') { throw new MysqlDumpException('mysqldump node not present'); } /** * Iterate through the available XML nodes, while there's still * something to read. */ while ($xmlReader->read()) { // If this isn't the start of a node, we don't care. Next. if ($xmlReader->nodeType != \XmlReader::ELEMENT) { continue; } switch ($xmlReader->name) { case 'database': // Attempt to pull the database name we should be using. $database = $xmlReader->getAttribute('name'); if (empty($database)) { throw new MysqlDumpException('No database name'); } // Generate that SQL. $createDatabase = sprintf('create database if not exists `%s`;', $database); $this->doOutput("{$createDatabase}\n", $output); $this->doOutput("use `{$database}`;\n", $output); unset($database, $createDatabase); break; case 'table_structure': $tableStructure = simplexml_load_string($xmlReader->readOuterXML(), 'Initvector\\Xml2Mysql\\XmlNode\\TableStructure'); $this->doOutput($tableStructure->getCreateTable() . "\n", $output); /** * All children for this node have been processed, so we * can safely skip to the next sibling. */ $xmlReader->next(); unset($tableStructure); break; case 'table_data': $table = $xmlReader->getAttribute('name'); if (empty($table)) { throw new MysqlDumpException('No table name'); } $xmlReader->read(); $columns = array(); $rowBuffer = array(); while ($xmlReader->nodeType != \XMLReader::END_ELEMENT) { if ($xmlReader->name == 'row') { $tableRow = $tableStructure = simplexml_load_string($xmlReader->readOuterXML(), 'Initvector\\Xml2Mysql\\XmlNode\\Row'); $rowData = $tableRow->getData(); if (empty($columns)) { $columns = array_keys($rowData); } $rowBuffer[] = $rowData; if ($this->outputInsert($table, $columns, $rowBuffer, $output)) { $rowBuffer = array(); } } $xmlReader->next(); } $this->outputInsert($table, $columns, $rowBuffer, $output, true); break; } } // Close the MySQL XML dump file $xmlReader->close(); }
public function replaceTokens($pattern) { $xml = new XmlReader($this->content); $queryString = str_replace("#{", "", str_replace("}", "", $pattern[0])); return @$xml->query($queryString); }