-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from fcastilloes/master
Refactor and test runtime-call mappers
- Loading branch information
Showing
14 changed files
with
699 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/** | ||
* PHP 7 SDK for the KATANA(tm) Framework (http://katana.kusanagi.io) | ||
* Copyright (c) 2016-2017 KUSANAGI S.L. All rights reserved. | ||
* | ||
* Distributed under the MIT license | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code | ||
* | ||
* @link https://github.com/kusanagi/katana-sdk-php7 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
* @copyright Copyright (c) 2016-2017 KUSANAGI S.L. (http://kusanagi.io) | ||
*/ | ||
|
||
namespace Katana\Sdk\Mapper; | ||
|
||
use Katana\Sdk\Api\Value\ActionTarget; | ||
use Katana\Sdk\Api\Transport; | ||
use Katana\Sdk\File; | ||
use Katana\Sdk\Param; | ||
|
||
class CompactRuntimeCallMapper implements RuntimeCallWriterInterface | ||
{ | ||
/** | ||
* @var TransportWriterInterface | ||
*/ | ||
private $transportMapper; | ||
|
||
/** | ||
* @param TransportWriterInterface $transportMapper | ||
*/ | ||
public function __construct(TransportWriterInterface $transportMapper) | ||
{ | ||
$this->transportMapper = $transportMapper; | ||
} | ||
|
||
/** | ||
* @param Param $param | ||
* @return array | ||
*/ | ||
private function writeParam(Param $param) | ||
{ | ||
return [ | ||
'n' => $param->getName(), | ||
'v' => $param->getValue(), | ||
't' => $param->getType(), | ||
]; | ||
} | ||
|
||
/** | ||
* @param File $file | ||
* @return array | ||
*/ | ||
private function writeFile(File $file) | ||
{ | ||
return [ | ||
'n' => $file->getName(), | ||
'p' => $file->getPath(), | ||
't' => $file->getToken(), | ||
'f' => $file->getFilename(), | ||
's' => $file->getSize(), | ||
'm' => $file->getMime() | ||
]; | ||
} | ||
|
||
/** | ||
* @param string $action | ||
* @param Transport $transport | ||
* @param ActionTarget $target | ||
* @param Param[] $params | ||
* @param File[] $files | ||
* @return array | ||
*/ | ||
public function writeRuntimeCall( | ||
string $action, | ||
Transport $transport, | ||
ActionTarget $target, | ||
array $params = [], | ||
array $files = [] | ||
): array { | ||
return [ | ||
'c' => [ | ||
'n' => 'runtime-call', | ||
'a' => [ | ||
'a' => $action, | ||
'c' => [ | ||
$target->getService(), | ||
$target->getVersion()->getVersion(), | ||
$target->getAction() | ||
], | ||
'T' => $this->transportMapper->writeTransport($transport), | ||
'p' => array_map([$this, 'writeParam'], $params), | ||
'f' => array_map([$this, 'writeFile'], $files), | ||
], | ||
], | ||
'm' => [ | ||
's' => 'service', | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/** | ||
* PHP 7 SDK for the KATANA(tm) Framework (http://katana.kusanagi.io) | ||
* Copyright (c) 2016-2017 KUSANAGI S.L. All rights reserved. | ||
* | ||
* Distributed under the MIT license | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code | ||
* | ||
* @link https://github.com/kusanagi/katana-sdk-php7 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
* @copyright Copyright (c) 2016-2017 KUSANAGI S.L. (http://kusanagi.io) | ||
*/ | ||
|
||
namespace Katana\Sdk\Mapper; | ||
|
||
use Katana\Sdk\Api\Value\ActionTarget; | ||
use Katana\Sdk\Api\Transport; | ||
use Katana\Sdk\File; | ||
use Katana\Sdk\Param; | ||
|
||
class ExtendedRuntimeCallMapper implements RuntimeCallWriterInterface | ||
{ | ||
/** | ||
* @var TransportWriterInterface | ||
*/ | ||
private $transportMapper; | ||
|
||
/** | ||
* @param TransportWriterInterface $transportMapper | ||
*/ | ||
public function __construct(TransportWriterInterface $transportMapper) | ||
{ | ||
$this->transportMapper = $transportMapper; | ||
} | ||
|
||
/** | ||
* @param Param $param | ||
* @return array | ||
*/ | ||
private function writeParam(Param $param) | ||
{ | ||
return [ | ||
'name' => $param->getName(), | ||
'value' => $param->getValue(), | ||
'type' => $param->getType(), | ||
]; | ||
} | ||
|
||
/** | ||
* @param File $file | ||
* @return array | ||
*/ | ||
private function writeFile(File $file) | ||
{ | ||
return [ | ||
'name' => $file->getName(), | ||
'path' => $file->getPath(), | ||
'token' => $file->getToken(), | ||
'filename' => $file->getFilename(), | ||
'size' => $file->getSize(), | ||
'mime' => $file->getMime() | ||
]; | ||
} | ||
|
||
/** | ||
* @param string $action | ||
* @param Transport $transport | ||
* @param ActionTarget $target | ||
* @param Param[] $params | ||
* @param File[] $files | ||
* @return array | ||
*/ | ||
public function writeRuntimeCall( | ||
string $action, | ||
Transport $transport, | ||
ActionTarget $target, | ||
array $params = [], | ||
array $files = [] | ||
): array { | ||
return [ | ||
'command' => [ | ||
'name' => 'runtime-call', | ||
'arguments' => [ | ||
'action' => $action, | ||
'callee' => [ | ||
$target->getService(), | ||
$target->getVersion()->getVersion(), | ||
$target->getAction() | ||
], | ||
'transport' => $this->transportMapper->writeTransport($transport), | ||
'params' => array_map([$this, 'writeParam'], $params), | ||
'files' => array_map([$this, 'writeFile'], $files), | ||
], | ||
], | ||
'meta' => [ | ||
'scope' => 'service', | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* PHP 7 SDK for the KATANA(tm) Framework (http://katana.kusanagi.io) | ||
* Copyright (c) 2016-2017 KUSANAGI S.L. All rights reserved. | ||
* | ||
* Distributed under the MIT license | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code | ||
* | ||
* @link https://github.com/kusanagi/katana-sdk-php7 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
* @copyright Copyright (c) 2016-2017 KUSANAGI S.L. (http://kusanagi.io) | ||
*/ | ||
|
||
namespace Katana\Sdk\Mapper; | ||
|
||
use Katana\Sdk\Api\Transport; | ||
use Katana\Sdk\Api\Value\ActionTarget; | ||
use Katana\Sdk\File; | ||
use Katana\Sdk\Param; | ||
|
||
interface RuntimeCallWriterInterface | ||
{ | ||
/** | ||
* @param string $action | ||
* @param Transport $transport | ||
* @param ActionTarget $target | ||
* @param Param[] $params | ||
* @param File[] $files | ||
* @return array | ||
*/ | ||
public function writeRuntimeCall( | ||
string $action, | ||
Transport $transport, | ||
ActionTarget $target, | ||
array $params = [], | ||
array $files = [] | ||
): array; | ||
} |
Oops, something went wrong.