Skip to content

Commit

Permalink
New JSON to model mapper has been introduced
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Aug 2, 2018
1 parent 71b69ab commit e653e7b
Show file tree
Hide file tree
Showing 41 changed files with 483 additions and 392 deletions.
4 changes: 2 additions & 2 deletions src/Discovery/DiscoveryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Office365\PHP\Client\Runtime\Auth\IAuthenticationContext;
use Office365\PHP\Client\Runtime\ClientAction;
use Office365\PHP\Client\Runtime\ClientRuntimeContext;
use Office365\PHP\Client\Runtime\OData\JsonFormat;
use Office365\PHP\Client\Runtime\OData\JsonSerializerContext;
use Office365\PHP\Client\Runtime\OData\ODataMetadataLevel;
use Office365\PHP\Client\Runtime\Office365Version;
use Office365\PHP\Client\Runtime\ResourcePathEntity;
Expand All @@ -16,7 +16,7 @@ class DiscoveryClient extends ClientRuntimeContext
public function __construct(IAuthenticationContext $authContext, $version = Office365Version::V1)
{
$serviceRootUrl = "https://api.office.com/discovery/$version/";
parent::__construct($serviceRootUrl, $authContext,new JsonFormat(ODataMetadataLevel::Verbose),$version);
parent::__construct($serviceRootUrl, $authContext,new JsonSerializerContext(ODataMetadataLevel::NoMetadata),$version);
}


Expand Down
4 changes: 2 additions & 2 deletions src/GraphClient/GraphServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Office365\PHP\Client\Runtime\Auth\IAuthenticationContext;
use Office365\PHP\Client\Runtime\ClientAction;
use Office365\PHP\Client\Runtime\ClientRuntimeContext;
use Office365\PHP\Client\Runtime\OData\JsonFormat;
use Office365\PHP\Client\Runtime\OData\JsonSerializerContext;
use Office365\PHP\Client\Runtime\OData\ODataMetadataLevel;
use Office365\PHP\Client\Runtime\Office365Version;
use Office365\PHP\Client\Runtime\ResourcePathEntity;
Expand All @@ -17,7 +17,7 @@ class GraphServiceClient extends ClientRuntimeContext
public function __construct(IAuthenticationContext $authContext)
{
$serviceRootUrl = "https://graph.microsoft.com/" . Office365Version::V1 . "/";
parent::__construct($serviceRootUrl, $authContext,new JsonFormat(ODataMetadataLevel::Verbose));
parent::__construct($serviceRootUrl, $authContext,new JsonSerializerContext(ODataMetadataLevel::Verbose));
}


Expand Down
5 changes: 2 additions & 3 deletions src/OneDrive/OneDriveClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use Office365\PHP\Client\Runtime\Auth\IAuthenticationContext;
use Office365\PHP\Client\Runtime\ClientAction;
use Office365\PHP\Client\Runtime\ClientRuntimeContext;
use Office365\PHP\Client\Runtime\ContextWebInformation;
use Office365\PHP\Client\Runtime\OData\JsonFormat;
use Office365\PHP\Client\Runtime\OData\JsonSerializerContext;
use Office365\PHP\Client\Runtime\OData\ODataMetadataLevel;
use Office365\PHP\Client\Runtime\Office365Version;
use Office365\PHP\Client\Runtime\ResourcePathEntity;
Expand All @@ -18,7 +17,7 @@ class OneDriveClient extends ClientRuntimeContext
public function __construct($authorityUrl,IAuthenticationContext $authContext)
{
$serviceRootUrl = $authorityUrl . "/_api/" . Office365Version::V1 . "/";
parent::__construct($serviceRootUrl, $authContext,new JsonFormat(ODataMetadataLevel::Verbose));
parent::__construct($serviceRootUrl, $authContext,new JsonSerializerContext(ODataMetadataLevel::Verbose));
}


