/** * Build a response object * * @param \GuzzleHttp\Psr7\Response $response * @return Activity[] */ public function map(Response $response) { // Pares XML $reader = new Reader(); $reader->xml($response->getBody()); $parse = $reader->parse(); $return = []; foreach ($parse['value'] as $value) { $return[] = new Activity($value['attributes'], $value['value']); } return $return; }
function testDeserialize() { $input = <<<BLA <?xml version="1.0"?> <root xmlns="http://sabredav.org/ns"> <listThingy> <elem1 /> <elem2 /> <elem3 /> <elem4 attr="val" /> <elem5>content</elem5> <elem6><subnode /></elem6> </listThingy> <listThingy /> <otherThing> <elem1 /> <elem2 /> <elem3 /> </otherThing> </root> BLA; $reader = new Reader(); $reader->elementMap = ['{http://sabredav.org/ns}listThingy' => 'Sabre\\Xml\\Element\\Elements']; $reader->xml($input); $output = $reader->parse(); $this->assertEquals(['name' => '{http://sabredav.org/ns}root', 'value' => [['name' => '{http://sabredav.org/ns}listThingy', 'value' => ['{http://sabredav.org/ns}elem1', '{http://sabredav.org/ns}elem2', '{http://sabredav.org/ns}elem3', '{http://sabredav.org/ns}elem4', '{http://sabredav.org/ns}elem5', '{http://sabredav.org/ns}elem6'], 'attributes' => []], ['name' => '{http://sabredav.org/ns}listThingy', 'value' => [], 'attributes' => []], ['name' => '{http://sabredav.org/ns}otherThing', 'value' => [['name' => '{http://sabredav.org/ns}elem1', 'value' => null, 'attributes' => []], ['name' => '{http://sabredav.org/ns}elem2', 'value' => null, 'attributes' => []], ['name' => '{http://sabredav.org/ns}elem3', 'value' => null, 'attributes' => []]], 'attributes' => []]], 'attributes' => []], $output); }
function parse($xml, array $elementMap = []) { $reader = new Reader(); $reader->elementMap = array_merge($this->elementMap, $elementMap); $reader->xml($xml); return $reader->parse(); }
function parse($xml) { $reader = new Reader(); $reader->elementMap['{DAV:}root'] = 'Sabre\\DAVACL\\Xml\\Property\\CurrentUserPrivilegeSet'; $reader->xml($xml); $result = $reader->parse(); return $result['value']; }
public function read($path) { parent::read($path); $reader = new Reader(); $reader->xml($this->contents); $this->parsed = $reader->parse(); return $this; }
public function testParseReturnsArray() { $rw = new Realworks(); $xmlString = file_get_contents('example.xml'); $reader = new XML\Reader(); $reader->xml($xmlString); $output = $reader->parse(); $objects = $rw->parse($output); $this->assertInternalType('array', $objects); }
protected function read($xmlFile) { $xml_contents = file_get_contents($xmlFile); $reader = new Reader(); $reader->xml($xml_contents); $tree = $reader->parse(); foreach ($tree['value'] as $node) { $key = $node['attributes']['name']; $value = $node['value']; $this->patterns[$key] = $value; } }
/** * @expectedException \LogicException */ function testDeserialize() { $input = <<<BLA <?xml version="1.0"?> <root xmlns="http://sabredav.org/ns"> <blabla /> </root> BLA; $reader = new Reader(); $reader->elementMap = ['{http://sabredav.org/ns}blabla' => 'Sabre\\Xml\\Element\\Cdata']; $reader->xml($input); $output = $reader->parse(); }
/** * @dataProvider xmlProvider */ function testDeserialize($input, $expected) { $input = <<<BLA <?xml version="1.0"?> <root xmlns="http://sabredav.org/ns"> <fragment>{$input}</fragment> </root> BLA; $reader = new Reader(); $reader->elementMap = ['{http://sabredav.org/ns}fragment' => 'Sabre\\Xml\\Element\\XmlFragment']; $reader->xml($input); $output = $reader->parse(); $this->assertEquals(['name' => '{http://sabredav.org/ns}root', 'value' => [['name' => '{http://sabredav.org/ns}fragment', 'value' => new XmlFragment($expected), 'attributes' => []]], 'attributes' => []], $output); }
function testDeserialize() { $input = <<<BLA <?xml version="1.0"?> <root xmlns="http://sabredav.org/ns"> <uri>/foo/bar</uri> </root> BLA; $reader = new Reader(); $reader->contextUri = 'http://example.org/'; $reader->elementMap = ['{http://sabredav.org/ns}uri' => 'Sabre\\Xml\\Element\\Uri']; $reader->xml($input); $output = $reader->parse(); $this->assertEquals(['name' => '{http://sabredav.org/ns}root', 'value' => [['name' => '{http://sabredav.org/ns}uri', 'value' => new Uri('http://example.org/foo/bar'), 'attributes' => []]], 'attributes' => []], $output); }
function testDeserializeValueObjectEmpty() { $input = <<<XML <?xml version="1.0"?> <foo xmlns="urn:foo" /> XML; $reader = new Reader(); $reader->xml($input); $reader->elementMap = ['{urn:foo}foo' => function (Reader $reader) { return valueObject($reader, 'Sabre\\Xml\\Deserializer\\TestVo', 'urn:foo'); }]; $output = $reader->parse(); $vo = new TestVo(); $expected = ['name' => '{urn:foo}foo', 'value' => $vo, 'attributes' => []]; $this->assertEquals($expected, $output); }
/** * The xmlSerialize metod is called during xml writing. * * Use the $writer argument to write its own xml serialization. * * An important note: do _not_ create a parent element. Any element * implementing XmlSerializble should only ever write what's considered * its 'inner xml'. * * The parent of the current element is responsible for writing a * containing element. * * This allows serializers to be re-used for different element names. * * If you are opening new elements, you must also close them again. * * @param Writer $writer * @return void */ function xmlSerialize(Writer $writer) { $reader = new Reader(); // Wrapping the xml in a container, so root-less values can still be // parsed. $xml = <<<XML <?xml version="1.0"?> <xml-fragment xmlns="http://sabre.io/ns">{$this->getXml()}</xml-fragment> XML; $reader->xml($xml); $elementNamespace = null; while ($reader->read()) { if ($reader->depth < 1) { // Skipping the root node. continue; } switch ($reader->nodeType) { case Reader::ELEMENT: $writer->startElement($reader->getClark()); $empty = $reader->isEmptyElement; while ($reader->moveToNextAttribute()) { switch ($reader->namespaceURI) { case '': $writer->writeAttribute($reader->localName, $reader->value); break; case 'http://www.w3.org/2000/xmlns/': // Skip namespace declarations break; default: $writer->writeAttribute($reader->getClark(), $reader->value); break; } } if ($empty) { $writer->endElement(); } break; case Reader::CDATA: case Reader::TEXT: $writer->text($reader->value); break; case Reader::END_ELEMENT: $writer->endElement(); break; } } }
public static function loadFilename($filename) { $xml_contents = file_get_contents($filename); $reader = new Reader(); /** * Loading components */ $components_list = array(); $components = scandir(__DIR__ . '/../../Component/'); foreach ($components as $file) { if ($file[0] == '.') { continue; } if (substr($file, -4) != '.php') { continue; } $componentName = substr($file, 0, -strlen('Component.php')); $components_list['{http://github.com/mermetbt/Biome/}' . strtolower($componentName)] = 'Biome\\Component\\' . $componentName . 'Component'; } $components_dirs = \Biome\Biome::getDirs('components'); $components_dirs = array_reverse($components_dirs); foreach ($components_dirs as $dir) { if (!file_exists($dir)) { continue; } $components = scandir($dir); foreach ($components as $file) { if ($file[0] == '.') { continue; } if (substr($file, -4) != '.php') { continue; } $componentName = substr($file, 0, -strlen('Component.php')); $components_list['{http://github.com/mermetbt/Biome/}' . strtolower($componentName)] = $componentName . 'Component'; } } $reader->elementMap = $components_list; /** * Parsing XML template */ $reader->xml($xml_contents); $tree = $reader->parse(); return $tree; }
public function check(Request $request) { // Check if Domain Name is available via API $domain = Domains::cleanURL(strtolower($request->input('domain'))); // International Domain Names// if (Domains::isDomainIntl($domain)) { InternetBS::init('X1A7S0D7X8N0U0U0I6S2', 'Toto197500cxz'); $status = InternetBS::api()->domainCheck($domain); if ($status) { $message = 'Domain Name is available'; } $message = 'Domain Name is not available'; return ['message' => $message, 'status' => $status]; } // Rwandan Domain Names if (Domains::isDomainRW($domain)) { $params = ['form_params' => ['search' => $domain], 'verify' => false]; $data = Domains::post('https://whois.ricta.org.rw/whois.jsp', $params); if (preg_match_all('/<tr><th>(?:[a-zA-Z\\s]+)<\\/th><td><a href=\'(.+)\'>(?:[a-zA-Z\\.]+)<\\/a>/im', $data, $matches)) { $status = false; $message = 'Domain Name is not available'; } else { $message = 'Domain Name is available'; $status = true; } return ['message' => $message, 'status' => $status]; } // Ugandan Domain Names if (Domains::isDomainUG($domain)) { $xml = (string) Domains::post('https://new.registry.co.ug:8006/api', ['body' => Domains::UG_Whois_Command($domain)]); $reader = new Reader(); $reader->xml($xml); $parsedXML = $reader->parse(); $data = $parsedXML['value']; $status = (int) $parsedXML['attributes']['status']; if ($status) { $status = false; $message = 'Domain Name is Not available'; } else { $message = 'Domain Name is available'; $status = true; } return ['message' => $message, 'status' => $status]; } }
/** * Execute the job. * * @return void */ public function handle() { // Avoid PHP timeouts when querying large clusters set_time_limit(0); //Create Sabre XML Reader Object $reader = new Reader(); //Create Guzzle REST client Object $client = new Client(['headers' => ['Accept' => 'application/xml', 'Content-Type' => 'application/xml']]); //Pick up the csv report created in the calling controller $csvFile = new CsvFile($this->csvFileName); //Write the csv headers $csvFile->writeRow(explode(',', $this->csv_headers)); //Loop the devices in $this->deviceList to get firmware info foreach ($this->deviceList as $device) { //Only get firmware if the device is registered if ($device['IsRegistered']) { \Log::debug('Running with', [$device]); try { //Query the phones web interface for the XML device info $response = $client->get('http://' . $device['IpAddress'] . '/DeviceInformationX', ['connect_timeout' => 2]); } catch (RequestException $e) { \Log::debug('Phone request exception', [$e]); continue; } $body = $response->getBody()->getContents(); \Log::debug('XML:', [$body]); //Consume the XML with Sabre XML Reader if ($reader->xml($body)) { //Parse the XML $deviceInfoX = $response = $reader->parse(); } else { \Log::debug('Error, there was no XML', []); } //Find the index for XML key holding the Firmware information $index = searchMultiDimArray($deviceInfoX['value'], 'name', '{}versionID'); //Place the firmware info into our $device array $device['Firmware'] = $deviceInfoX['value'][$index]['value']; } //Write the firmware info to csv $csvFile->writeRow($device); } }
/** * @expectedException \Sabre\Xml\LibXMLException */ function testKeyValueLoop() { /** * This bug is a weird one, because it triggers an infinite loop, but * only if the XML document is a certain size (in bytes). Removing one * or two characters from the xml body here cause the infinite loop to * *not* get triggered, so to properly test this bug (Issue #94), don't * change the XML body. */ $invalid_xml = ' <foo ft="PRNTING" Ppt="YES" AutoClose="YES" SkipUnverified="NO" Test="NO"> <Package ID="1"> <MailClass>NONE</MailClass> <PackageType>ENVELOPE</PackageType> <WeightOz>1</WeightOz> <FleetType>DC</FleetType> <Package ID="2"> <MailClass>NONE</MailClass> <PackageType>ENVELOPE</PackageType> <WeightOz>1</WeightOz> <FleetType>DC/FleetType> </Package> </foo>'; $reader = new Reader(); $reader->xml($invalid_xml); $reader->elementMap = ['{}Package' => function ($reader) { $recipient = []; // Borrowing a parser from the KeyValue class. $keyValue = keyValue($reader); if (isset($keyValue['{}WeightOz'])) { $recipient['referenceId'] = $keyValue['{}WeightOz']; } return $recipient; }]; $reader->parse(); }
/** * Sets the input data. * * @param resource|string $input * * @return void */ function setInput($input) { if (is_resource($input)) { $input = stream_get_contents($input); } if (is_string($input)) { $reader = new SabreXml\Reader(); $reader->elementMap['{' . self::XCAL_NAMESPACE . '}period'] = 'Sabre\\VObject\\Parser\\XML\\Element\\KeyValue'; $reader->elementMap['{' . self::XCAL_NAMESPACE . '}recur'] = 'Sabre\\VObject\\Parser\\XML\\Element\\KeyValue'; $reader->xml($input); $input = $reader->parse(); } $this->input = $input; }
/** * Get the error message from the error xml. * * @return string */ public function getError() { $reader = new Reader(); $reader->xml($this->response->getBody()->getContents()); return ''; }
/** * Convert tool output into PHP Hound array output. * @return void */ protected function processResults() { $content = $this->getOutputContent(); if (empty($content)) { return; } $xml = new Reader(); $xml->xml($content); $this->addIssuesFromXml($xml); }
/** * I discovered that when there's no whitespace between elements, elements * can get skipped. */ function testElementSkipProblem() { $input = <<<BLA <?xml version="1.0" encoding="utf-8"?> <root xmlns="http://sabredav.org/ns"> <elem3>val3</elem3><elem4>val4</elem4><elem5>val5</elem5></root> BLA; $reader = new Reader(); $reader->elementMap = ['{http://sabredav.org/ns}root' => 'Sabre\\Xml\\Element\\KeyValue']; $reader->xml($input); $output = $reader->parse(); $this->assertEquals(['name' => '{http://sabredav.org/ns}root', 'value' => ['{http://sabredav.org/ns}elem3' => 'val3', '{http://sabredav.org/ns}elem4' => 'val4', '{http://sabredav.org/ns}elem5' => 'val5'], 'attributes' => []], $output); }
/** * Parse the curriculum definition file. * * By passing the official curriculum definition file (XML), this method * will parse it and return a curriculum definition it can understand and * treat. It mainly needs a "dictionary" of term types. * * @param string $curriculumXml * The curriculum definition file, in XML. * @param string $variant * (optional) The variant of the curriculum to parse. Defaults to 'V_EF'. * * @return array * An object with 2 properties: * - curriculum: A parsed and prepared curriculum tree. It uses * Educa\DSB\Client\Curriculum\Term\LP21Term elements to define * the curriculum tree. * - dictionary: A dictionary of term identifiers, with name and type * information for each one of them. * * @see \Educa\DSB\Client\Curriculum\LP21Curriculum::setCurriculumDictionary() */ public static function parseCurriculumXml($curriculumXml, $variant = 'V_EF') { $reader = new Reader(); // Prepare custom handlers for reading an XML node. See the Sabre\Xml // documentation for more information. $baseHandler = function ($reader) use($variant) { $node = new \stdClass(); // Fetch the attributes. We want the UUID attribute. $attributes = $reader->parseAttributes(); $node->uuid = trim($attributes['uuid']); // We derive the type from the node name. $node->type = strtolower(str_replace('{}', '', trim($reader->getClark()))); // Give a default description. $node->description = (object) array('de' => ''); // Fetch the descendants. $children = $reader->parseInnerTree(); if (!empty($children)) { $node->children = array(); foreach ($children as $child) { // Look for child types that are relevant for us. Some must // be parsed as child types of their own, others should be // treated as being part of the current node. if (in_array($child['name'], array('{}fach', '{}kompetenzbereich', '{}handlungs-themenaspekt', '{}kompetenz', '{}kompetenzstufe'))) { $node->children[] = $child; } elseif ($child['name'] == '{}bezeichnung') { $node->description = (object) array_reduce($child['value'], function ($carry, $item) { $langcode = strtolower(str_replace('{}', '', $item['name'])); $carry[$langcode] = $item['value']; return $carry; }, array()); } elseif ($child['name'] == '{}kantone') { $node->cantons = array_map('trim', explode(',', $child['value'])); } } } if (!empty($node->cantons) && !in_array($variant, $node->cantons)) { return null; } return $node; }; $kompetenzstufeHandler = function ($reader) use($variant) { $nodes = array(); $cycle = $url = $version = $code = null; // Fetch the descendants. $children = $reader->parseInnerTree(); if (!empty($children)) { foreach ($children as $child) { if ($child['name'] == '{}absaetze') { $nodes = $child['value']; } elseif ($child['name'] == '{}zyklus') { $cycle = trim($child['value']); } elseif ($child['name'] == '{}lehrplanversion') { $version = trim($child['value']); } elseif ($child['name'] == '{}kanton' && $child['attributes']['id'] == $variant) { foreach ($child['value'] as $grandChild) { if ($grandChild['name'] == '{}code') { $code = trim($grandChild['value']); } elseif ($grandChild['name'] == '{}url') { $url = trim($grandChild['value']); } } } } } // Map all the Kompetenzstufe properties to the child Absaetzen. return array_map(function ($node) use($cycle, $url, $version, $code) { if (isset($cycle)) { $node->cycle = $cycle; } if (isset($url)) { $node->url = $url; } if (isset($version)) { $node->version = $version; } if (isset($code)) { $node->code = $code; } return $node; }, $nodes); }; $absaetzeHandler = function ($reader) { $nodes = array(); // Fetch the descendants. $children = $reader->parseInnerTree(); if (!empty($children)) { foreach ($children as $child) { if ($child['name'] == '{}bezeichnung') { $node = new \stdClass(); // We treat it as a "Kompetenzstufe". $node->type = 'kompetenzstufe'; $node->description = (object) array_reduce($child['value'], function ($carry, $item) { $langcode = strtolower(str_replace('{}', '', $item['name'])); $carry[$langcode] = $item['value']; return $carry; }, array()); // The UUID is on the child Bezeichnung element, not our // own node. $node->uuid = $child['attributes']['uuid']; $nodes[] = $node; } } } return $nodes; }; // Register our handler for the following node types. All others will be // treated with the default one provided by Sabre\Xml, but we don't // really care. $reader->elementMap = ['{}fachbereich' => $baseHandler, '{}fach' => $baseHandler, '{}kompetenzbereich' => $baseHandler, '{}handlungs-themenaspekt' => $baseHandler, '{}kompetenz' => $baseHandler, '{}kompetenzstufe' => $kompetenzstufeHandler, '{}absaetze' => $absaetzeHandler]; // Parse the data. $reader->xml($curriculumXml); $data = $reader->parse(); // Prepare the dictionary. $dictionary = array(); // Prepare our root element. $root = new LP21Term('root', 'root'); // Now, recursively parse the tree, transforming it into a tree of // LP21Term instances. $recurse = function ($tree, $parent) use(&$recurse, &$dictionary) { foreach ($tree as $item) { // Fetch our nodes. $nodes = $item['value']; if (!is_array($nodes)) { $nodes = [$nodes]; } // Double check the format. Is this one of our nodes? foreach ($nodes as $node) { if (isset($node->uuid) && isset($node->type) && isset($node->description)) { $term = new LP21Term($node->type, $node->uuid, $node->description); $parent->addChild($term); // Add it to our dictionary. $dictionary[$node->uuid] = (object) array('name' => $node->description, 'type' => $node->type); // Do we have an objective code? if (!empty($node->code)) { $term->setCode($node->code); $dictionary[$node->uuid]->code = $node->code; } // Do we have any cantons information? if (!empty($node->cantons)) { $term->setCantons($node->cantons); $dictionary[$node->uuid]->cantons = $node->cantons; } // Do we have curriculum version information? if (!empty($node->version)) { $term->setVersion($node->version); $dictionary[$node->uuid]->version = $node->version; } // Do we have URL information? if (!empty($node->url)) { $term->setUrl($node->url); $dictionary[$node->uuid]->url = $node->url; } // Do we have cycle information? if (!empty($node->cycle)) { $cycles = str_split($node->cycle); $term->setCycles($cycles); $dictionary[$node->uuid]->cycles = $cycles; } if (!empty($node->children)) { $recurse($node->children, $term); } } } } }; $recurse($data['value'], $root); // Return the parsed data. return (object) array('curriculum' => $root, 'dictionary' => $dictionary); }
public function search(Request $request) { $domain = strtolower($request->input('domain')); $response = []; $response['domain'] = $domain; $response['country'] = null; $response['status'] = false; $response['domain_details'] = Domains::getDomainDetails($domain); if (Domains::isDomainUG($domain)) { $response['country'] = "UGANDA"; $xml = (string) Domains::post('https://new.registry.co.ug:8006/api', ['body' => Domains::UG_Whois_Command($domain)]); $reader = new Reader(); $reader->xml($xml); $parsedXML = $reader->parse(); $data = $parsedXML['value']; $status = (int) $parsedXML['attributes']['status']; if ($status) { $response['status'] = true; Session::flash('errordomain', $domain . ' domain is not available'); $response['data']['domain'] = $data[1]['attributes']; $response['data']['registrant'] = $data[2]['value'][0]['attributes']; $response['data']['admin'] = $data[2]['value'][1]['attributes']; $response['data']['billing'] = $data[2]['value'][2]['attributes']; $response['data']['tech'] = $data[2]['value'][3]['attributes']; $response['data']['nameservers'] = ["ns1" => $data[3]['value'][0]['value'], "ns2" => $data[3]['value'][1]['value'], "ns3" => $data[3]['value'][2]['value'], "ns4" => $data[3]['value'][3]['value']]; } else { Session::flash('successdomain', $domain . ' domain is available'); } } elseif (Domains::isDomainRW($domain)) { $response['country'] = "RWANDA"; $response['status'] = true; $response['data'] = []; $domain = Domains::cleanURL($domain); $params = ['form_params' => ['search' => $domain], 'verify' => false]; $data = Domains::post('https://whois.ricta.org.rw/whois.jsp', $params); if (preg_match_all('/<tr><th>(?:[a-zA-Z\\s]+)<\\/th><td><a href=\'(.+)\'>(?:[a-zA-Z\\.]+)<\\/a>/im', $data, $matches)) { Session::flash('errordomain', $domain . ' domain is not available'); } else { Session::flash('successdomain', $domain . ' domain is available'); } } else { $domain = Domains::cleanURL($domain); if (!empty($domain)) { $response['country'] = "INTERNATIONAL"; try { InternetBS::init('X1A7S0D7X8N0U0U0I6S2', 'Toto197500cxz'); if (InternetBS::api()->domainCheck($domain)) { Session::flash('successdomain', $domain . ' domain is available'); } else { Session::flash('errordomain', $domain . ' domain is not available'); } } catch (Exception $e) { Session::flash('errordomain', ' Incorrect input domain. please type correctly'); } } else { Session::flash('errordomain', ' Incorrect input domain. please type correctly'); } } return view('domain.search', compact('response', $response)); }
function parse($xml) { $reader = new Reader(); $reader->elementMap['{DAV:}principal'] = 'Sabre\\DAVACL\\Xml\\Property\\Principal'; $reader->xml($xml); $result = $reader->parse(); return $result['value']; }