public function getXPath($entry) { $fieldManager = new FieldManager(Symphony::Engine()); $entry_xml = new XMLElement('entry'); $section_id = $entry->get('section_id'); $data = $entry->getData(); $fields = array(); $entry_xml->setAttribute('id', $entry->get('id')); $associated = $entry->fetchAllAssociatedEntryCounts(); if (is_array($associated) and !empty($associated)) { foreach ($associated as $section => $count) { $handle = Symphony::Database()->fetchVar('handle', 0, "\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\ts.handle\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t`tbl_sections` AS s\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\ts.id = '{$section}'\n\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t"); $entry_xml->setAttribute($handle, (string) $count); } } // Add fields: foreach ($data as $field_id => $values) { if (empty($field_id)) { continue; } $field = $fieldManager->fetch($field_id); $field->appendFormattedElement($entry_xml, $values, false, null); } $xml = new XMLElement('data'); $xml->appendChild($entry_xml); $dom = new DOMDocument(); $dom->strictErrorChecking = false; $dom->loadXML($xml->generate(true)); $xpath = new DOMXPath($dom); if (version_compare(phpversion(), '5.3', '>=')) { $xpath->registerPhpFunctions(); } return $xpath; }
/** * Get array of class names * * @param array $files * @return array */ public function collectEntities(array $files) { $output = []; foreach ($files as $file) { $dom = new \DOMDocument(); $dom->load($file); $xpath = new \DOMXPath($dom); $xpath->registerNamespace("php", "http://php.net/xpath"); $xpath->registerPhpFunctions('preg_match'); $regex = '/^(.*)\\\\(.*)Proxy$/'; $query = "/config/preference[ php:functionString('preg_match', '{$regex}', @type) > 0]/@type | " . "//argument[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" . "//item[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" . "/config/virtualType[ php:functionString('preg_match', '{$regex}', @type) > 0]/@type"; /** @var \DOMNode $node */ foreach ($xpath->query($query) as $node) { $output[] = $node->nodeValue; } } $output = array_unique($output); return $this->_filterEntities($output); }
public function getXPath($entry, $XSLTfilename = NULL, $fetch_associated_counts = NULL) { $entry_xml = new XMLElement('entry'); $data = $entry->getData(); $fields = array(); $entry_xml->setAttribute('id', $entry->get('id')); //Add date created and edited values $date = new XMLElement('system-date'); $date->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->get('creation_date')), 'created')); $date->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->get('modification_date')), 'modified')); $entry_xml->appendChild($date); //Reflect Workspace and Siteroot params $workspace = new XMLElement('workspace', URL . '/workspace'); $root = new XMLElement('root', URL); // Add associated entry counts if ($fetch_associated_counts == 'yes') { $associated = $entry->fetchAllAssociatedEntryCounts(); if (is_array($associated) and !empty($associated)) { foreach ($associated as $section_id => $count) { $section = SectionManager::fetch($section_id); if ($section instanceof Section === false) { continue; } $entry_xml->setAttribute($section->get('handle'), (string) $count); } } } // Add fields: foreach ($data as $field_id => $values) { if (empty($field_id)) { continue; } $field = FieldManager::fetch($field_id); $field->appendFormattedElement($entry_xml, $values, false, null, $entry->get('id')); } $xml = new XMLElement('data'); $xml->appendChild($entry_xml); $xml->appendChild($workspace); $xml->appendChild($root); // Build some context $section = SectionManager::fetch($entry->get('section_id')); $params = new XMLElement('params'); $params->appendChild(new XMLElement('section-handle', $section->get('handle'))); $params->appendChild(new XMLElement('entry-id', $entry->get('id'))); $xml->prependChild($params); $dom = new DOMDocument(); $dom->strictErrorChecking = false; $dom->loadXML($xml->generate(true)); if (!empty($XSLTfilename)) { $XSLTfilename = UTILITIES . '/' . preg_replace(array('%/+%', '%(^|/)../%'), '/', $XSLTfilename); if (file_exists($XSLTfilename)) { $XSLProc = new XsltProcessor(); $xslt = new DomDocument(); $xslt->load($XSLTfilename); $XSLProc->importStyleSheet($xslt); // Set some context $XSLProc->setParameter('', array('section-handle' => $section->get('handle'), 'entry-id' => $entry->get('id'))); $temp = $XSLProc->transformToDoc($dom); if ($temp instanceof DOMDocument) { $dom = $temp; } } } $xpath = new DOMXPath($dom); if (version_compare(phpversion(), '5.3', '>=')) { $xpath->registerPhpFunctions(); } return $xpath; }
/** * Register PHP functions as XPath functions * * @link http://php.net/manual/en/domxpath.registerphpfunctions.php * * @param mixed $restrict [optional] Use this parameter to only allow certain functions to be called from XPath. * This parameter can be either a string (a function name) or an array of function names. * * @return void */ public function registerPhpFunctions($restrict = null) { $this->xpath->registerPhpFunctions($restrict); }