public function __construct($input) { $sxe = new \SimpleXMLElement($input); $this->evec_method = (string) $sxe->attributes()->method; $this->evec_version = (string) $sxe->attributes()->version; foreach ($sxe->marketstat->type as $t) { $id = (int) $t->attributes()->id; $this->types[$id] = new \stdClass(); $this->types[$id]->buy = new \stdClass(); $this->types[$id]->buy->volume = (double) $t->buy->volume; $this->types[$id]->buy->avg = (double) $t->buy->avg; $this->types[$id]->buy->max = (double) $t->buy->max; $this->types[$id]->buy->min = (double) $t->buy->min; $this->types[$id]->buy->stddev = (double) $t->buy->stddev; $this->types[$id]->buy->median = (double) $t->buy->median; $this->types[$id]->buy->percentile = (double) $t->buy->percentile; $this->types[$id]->sell = new \stdClass(); $this->types[$id]->sell->volume = (double) $t->sell->volume; $this->types[$id]->sell->avg = (double) $t->sell->avg; $this->types[$id]->sell->max = (double) $t->sell->max; $this->types[$id]->sell->min = (double) $t->sell->min; $this->types[$id]->sell->stddev = (double) $t->sell->stddev; $this->types[$id]->sell->median = (double) $t->sell->median; $this->types[$id]->sell->percentile = (double) $t->sell->percentile; $this->types[$id]->all = new \stdClass(); $this->types[$id]->all->volume = (double) $t->all->volume; $this->types[$id]->all->avg = (double) $t->all->avg; $this->types[$id]->all->max = (double) $t->all->max; $this->types[$id]->all->min = (double) $t->all->min; $this->types[$id]->all->stddev = (double) $t->all->stddev; $this->types[$id]->all->median = (double) $t->all->median; $this->types[$id]->all->percentile = (double) $t->all->percentile; } }
/** * Unserialize SimpleXMLElement * * @param \SimpleXMLElement $element Element to unserialize * @param string $classHint Hint to which class unserialize * * @return mixed unserialized object */ protected function unserializeXml(\SimpleXMLElement $element, $classHint = null) { if ($this->configValue("extractClassFrom", "tagName") == "tagName") { $elementClassHint = $element->getName(); } else { $xsiAttrs = $element->attributes("http://www.w3.org/2001/XMLSchema-instance"); if (!isset($xsiAttrs["type"])) { throw new \Exception("Element {$element->getName()} has no {http://www.w3.org/2001/XMLSchema-instance}type attribute"); } $elementClassHint = $xsiAttrs["type"]; } $mapperClass = $this->configValue("mapperClasses", []); if (isset($mapperClass[$elementClassHint])) { $className = $mapperClass[$elementClassHint]; } else { $className = $classHint ? $classHint : rtrim($this->configValue("classesNamespace", ""), '\\') . '\\' . $elementClassHint; } if (!class_exists($className, true)) { throw new ClassNotFoundException("Class '{$className}' not found"); } $classInstance = new $className(); $this->checkNodes($element->attributes(), $className, $classInstance); $this->checkNodes($element->children(), $className, $classInstance); return $classInstance; }
public static function createFromResponse(\SimpleXMLElement $response) { $chart = new Chart(); $chart->setFrom((int) $response->attributes()->from); $chart->setTo((int) $response->attributes()->to); return $chart; }
/** * Parses a simple xml element and returns an executable string for a layout node * * @param SimpleXMLElement $element * @param \EcomDev_LayoutCompiler_Contract_CompilerInterface $compiler * @param null|string $blockIdentifier * @param string[] $parentIdentifiers * @return string|string[] */ public function parse(SimpleXMLElement $element, \EcomDev_LayoutCompiler_Contract_CompilerInterface $compiler, $blockIdentifier = null, $parentIdentifiers = array()) { if (empty($element->attributes()->name)) { return false; } return $this->getClassStatement(array((string) $element->attributes()->name)); }
private function xml2js(SimpleXMLElement $xmlnode, $isRoot = true) { $jsnode = array(); if (!$isRoot) { if (count($xmlnode->attributes()) > 0) { $jsnode["@attribute"] = array(); foreach ($xmlnode->attributes() as $key => $value) { $jsnode["@attribute"][$key] = (string) $value; } } $textcontent = trim((string) $xmlnode); if (count($textcontent) > 0) { $jsnode['_'] = $textcontent; } foreach ($xmlnode->children() as $childxmlnode) { $childname = $childxmlnode->getName(); if (!array_key_exists($childname, $jsnode)) { $jsnode[$childname] = array(); } array_push($jsnode[$childname], $this->xml2js($childxmlnode, false)); } return $jsnode; } else { $nodename = $xmlnode->getName(); $jsnode[$nodename] = array(); array_push($jsnode[$nodename], $this->xml2js($xmlnode, false)); return json_encode($jsnode, JSON_PRETTY_PRINT); } }
public function recreate_img_tag($tag) { // Supress SimpleXML errors libxml_use_internal_errors(TRUE); try { $x = new SimpleXMLElement($tag); // We only want to rebuild img tags if ($x->getName() == 'img') { // Get the attributes I'll use in the new tag $alt = (string) $x->attributes()->alt; $src = (string) $x->attributes()->src; $classes = (string) $x->attributes()->class; $class_segs = explode(' ', $classes); // All images have a source $img = '<img src="' . $src . '"'; // If alt not empty, add it if (!empty($alt)) { $img .= ' alt="' . $alt . '"'; } // Only alignment classes are allowed $allowed_classes = array('alignleft', 'alignright', 'alignnone', 'aligncenter'); if (in_array($class_segs[0], $allowed_classes)) { $img .= ' class="' . $class_segs[0] . '"'; } // Finish up the img tag $img .= ' />'; return $img; } } catch (Exception $e) { } // Tag not an img, so just return it untouched return $tag; }
/** * Custom loadLanguage method * * @param string $path The path where to find language files. * * @return void * * @since 3.1 */ public function loadLanguage($path = null) { $source = $this->parent->getPath('source'); if (!$source) { $this->parent->setPath('source', JPATH_PLUGINS . '/' . $this->parent->extension->folder . '/' . $this->parent->extension->element); } $this->manifest = $this->parent->getManifest(); $element = $this->manifest->files; if ($element) { $group = strtolower((string) $this->manifest->attributes()->group); $name = ''; if (count($element->children())) { foreach ($element->children() as $file) { if ((string) $file->attributes()->plugin) { $name = strtolower((string) $file->attributes()->plugin); break; } } } if ($name) { $extension = "plg_{$group}_{$name}"; $lang = JFactory::getLanguage(); $source = $path ? $path : JPATH_PLUGINS . "/{$group}/{$name}"; $folder = (string) $element->attributes()->folder; if ($folder && file_exists("{$path}/{$folder}")) { $source = "{$path}/{$folder}"; } $lang->load($extension . '.sys', $source, null, false, true) || $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, true); } } }
/** * Add item index and level to class attribute * * @param SimpleXMLElement $node The node to add the index and level to * @param array $args Callback arguments */ public static function index(SimpleXMLElement $node, $args) { if ($node->getName() == 'ul') { // set up level $level = $args['level'] / 2 + 1; if ($level > 1) { $node->addAttribute('class', 'uk-nav uk-nav-navbar'); } else { $node->addAttribute('class', 'uk-navbar-nav'); } } if ($node->getName() == 'li') { $css = ''; // parent if (isset($node->div)) { $css .= ' uk-parent'; $node->addAttribute('data-uk-dropdown', ''); } // add li css classes $node->attributes()->class = trim($node->attributes()->class . $css); // add a/span css classes $children = $node->children(); if ($firstChild = $children[0]) { $firstChild->addAttribute('class', trim($firstChild->attributes()->class . $css)); } } unset($node->attributes()->icon); }
/** * Returns the response status (OK = success, ERROR = error, null = invalid responses) * * @return string NULL */ public function getStatus() { if ($this->xml && $this->xml instanceof \SimpleXMLElement) { return (string) $this->xml->attributes()->Status; } return null; }
/** * Parses a simple xml element and returns an executable string for a layout node * * @param SimpleXMLElement $element * @param \EcomDev_LayoutCompiler_Contract_CompilerInterface $compiler * @param null|string $blockIdentifier * @param string[] $parentIdentifiers * @return string|string[] */ public function parse(SimpleXMLElement $element, CompilerInterface $compiler, $blockIdentifier = null, $parentIdentifiers = array()) { if ($blockIdentifier !== null && !in_array($blockIdentifier, $parentIdentifiers, true)) { $parentIdentifiers[] = $blockIdentifier; } $blockIdentifier = isset($element->attributes()->{$this->idAttribute}) ? (string) $element->attributes()->{$this->idAttribute} : null; return $compiler->parseElements($element, $blockIdentifier, $parentIdentifiers); }
/** * Get the bootstrap PHPUnit configuration attribute * * @return string The bootstrap attribute or empty string if not set */ public function getBootstrap() { if ($this->xml) { return (string) $this->xml->attributes()->bootstrap; } else { return ''; } }
protected function getAttributes(\SimpleXMLElement $node) { if (count($node->attributes()) > 0) { $attr = (array) $node->attributes(); return $attr['@attributes']; } return array(); }
/** * @param \SimpleXMLElement $node */ public function __construct(\SimpleXMLElement $node) { $this->node = $node; $attrs = $this->node->attributes(); $this->name = (string) $attrs['name']; $this->type = (string) $attrs['type']; $this->relation = (string) $attrs['relation']; }
public function __construct(\SimpleXMLElement $object) { $this->setURL((string) $object->attributes()->url); $this->setData((string) $object); $this->setFileName((string) $object->attributes()->file); $this->setOrdering((string) $object->attributes()->id); $this->setModified((string) $object->attributes()->modTime); $this->setFiletype((string) $object->attributes()->format); }
/** * Convert the raw XML into an object * * @param \SimpleXMLElement $xml * @return Mail */ public static function createFromXML(\SimpleXMLElement $xml) { $mail = new Mail(); if (isset($xml->attributes()['type'])) { $mail->setType((string) $xml->attributes()['type']); } $mail->setValue((string) $xml); return $mail; }
protected function guessClassName($file, \SimpleXMLElement $elem, \ReflectionClass $class = null) { if ($class === null) { return (string) $elem->attributes()->class; } if ($class->name !== (string) $elem->attributes()->class) { throw new \RuntimeException(sprintf('Expected metadata for class %s to be defined in %s.', $class->name, $file)); } return $class->name; }
/** * Constructs config * * @param \SimpleXMLElement $node The simple xml element used to build config */ public function __construct(\SimpleXMLElement $node) { // prepare properties $this->name = (string) $node->attributes()->name; $this->type = (string) $node->attributes()->type; if (isset($node->attributes()->channel)) { $this->channel = (string) $node->attributes()->channel; } // prepare handlers $this->servers = $this->prepareServers($node); }
/** * Convert the raw XML into an object * * @param \SimpleXMLElement $xml * @return Activity */ public static function createFromXML(\SimpleXMLElement $xml) { $activity = new Activity(); if (isset($xml->attributes()['count'])) { $activity->setCount((int) $xml->attributes()['count']); } if (isset($xml->attributes()['type'])) { $activity->setType((string) $xml->attributes()['type']); } return $activity; }
private function doPrettyPrintXML(SimpleXMLElement $han, $prefix = "") { if (count($han->children()) < 1) { return $prefix . "<" . $han->getName() . $this->doWarpAttributes($han->attributes()) . ">" . $han . "</" . $han->getName() . "><br />"; } $ret = $prefix . "<" . $han->getName() . $this->doWarpAttributes($han->attributes()) . "><br />"; foreach ($han->children() as $key => $child) { $ret .= $this->doPrettyPrintXML($child, $prefix . " "); } $ret .= $prefix . "</" . $han->getName() . "><br />"; return $ret; }
/** * Insert Show * @param SimpleXMLElement $Equipment */ private function insertShoe(SimpleXMLElement &$Equipment) { if ((string) $Equipment->Name == '') { return; } $ExistingShoe = DB::getInstance()->query('SELECT id FROM `' . PREFIX . 'shoe` WHERE name=' . DB::getInstance()->escape($Equipment->Name) . ' AND accountid = ' . SessionAccountHandler::getId() . ' LIMIT 1')->fetch(); if (isset($ExistingShoe['id'])) { self::$NewEquipment[(string) $Equipment->attributes()->id] = $ExistingShoe['id']; } else { self::$NewEquipment[(string) $Equipment->attributes()->id] = DB::getInstance()->insert('shoe', array('name', 'since', 'additionalKm', 'inuse'), array((string) $Equipment->Name, isset($Equipment->PurchaseInfo) && isset($Equipment->PurchaseInfo['date']) ? (string) $Equipment->PurchaseInfo['date'] : '', isset($Equipment->Distance) && isset($Equipment->Distance['initialDistance']) ? $this->distanceFromUnit($Equipment->Distance['initialDistance'], $Equipment->Distance['unit']) : 0, isset($Equipment->Name['retired']) && (string) $Equipment->Name['retired'] == 'true' ? 0 : 1)); } }
/** * @param \SimpleXMLElement $xml * @param string $instance */ protected function postprocess($xml, $instance) { $xml->addAttribute('instance', $instance); /** @noinspection PhpUndefinedFieldInspection */ if ($xml->attributes()->prefix) { /** @noinspection PhpUndefinedFieldInspection */ $prefix = $xml->attributes()->prefix; } else { $prefix = '/' . $instance; } $this->recursiveProcessor($xml, $prefix, 'menu', $instance); }
public function getThumbURL(SimpleXMLElement &$node) { $thumb = (string) $node->attributes()->thumb; $thumb = $this->base_url . '/photo/:/transcode?width=' . THUMB_WIDTH . '&height=' . THUMB_HEIGHT . '&url=' . urlencode($this->base_url . $thumb); hd_print(__METHOD__ . ':' . $thumb); if ($node->attributes()->thumb && $node->attributes()->ratingKey) { $cacheKey = (string) $node->attributes()->ratingKey . '.jpg'; EmplexerArchive::getInstance()->setFileToArchive($cacheKey, $thumb); return EmplexerArchive::getInstance()->getFileFromArchive($cacheKey, $thumb); } return $thumb; }
/** * Insert Show * @param SimpleXMLElement $Equipment */ private function insertShoe(SimpleXMLElement &$Equipment) { if ((string) $Equipment->Name == '') { return; } $ExistingEquipment = DB::getInstance()->query('SELECT id FROM `' . PREFIX . 'equipment` WHERE name=' . DB::getInstance()->escape($Equipment->Name) . ' AND accountid = ' . SessionAccountHandler::getId() . ' LIMIT 1')->fetch(); if (isset($ExistingEquipment['id'])) { self::$NewEquipment[(string) $Equipment->attributes()->id] = $ExistingEquipment['id']; } else { $purchaseDate = isset($Equipment->PurchaseInfo) && isset($Equipment->PurchaseInfo['date']) ? (string) $Equipment->PurchaseInfo['date'] : ''; self::$NewEquipment[(string) $Equipment->attributes()->id] = DB::getInstance()->insert('equipment', array('name', 'typeid', 'notes', 'additional_km', 'date_start', 'date_end'), array((string) $Equipment->Name, $this->equipmentTypeIdForNewStuff(), '', isset($Equipment->Distance) && isset($Equipment->Distance['initialDistance']) ? $this->distanceFromUnit($Equipment->Distance['initialDistance'], $Equipment->Distance['unit']) : 0, strtotime($purchaseDate) ? date('Y-m-d', strtotime($purchaseDate)) : null, isset($Equipment->Name['retired']) && (string) $Equipment->Name['retired'] == 'true' ? date('Y-m-d') : null)); } }
/** * To ensure SimpleXML-based queries work (for removing dependencies on * PHPXML)... */ public function testSimpleXML() { $myFile = dirname(__FILE__) . '/files/siteConfig.xml'; $this->assertFileExists($myFile); $x = new SimpleXMLElement(file_get_contents($myFile)); $this->assertEquals('2008-12-18 10:21:00', $x->attributes()->created); $this->assertEquals('', $x->attributes()->updated); $this->assertTrue(isset($x->website)); $this->assertEquals('sanitizeDirs', $x->website->attributes()->fix); $siteRoot = $x->website->SITE_ROOT; $this->assertTrue(is_object($siteRoot)); $this->assertEquals('{_DIRNAMEOFFILE_}/..', "{$siteRoot}"); //basically, the object is cast into a string which is the value of the tag. }
/** * Returns an associativearray from a SimpleXMLElement. * * @param SimpleXMLElement $xmlObject Convert a SimpleXMLElement into an array * @return array */ protected function _toArray(SimpleXMLElement $xmlObject) { $config = array(); // Search for parent node values if (count($xmlObject->attributes()) > 0) { foreach ($xmlObject->attributes() as $key => $value) { $value = (string) $value; if (array_key_exists($key, $config)) { if (!is_array($config[$key])) { $config[$key] = array($config[$key]); } $config[$key][] = $value; } else { $config[$key] = $value; } } } // Search for children if (count($xmlObject->children()) > 0) { foreach ($xmlObject->children() as $key => $value) { if (count($value->children()) > 0) { $value = $this->_toArray($value); } else { if (count($value->attributes()) > 0) { $attributes = $value->attributes(); if (isset($attributes['value'])) { $value = (string) $attributes['value']; } else { $value = $this->_toArray($value); } } else { $value = (string) $value; } } if (array_key_exists($key, $config)) { if (!is_array($config[$key]) || !array_key_exists(0, $config[$key])) { $config[$key] = array($config[$key]); } $config[$key][] = $value; } else { if (self::ARRAY_NON_ASSOC_ITEM_NAME != $key) { $config[$key] = $value; } else { $config[] = $value; } } } } return $config; }
public function loadFromXML(\SimpleXMLElement $message) { $this->id = (string) $message->attributes()["id"]; $this->priority = (string) $message->attributes()["priority"]; $this->created = (string) $message->createddate; $this->title = (string) $message->title; $this->location = (string) $message->exactlocation; $this->description = (string) $message->description; $this->latitude = (string) $message->latitude; $this->longitude = (string) $message->longitude; $this->category = (string) $message->category; $this->subcategory = (string) $message->subcategory; return $this; }
public function __construct(\SimpleXMLElement $address, $municipality = false) { // set display_address $this->setDisplayAddress($address->attributes()->display); // set site $this->setSite((string) $address->site); // set subNumber $this->setSubNumber((string) $address->subNumber); // set lotNumber $this->setLotNumber((string) $address->lotNumber); // set streetNumber $this->setStreetNumber((string) $address->streetNumber); // set street $this->setStreet((string) $address->street); // set suburb $this->setSuburb((string) $address->suburb); // set municipality $this->setMunicipality($municipality); // set state $this->setState((string) $address->state); // set region $this->setRegion((string) $address->region); // set postcode $this->setPostcode((string) $address->postcode); // set country $this->setCountry((string) $address->country); }
/** * Parses the affix configuration. * * @param \SimpleXMLElement $date * @param array $additional Array with key form and value text or numeric */ public function __construct(\SimpleXMLElement $date, array $additional) { $this->name = ''; $this->delimiter = '–'; $this->formatting = new Formatting($date); $this->textCase = new TextCase($date); $this->affix = new Affix($date); foreach ($date->attributes() as $name => $value) { switch ($name) { case 'name': $this->name = (string) $value; switch ($this->name) { case 'day': $this->render = Factory::day($additional['form'], $date); break; case 'month': $this->render = Factory::month($additional['form'], $date); break; case 'year': $this->render = Factory::year($additional['form'], $date); break; } break; case 'range-delimiter': $this->delimiter = (string) $value; break; } } }
public function __construct(\SimpleXMLElement $action_xml) { if ($action_xml == NULL) { throw new e\EmptyValueException("The xml cannot be empty."); } if (self::DEBUG && self::DUMP) { DebugUtility::dump(u\XMLUtility::replaceBrackets($action_xml->asXML())); } $this->action_xml = $action_xml; $action_attr = $action_xml->attributes(); $this->identifier = $action_attr->identifier->__toString(); if ($action_attr->label) { $this->label = $action_attr->label->__toString(); } if ($action_attr->move) { $this->move = $action_attr->move->__toString(); } else { $this->move = ""; } if ($action_attr->{"next-id"}) { $this->next_id = $action_attr->{"next-id"}->__toString(); } else { $this->next_id = ""; } $this->triggers = array(); if ($this->action_xml->trigger) { foreach ($this->action_xml->trigger as $trigger) { $this->triggers[] = new TriggerDefinition($trigger); } } }
/** * appendToParent * * @param SimpleXMLElement $parent * @param SimpleXMLElement $child * * @return void */ public static function appendToParent(\SimpleXMLElement $parent, \SimpleXMLElement $child) { $methodCall = false; $attributes = array(); foreach ($child->attributes() as $key => $value) { $value = (string) $value; if ($key === 'method-call' && method_exists($child, $value)) { $methodCall = $value; continue; } $attributes[$key] = $value; } if (false !== $methodCall && !$child->count()) { $childNode = $parent->addChild($child->getName()); $childNode->{$methodCall}($child->__toString()); } else { $childNode = $parent->addChild($child->getName(), !$child->count() ? (string) $child : null); } foreach ($attributes as $key => $value) { $childNode->addAttribute($key, $value); } if ($child->count()) { foreach ($child->children() as $_child) { static::appendToParent($childNode, $_child); } } }