Skip to content

Commit

Permalink
client skeleton, still not working
Browse files Browse the repository at this point in the history
  • Loading branch information
marcogiovinazzi committed Mar 8, 2016
1 parent 2b24671 commit 86fe2fc
Show file tree
Hide file tree
Showing 17 changed files with 1,063 additions and 986 deletions.
13 changes: 7 additions & 6 deletions composer.json
Expand Up @@ -22,18 +22,19 @@
],
"autoload": {
"psr-4": {
"Comodojo\\RpcClient\\": "src"
"Comodojo\\RpcClient\\": "src/Comodojo/RpcClient"
}
},
"require": {
"php": ">=5.3.0",
"comodojo/httprequest": "1.2.*",
"php": ">=5.6.0",
"psr/log": "^1.0",
"comodojo/httprequest": "^1.2",
"comodojo/xmlrpc": "^1.1.1",
"comodojo/exceptions": "@stable",
"phpseclib/phpseclib": "0.3.*"
"phpseclib/phpseclib": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"scrutinizer/ocular": "~1.1"
"phpunit/phpunit": "^4.0|^5.0",
"scrutinizer/ocular": "^1.0"
}
}
53 changes: 53 additions & 0 deletions src/Comodojo/RpcClient/Components/Encoding.php
@@ -0,0 +1,53 @@
<?php namespace Comodojo\RpcClient\Components;

use \Exception;

/**
* Protocol Trait
*
* @package Comodojo Spare Parts
* @author Marco Giovinazzi <marco.giovinazzi@comodojo.org>
* @license MIT
*
* LICENSE:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

trait Encoding {

/**
* Characters encoding
*
* @var string
*/
private $encoding = 'utf-8';

/**
* Set encoding (default to utf-8)
*
* @param string $encoding Characters encoding
*
* @return \Comodojo\RpcClient\RpcClient
*/
public function setEncoding($encoding) {

$this->encoding = $encoding;

return $this;

}

final public function getEncoding() {

return $this->encoding;

}

}
57 changes: 57 additions & 0 deletions src/Comodojo/RpcClient/Components/Encryption.php
@@ -0,0 +1,57 @@
<?php namespace Comodojo\RpcClient\Components;

use \Exception;

/**
* Protocol Trait
*
* @package Comodojo Spare Parts
* @author Marco Giovinazzi <marco.giovinazzi@comodojo.org>
* @license MIT
*
* LICENSE:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

trait Encryption {

/**
* Enable comodojo encrypted transport
*
* @var mixed
*/
private $encryption = false;

/**
* Set encryption key; this will enable the NOT-STANDARD payload encryption
*
* @param string $key Encryption key
*
* @return \Comodojo\RpcClient\RpcClient
*
* @throws \Exception
*/
public function setEncryption($key) {

if ( empty($key) ) throw new Exception("Shared key cannot be empty");

$this->$encryption = $key;

return $this;

}

final public function getEncryption() {

return $this->encryption;

}

}
66 changes: 66 additions & 0 deletions src/Comodojo/RpcClient/Components/Protocol.php
@@ -0,0 +1,66 @@
<?php namespace Comodojo\RpcClient\Components;

use \Exception;

/**
* Protocol Trait
*
* @package Comodojo Spare Parts
* @author Marco Giovinazzi <marco.giovinazzi@comodojo.org>
* @license MIT
*
* LICENSE:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

trait Protocol {

/**
* Supported RPC protocols
*
* @var string
*/
protected $supported_protocols = array("XML", "JSON");

/**
* RPC protocol
*
* @var string
*/
private $protocol = 'XML';

/**
* Set RPC protocol
*
* @param string $protocol RPC protocol
*
* @return \Comodojo\RpcClient\RpcClient
*
* @throws \Exception
*/
public function setProtocol($protocol) {

$proto = strtoupper($protocol);

if ( !in_array($proto, $this->supported_protocols) ) throw new Exception("Invalid RPC protocol");

$this->protocol = $proto;

return $this;

}

final public function getProtocol() {

return $this->protocol;

}

}
114 changes: 114 additions & 0 deletions src/Comodojo/RpcClient/Components/Request.php
@@ -0,0 +1,114 @@
<?php namespace Comodojo\RpcClient\Components;

use \Comodojo\RpcClient\RpcRequest;
use \Exception;

/**
* Protocol Trait
*
* @package Comodojo Spare Parts
* @author Marco Giovinazzi <marco.giovinazzi@comodojo.org>
* @license MIT
*
* LICENSE:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

trait Request {

/**
* Autoclean requests
*
* @var string
*/
private $autoclean = true;

private $requests = array();

/**
* Set autoclean on/off
*
* @param bool $mode If true, requests will be removed from queue at each send()
*
* @return \Comodojo\RpcClient\RpcClient
*/
public function setAutoclean($mode = true) {

$this->autoclean = filter_var($mode, FILTER_VALIDATE_BOOLEAN);

return $this;

}

public function getAutoclean() {

return $this->autoclean;

}

public function clean() {

$this->requests = array();

return $this;

}

public function addRequest(RpcRequest $request) {

$uid = $request->getUniqueId();

$this->requests[$uid] = $request;

return $this;

}

public function getRequest($uid = null) {

if ( is_null($uid) ) {

return $this->requests;

} else if ( array_key_exists($uid, $this->requests) ) {

return $this->requests[$uid];

} else {

return null;

}

}

public function deleteRequest($uid = null) {

if ( is_null($uid) ) {

$this->requests = arrray();

return true;

} else if ( array_key_exists($uid, $this->requests) ) {

unset($this->requests[$uid]);

return true;

} else {

return false;

}

}

}

0 comments on commit 86fe2fc

Please sign in to comment.