Expand Down
4 changes: 2 additions & 2 deletions src/OneNote/OneNoteClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Office365\PHP\Client\Runtime\UpdateEntityQuery;
use Office365\PHP\Client\Runtime\ClientRuntimeContext;
use Office365\PHP\Client\Runtime\HttpMethod;
use Office365\PHP\Client\Runtime\OData\JsonFormat;
use Office365\PHP\Client\Runtime\OData\JsonSerializerContext;
use Office365\PHP\Client\Runtime\OData\ODataMetadataLevel;
use Office365\PHP\Client\Runtime\Office365Version;
use Office365\PHP\Client\Runtime\ResourcePathEntity;
Expand All @@ -22,7 +22,7 @@ public function __construct(IAuthenticationContext $authContext, $version = Offi
{
$this->version = $version;
$this->serviceRootUrl = $this->serviceRootUrl . $version . "/";
parent::__construct($this->serviceRootUrl, $authContext, new JsonFormat(ODataMetadataLevel::NoMetadata), $version);
parent::__construct($this->serviceRootUrl, $authContext, new JsonSerializerContext(ODataMetadataLevel::NoMetadata), $version);
}


Expand Down
4 changes: 2 additions & 2 deletions src/OutlookServices/OutlookClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Office365\PHP\Client\Runtime\HttpMethod;
use Office365\PHP\Client\Runtime\Office365Version;
use Office365\PHP\Client\Runtime\ResourcePathEntity;
use Office365\PHP\Client\Runtime\OData\JsonFormat;
use Office365\PHP\Client\Runtime\OData\JsonSerializerContext;
use Office365\PHP\Client\Runtime\OData\ODataMetadataLevel;
use Office365\PHP\Client\Runtime\Utilities\RequestOptions;

Expand All @@ -25,7 +25,7 @@ public function __construct(IAuthenticationContext $authContext, $version = Offi
{
$this->version = $version;
$this->serviceRootUrl = $this->serviceRootUrl . $version . "/";
parent::__construct($this->serviceRootUrl, $authContext, new JsonFormat(ODataMetadataLevel::Verbose), $version);
parent::__construct($this->serviceRootUrl, $authContext, new JsonSerializerContext(ODataMetadataLevel::Verbose), $version);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Runtime/Auth/SamlTokenProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected function acquireAuthenticationCookies($token)
$headers['Authorization'] = 'BPOSIDCRL ' . $token;
$headers['Content-Type'] = 'application/x-www-form-urlencoded';

$response = Requests::getHead($url,$headers,$token,true);
$response = Requests::head($url,$headers,true);
$cookies = Requests::parseCookies($response);
$this->SPOIDCRL = $cookies['SPOIDCRL'];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Runtime/ClientObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Represents OData base entity
*/
class ClientObject implements ISchemaType
class ClientObject implements IEntityType
{
/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion src/Runtime/ClientObjectCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Client objects collection (represents EntitySet in terms of OData)
*/
class ClientObjectCollection extends ClientObject implements ISchemaTypeCollection
class ClientObjectCollection extends ClientObject implements IEntityTypeCollection
{

/**
Expand Down
13 changes: 9 additions & 4 deletions src/Runtime/ClientRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,14 @@ protected abstract function setRequestHeaders(RequestOptions $request);

/**
* @param string $response
* @param ClientObject|ClientResult $resultObject
*/
public abstract function processResponse($response, $resultObject);
public abstract function processResponse($response);

/**
* Build Client Request
* @param ClientAction $query
* @return RequestOptions
*/
protected abstract function buildRequest(ClientAction $query);
protected abstract function buildRequest();

/**
* @param ClientObject $clientObject
Expand All @@ -129,4 +127,11 @@ public function executeQueryDirect(RequestOptions $request,&$responseInfo=array(
return Requests::execute($request,$responseInfo);
}

/**
* @return ClientAction[]
*/
public function getActions(){
return $this->queries;
}

}
14 changes: 9 additions & 5 deletions src/Runtime/ClientResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


namespace Office365\PHP\Client\Runtime;
use Office365\PHP\Client\Runtime\OData\ODataSerializerContext;


/**
Expand All @@ -10,9 +11,8 @@
class ClientResult
{

function __construct($functionName, $returnValue=null)
function __construct($returnValue=null)
{
$this->FunctionName = $functionName;
$this->Value = $returnValue;
}

Expand All @@ -22,7 +22,7 @@ function __construct($functionName, $returnValue=null)
public function getType(){
if(!is_null($this->Value))
{
if($this->Value instanceof ISchemaType)
if($this->Value instanceof IEntityType)
return $this->Value->getTypeName();
return basename(get_class($this->Value));
}
Expand All @@ -31,9 +31,13 @@ public function getType(){


/**
* @var string $FunctionName
* @param $json
* @param ODataSerializerContext $serializationContext
*/
public $FunctionName;
public function fromJson($json, ODataSerializerContext $serializationContext)
{
$serializationContext->map($json, $this->Value);
}

/**
* @var mixed $Value
Expand Down
41 changes: 30 additions & 11 deletions src/Runtime/ClientRuntimeContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Office365\PHP\Client\Runtime\Auth\IAuthenticationContext;
use Office365\PHP\Client\Runtime\OData\ODataRequest;
use Office365\PHP\Client\Runtime\OData\ODataFormat;
use Office365\PHP\Client\Runtime\OData\ODataSerializerContext;
use Office365\PHP\Client\Runtime\OData\ODataQueryOptions;
use Office365\PHP\Client\Runtime\Utilities\RequestOptions;
use Office365\PHP\Client\Runtime\Utilities\Version;
Expand Down Expand Up @@ -38,9 +38,9 @@ class ClientRuntimeContext
private $pendingRequest;

/**
* @var ODataFormat
* @var ODataSerializerContext
*/
public $Format;
private $serializerContext;


/**
Expand All @@ -52,15 +52,15 @@ class ClientRuntimeContext
* REST client context ctor
* @param string $serviceUrl
* @param IAuthenticationContext $authContext
* @param ODataFormat $format
* @param ODataSerializerContext $serializationContext
* @param string $version
*/
public function __construct($serviceUrl, IAuthenticationContext $authContext, ODataFormat $format, $version = Office365Version::V1)
public function __construct($serviceUrl, IAuthenticationContext $authContext, ODataSerializerContext $serializationContext, $version = Office365Version::V1)
{
$this->version = $version;
$this->serviceRootUrl = $serviceUrl;
$this->authContext = $authContext;
$this->Format = $format;
$this->serializerContext = $serializationContext;
}

/**
Expand Down Expand Up @@ -138,10 +138,21 @@ public function loadQuery(ClientObject $clientObject,ODataQueryOptions $query =
*/
public function executeQuery()
{
$this->getPendingRequest()->executeQuery();
while ($this->hasPendingRequest()) {
$this->getPendingRequest()->executeQuery();
}
return $this;
}

/**
* @return bool
*/
public function hasPendingRequest(){
$queries = $this->pendingRequest->getActions();
return !empty($queries);
}


/**
* @param RequestOptions $options
* @return string
Expand All @@ -154,12 +165,11 @@ public function executeQueryDirect(RequestOptions $options)

/**
* @param string $response
* @param ClientObject|ClientResult $resultObject
* @return self
*/
public function processResponse($response, $resultObject)
public function processResponse($response)
{
$this->getPendingRequest()->processResponse($response, $resultObject);
$this->getPendingRequest()->processResponse($response);
return $this;
}

Expand All @@ -180,7 +190,7 @@ public function addQuery(ClientAction $query, $resultObject = null)
public function getPendingRequest()
{
if (!isset($this->pendingRequest)) {
$this->pendingRequest = new ODataRequest($this, $this->Format);
$this->pendingRequest = new ODataRequest($this);
}
return $this->pendingRequest;
}
Expand All @@ -192,4 +202,13 @@ public function getServerLibraryVersion(){
return new Version();
}


/**
* @return ODataSerializerContext
*/
public function getSerializerContext()
{
return $this->serializerContext;
}

}
2 changes: 1 addition & 1 deletion src/Runtime/ClientValueObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Represents OData complex type(property) of a server-side property value.
*/
class ClientValueObject implements ISchemaType
class ClientValueObject implements IEntityType
{

/**
Expand Down
13 changes: 1 addition & 12 deletions src/Runtime/ClientValueObjectCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Office365\PHP\Client\Runtime;


class ClientValueObjectCollection extends ClientValueObject implements ISchemaTypeCollection
class ClientValueObjectCollection extends ClientValueObject implements IEntityTypeCollection
{

/**
Expand Down Expand Up @@ -70,17 +70,6 @@ function getProperties($flag=SCHEMA_ALL_PROPERTIES)
}, $this->getData());
}


/*function setProperty($name, $payload, $persistChanges = false)
{
foreach ($payload as $key => $value) {
$clientValueObject = $this->createTypedValueObject();
$clientValueObject->setProperty($key,$value,$persistChanges);
$this->addChild($clientValueObject);
}
}*/


/**
* @var array
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Runtime/ISchemaType.php → src/Runtime/IEntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
define ("SCHEMA_SERIALIZABLE_PROPERTIES", 2);


interface ISchemaType
interface IEntityType
{
/**
* @return string
Expand All @@ -29,7 +29,7 @@ public function getProperty($name);

/**
* @param string $name
* @param string $value
* @param mixed $value
* @param bool $persistChanges
*/
function setProperty($name, $value, $persistChanges = true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@



interface ISchemaTypeCollection
interface IEntityTypeCollection extends IEntityType
{

function clearData();

/**
* Instantiates an item
* @return ISchemaType
* @return IEntityType
*/
function createType();


/**
* @param ISchemaType $type
* @param IEntityType $type
*/
function addChild($type);
}
4 changes: 2 additions & 2 deletions src/Runtime/InvokeMethodQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class InvokeMethodQuery extends ClientAction
* InvokeMethodQuery constructor.
* @param ResourcePath $resourcePath
* @param string $methodName
* @param array|ISchemaType $methodParameters
* @param array|IEntityType $methodParameters
*/
public function __construct(ResourcePath $resourcePath, $methodName=null, $methodParameters=null)
{
Expand Down Expand Up @@ -56,7 +56,7 @@ protected function toXmlQuery(SimpleXMLElement $writer){


/**
* @var $MethodParameters array|ISchemaType
* @var $MethodParameters array|IEntityType
*/
public $MethodParameters;

Expand Down
Loading

0 comments on commit e653e7b

Please sign in to comment.