Skip to content

Commit

Permalink
Hydrate publics
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Sep 16, 2014
1 parent bfa78be commit 96f7881
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 122 deletions.
15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@
}
],
"require": {
"php": ">=5.4.0",
"guzzlehttp/guzzle": "4.*",
"symfony/serializer":"*",
"packaged/helpers": "*",
"packaged/docblock": "*",
"packaged/config": "*"
"php": ">=5.4.0",
"guzzlehttp/guzzle": "4.*",
"symfony/serializer": "*",
"packaged/helpers": "*",
"packaged/docblock": "*",
"packaged/config": "*"
},
"require-dev": {
"phpunit/phpunit": "4.1"
},
"autoload": {
"psr-4": {
"Packaged\\Api\\": "src",
"Packaged\\ApiExample\\": "example"
"Packaged\\Api\\": "src"
}
}
}
17 changes: 0 additions & 17 deletions example/CorpApi.php

This file was deleted.

31 changes: 0 additions & 31 deletions example/Endpoints/UserEndpoint.php

This file was deleted.

18 changes: 0 additions & 18 deletions example/Requests/UserPayload.php

This file was deleted.

16 changes: 0 additions & 16 deletions example/UserResult.php

This file was deleted.

14 changes: 0 additions & 14 deletions run.php

This file was deleted.

11 changes: 11 additions & 0 deletions src/Abstracts/AbstractApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
use Packaged\Api\Interfaces\ApiRequestInterface;
use Packaged\Api\Interfaces\ApiResponseInterface;
use Packaged\Api\Response\ApiCallData;
use Packaged\Helpers\ValueAs;

abstract class AbstractApiResponse implements ApiResponseInterface
{
protected $_hydratePublic = true;

/**
* @param ApiRequestInterface $request
*
Expand Down Expand Up @@ -59,6 +62,14 @@ public function getApiCallData()
public function setApiCallData(ApiCallData $callData)
{
$this->_apiCallData = $callData;
if($this->_hydratePublic)
{
$data = $callData->getRawResult();
foreach(ValueAs::arr($data) as $key => $value)
{
$this->$key = $value;
}
}
}

public function __call($method, $params)
Expand Down
7 changes: 7 additions & 0 deletions src/Interfaces/ApiResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ public function getApiCallData();
* @return ApiResponseInterface|static
*/
public function setApiCallData(ApiCallData $callData);

/**
* Retrieve the response data as an array
*
* @return array
*/
public function toArray();
}
18 changes: 0 additions & 18 deletions test.php

This file was deleted.

0 comments on commit 96f7881

Please sign in to comment.