Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 058ed9aca4d2f2827bc6fc08bfc52a5d030ca300 1 parent 4424038
@cameronjacobson authored
View
16 LICENSE
@@ -0,0 +1,16 @@
+KyotoTyphoon - PHP client for KyotoTycoon database.
+
+Copyright (C) 2013 Cameron Jacobson
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
View
9 README.md
@@ -1,4 +1,7 @@
-KyotoTyphoon
-============
+# KyotoTyphoon
-PHP client for KyotoTycoon database
+Very early stage of a PHP client for KyotoTycoon
+
+## see examples in:
+
+examples/*
View
10 composer.json
@@ -0,0 +1,10 @@
+{
+ "require": {
+ "evenement/evenement": "2.0.*"
+ },
+ "autoload": {
+ "psr-0": {
+ "KyotoTyphoon": "src/"
+ }
+ }
+}
View
26 examples/example1.php
@@ -0,0 +1,26 @@
+<?php
+
+require_once(dirname(__DIR__).'/vendor/autoload.php');
+
+use KyotoTyphoon\KyotoClient;
+
+// Instantiate BINARY client
+$binaryClient = new KyotoClient([
+ 'url'=>'https://localhost2:1979',
+ 'protocol'=>'binary'
+]);
+var_dump($binaryClient);
+
+// Instantiate REST client
+$restClient = new KyotoClient([
+ 'url'=>'https://localhost2:1979',
+ 'protocol'=>'rest'
+]);
+var_dump($restClient);
+
+// Instantiate RPC client
+$rpcClient = new KyotoClient([
+ 'url'=>'https://localhost2:1979',
+ 'protocol'=>'rpc'
+]);
+var_dump($rpcClient);
View
25 phpunit.xml.dist
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ bootstrap="tests/bootstrap.php"
+>
+ <testsuites>
+ <testsuite name="KyotoTyphoon Test Suite">
+ <directory>./tests/KyotoTyphoon/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory>./src/</directory>
+ </whitelist>
+ </filter>
+</phpunit>
View
11 src/KyotoTyphoon/Client/KyotoBinaryClient.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace KyotoTyphoon\Client;
+
+use \KyotoTyphoon\Interfaces\KyotoClientInterface;
+
+class KyotoBinaryClient implements KyotoClientInterface
+{
+ public function __construct(Array $options){
+ }
+}
View
11 src/KyotoTyphoon/Client/KyotoRestClient.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace KyotoTyphoon\Client;
+
+use KyotoTyphoon\Interfaces\KyotoClientInterface;
+
+class KyotoRestClient implements KyotoClientInterface
+{
+ public function __construct(Array $options){
+ }
+}
View
33 src/KyotoTyphoon/Client/KyotoRpcClient.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace KyotoTyphoon\Client;
+
+use KyotoTyphoon\Interfaces\KyotoClientInterface;
+
+class KyotoRpcClient implements KyotoClientInterface
+{
+ private $defaultEncoding = 'B';
+ private $defaultContentType = 'text/tab-separated-values';
+ private $validContentTypes = ['text/tab-separated-values','application/x-www-form-urlencoded','query-string'];
+ private $validEncodings = ['base64'=>'B', 'quoted-printable'=>'Q', 'url-encoding'=>'U'];
+
+ public function __construct(Array $options){
+ $this->setDefaultEncoding(@$options['encoding']);
+ $this->setDefaultContentType(@$options['contentType']);
+ }
+
+ public function setDefaultEncoding($encoding = ''){
+ if(isset($this->validEncodings[$encoding])){
+ $this->defaultEncoding = $this->validEncodings[$encoding];
+ }
+ elseif(in_array($encoding, $this->validEncodings)){
+ $this->defaultEncoding = $encoding;
+ }
+ }
+
+ public function setDefaultContentType($contentType = ''){
+ if(in_array($contentType,$this->validContentTypes)){
+ $this->defaultContentType = strtolower($contentType);
+ }
+ }
+}
View
8 src/KyotoTyphoon/Interfaces/KyotoClientInterface.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace KyotoTyphoon\Interfaces;
+
+interface KyotoClientInterface
+{
+ public function __construct(Array $options);
+}
View
8 src/KyotoTyphoon/Interfaces/KyotoTransportInterface.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace KyotoTyphoon\Interfaces;
+
+interface KyotoTransportInterface
+{
+ public function __construct(Array $options);
+}
View
62 src/KyotoTyphoon/KyotoClient.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace KyotoTyphoon;
+
+use \KyotoTyphoon\Client\KyotoBinaryClient;
+use \KyotoTyphoon\Client\KyotoRestClient;
+use \KyotoTyphoon\Client\KyotoRpcClient;
+use \KyotoTyphoon\Transport\KyotoBinaryTransport;
+use \KyotoTyphoon\Transport\KyotoRestTransport;
+use \KyotoTyphoon\Transport\KyotoRpcTransport;
+
+class KyotoClient
+{
+ private $requests = array();
+ private $responses = array();
+ private $scheme = 'http';
+ private $host = 'localhost';
+ private $port = '1978';
+ private $validSchemes = ['http', 'https'];
+ private $protocol;
+ private $transport;
+ private $client;
+
+ public function __construct(Array $options){
+ $url = empty($options['url']) ? array() : parse_url($options['url']);
+ $this->setScheme(@$url['scheme']);
+ $this->setHost(@$url['host']);
+ $this->setPort(@$url['port']);
+ $this->protocol = @strtolower($options['protocol']) ?: 'rest';
+ switch($this->protocol){
+ case 'binary':
+ $this->transport = new KyotoBinaryTransport($options);
+ $this->client = new KyotoBinaryClient($options);
+ break;
+ case 'rpc':
+ $this->transport = new KyotoRpcTransport($options);
+ $this->client = new KyotoRpcClient($options);
+ break;
+ default:
+ $this->transport = new KyotoRestTransport($options);
+ $this->client = new KyotoRestClient($options);
+ break;
+ }
+ }
+
+ public function setScheme($scheme = ''){
+ if(in_array($scheme, $this->validSchemes)){
+ $this->scheme = $scheme;
+ }
+ }
+
+ public function setHost($host = ''){
+ $this->host = strtolower($host);
+ }
+
+ public function setPort($port = 0){
+ if(!empty($port)){
+ $this->port = (int)$port;
+ }
+ }
+
+}
View
9 src/KyotoTyphoon/KyotoEvent.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace KyotoTyphoon;
+
+use \Evenement\EventEmitter;
+
+class KyotoEvent extends EventEmitter
+{
+}
View
36 src/KyotoTyphoon/KyotoRequest.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace KyotoTyphoon;
+
+class KyotoRequest
+{
+ private $headers = array();
+ private $contentLength;
+
+ public setContentLength($length){
+ $this->contentLength = $length;
+ }
+
+ private function setHeader($key, $value){
+ $this->headers[$key] = $value;
+ }
+
+ private function removeHeader($key){
+ @unset($this->headers[$key]);
+ }
+
+ private function initRequest(){
+ $this->headers = array($action.' '.$path.' HTTP/1.0');
+ $this->setHeader('Host',$this->host.':'.$this->port);
+ $this->setHeader('Content-Type',$this->ctype);
+ $this->setHeader('Content-Length',$this->contentLength);
+ }
+
+ private function doAction(){
+
+ }
+
+ protected function send(){
+
+ }
+}
View
57 src/KyotoTyphoon/KyotoResponse.php
@@ -0,0 +1,57 @@
+<?php
+
+namespace KyotoTyphoon;
+
+class KyotoResponse
+{
+ public $host = 'localhost';
+ public $port = '1978';
+ public $ctype = 'text/tab-separated-values';
+ public $encoding = 'B';
+ private $headers = array();
+
+ public setEncoding($encoding = 'B'){
+ if(in_array($encoding, array('B', 'Q', 'U'))){
+ $this->encoding = $encoding;
+ }
+ }
+
+ public setHost($host){
+ $this->setHeader('Host', $host.':'.$this->port);
+ }
+
+ public setPort($port){
+ $this->port = $port;
+ }
+
+ public setContentType($contentType){
+ $this->setHeader('Content-Type', $contentType);
+ }
+
+ public setContentLength($length){
+ $this->clength = $length;
+ }
+
+ private function setHeader($key, $value){
+ $this->headers[$key] = $value;
+ }
+
+ private function removeHeader($key){
+ @unset($this->headers[$key]);
+ }
+
+ private function initRequest(){
+ $this->headers = array($action.' '.$path.' HTTP/1.0');
+ $this->setHeader('Host',$this->host.':'.$this->port);
+ $this->setHeader('Content-Type',$this->ctype);
+ $this->setHeader('Content-Length',$length);
+ }
+
+ private function doAction(){
+
+ }
+
+ private function parseResponse(){
+ $response =
+ }
+}
View
8 src/KyotoTyphoon/KyotoTransport.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace KyotoTyphoon;
+
+class KyotoTransport
+{
+ public function __construct(Array $options){}
+}
View
57 src/KyotoTyphoon/KyotoTycoon.php
@@ -0,0 +1,57 @@
+<?php
+
+namespace KyotoTyphoon;
+
+class KyotoTycoon
+{
+ public $host = 'localhost';
+ public $port = '1978';
+ public $ctype = 'text/tab-separated-values';
+ public $encoding = 'B';
+ private $headers = array();
+
+ public setEncoding($encoding = 'B'){
+ if(in_array($encoding, array('B', 'Q', 'U'))){
+ $this->encoding = $encoding;
+ }
+ }
+
+ public setHost($host){
+ $this->setHeader('Host', $host.':'.$this->port);
+ }
+
+ public setPort($port){
+ $this->port = $port;
+ }
+
+ public setContentType($contentType){
+ $this->setHeader('Content-Type', $contentType);
+ }
+
+ public setContentLength($length){
+ $this->clength = $length;
+ }
+
+ private function setHeader($key, $value){
+ $this->headers[$key] = $value;
+ }
+
+ private function removeHeader($key){
+ @unset($this->headers[$key]);
+ }
+
+ private function initRequest(){
+ $this->headers = array($action.' '.$path.' HTTP/1.0');
+ $this->setHeader('Host',$this->host.':'.$this->port);
+ $this->setHeader('Content-Type',$this->ctype);
+ $this->setHeader('Content-Length',$length);
+ }
+
+ private function doAction(){
+
+ }
+
+ private function parseResponse(){
+ $response =
+ }
+}
View
13 src/KyotoTyphoon/Transport/KyotoBinaryTransport.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace KyotoTyphoon\Transport;
+
+use KyotoTyphoon\KyotoTransport;
+use KyotoTyphoon\Interfaces\KyotoTransportInterface;
+
+class KyotoBinaryTransport extends KyotoTransport implements KyotoTransportInterface
+{
+ public function __construct(Array $options){
+ parent::__construct($options);
+ }
+}
View
13 src/KyotoTyphoon/Transport/KyotoRestTransport.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace KyotoTyphoon\Transport;
+
+use KyotoTyphoon\KyotoTransport;
+use KyotoTyphoon\Interfaces\KyotoTransportInterface;
+
+class KyotoRestTransport extends KyotoTransport implements KyotoTransportInterface
+{
+ public function __construct(Array $options){
+ parent::__construct($options);
+ }
+}
View
35 src/KyotoTyphoon/Transport/KyotoRpcTransport.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace KyotoTyphoon\Transport;
+
+use KyotoTyphoon\KyotoTransport;
+use KyotoTyphoon\Interfaces\KyotoTransportInterface;
+
+class KyotoRpcTransport extends KyotoTransport implements KyotoTransportInterface
+{
+ private $defaultEncoding = 'B';
+ private $defaultContentType = 'text/tab-separated-values';
+ private $validContentTypes = ['text/tab-separated-values','application/x-www-form-urlencoded','query-string'];
+ private $validEncodings = ['base64'=>'B', 'quoted-printable'=>'Q', 'url-encoding'=>'U'];
+
+ public function __construct(Array $options){
+ parent::__construct($options);
+ $this->setDefaultEncoding(@$options['encoding']);
+ $this->setDefaultContentType(@$options['contentType']);
+ }
+
+ public function setDefaultEncoding($encoding = ''){
+ if(isset($this->validEncodings[$encoding])){
+ $this->defaultEncoding = $this->validEncodings[$encoding];
+ }
+ elseif(in_array($encoding, $this->validEncodings)){
+ $this->defaultEncoding = $encoding;
+ }
+ }
+
+ public function setDefaultContentType($contentType = ''){
+ if(in_array($contentType,$this->validContentTypes)){
+ $this->defaultContentType = strtolower($contentType);
+ }
+ }
+}
View
87 tests/KyotoTyphoon/KyotoClientTest.php
@@ -0,0 +1,87 @@
+<?php
+
+namespace KyotoTyphoon\Tests;
+
+use \KyotoTyphoon\KyotoClient;
+use \KyotoTyphoon\Client\KyotoBinaryClient;
+use \KyotoTyphoon\Client\KyotoRestClient;
+use \KyotoTyphoon\Client\KyotoRpcClient;
+use \KyotoTyphoon\Transport\KyotoBinaryTransport;
+use \KyotoTyphoon\Transport\KyotoRestTransport;
+use \KyotoTyphoon\Transport\KyotoRpcTransport;
+
+class KyotoClientTest extends \PHPUnit_Framework_TestCase
+{
+ private $client;
+
+ public function setUp(){}
+
+ public function getClient($type){
+ return new KyotoClient([
+ 'url' => 'http://localhost:1978',
+ 'protocol' => $type
+ ]);
+ }
+
+ public function testClientConstructor(){
+ $this->BinaryClient = $this->getClient('binary');
+ $this->assertTrue($this->BinaryClient instanceof \KyotoTyphoon\KyotoClient);
+
+ $this->RestClient = $this->getClient('rest');
+ $this->assertTrue($this->RestClient instanceof \KyotoTyphoon\KyotoClient);
+
+ $this->RpcClient = $this->getClient('rpc');
+ $this->assertTrue($this->RpcClient instanceof \KyotoTyphoon\KyotoClient);
+ }
+
+ public function testBinaryProtocol(){
+ $this->BinaryClient = $this->getClient('binary');
+
+ $prop = new \ReflectionProperty('\KyotoTyphoon\KyotoClient','transport');
+ $prop->setAccessible(true);
+ $binaryTransport = $prop->getValue($this->BinaryClient);
+ $this->assertTrue($binaryTransport instanceof \KyotoTyphoon\Transport\KyotoBinaryTransport);
+
+ $prop = new \ReflectionProperty('\KyotoTyphoon\KyotoClient','client');
+ $prop->setAccessible(true);
+ $binaryClient = $prop->getValue($this->BinaryClient);
+ $this->assertTrue($binaryClient instanceof \KyotoTyphoon\Client\KyotoBinaryClient);
+
+ $this->assertTrue(in_array('KyotoTyphoon\Interfaces\KyotoTransportInterface',(array)class_implements($binaryTransport)));
+ $this->assertTrue(in_array('KyotoTyphoon\Interfaces\KyotoClientInterface',(array)class_implements($binaryClient)));
+ }
+
+ public function testRestProtocol(){
+ $this->RestClient = $this->getClient('rest');
+
+ $prop = new \ReflectionProperty('\KyotoTyphoon\KyotoClient','transport');
+ $prop->setAccessible(true);
+ $restTransport = $prop->getValue($this->RestClient);
+ $this->assertTrue($restTransport instanceof \KyotoTyphoon\Transport\KyotoRestTransport);
+
+ $prop = new \ReflectionProperty('\KyotoTyphoon\KyotoClient','client');
+ $prop->setAccessible(true);
+ $restClient = $prop->getValue($this->RestClient);
+ $this->assertTrue($restClient instanceof \KyotoTyphoon\Client\KyotoRestClient);
+
+ $this->assertTrue(in_array('KyotoTyphoon\Interfaces\KyotoTransportInterface',(array)class_implements($restTransport)));
+ $this->assertTrue(in_array('KyotoTyphoon\Interfaces\KyotoClientInterface',(array)class_implements($restClient)));
+ }
+
+ public function testRpcProtocol(){
+ $this->RpcClient = $this->getClient('rpc');
+
+ $prop = new \ReflectionProperty('\KyotoTyphoon\KyotoClient','transport');
+ $prop->setAccessible(true);
+ $rpcTransport = $prop->getValue($this->RpcClient);
+ $this->assertTrue($rpcTransport instanceof \KyotoTyphoon\Transport\KyotoRpcTransport);
+
+ $prop = new \ReflectionProperty('\KyotoTyphoon\KyotoClient','client');
+ $prop->setAccessible(true);
+ $rpcClient = $prop->getValue($this->RpcClient);
+ $this->assertTrue($rpcClient instanceof \KyotoTyphoon\Client\KyotoRpcClient);
+
+ $this->assertTrue(in_array('KyotoTyphoon\Interfaces\KyotoTransportInterface',(array)class_implements($rpcTransport)));
+ $this->assertTrue(in_array('KyotoTyphoon\Interfaces\KyotoClientInterface',(array)class_implements($rpcClient)));
+ }
+}
View
4 tests/bootstrap.php
@@ -0,0 +1,4 @@
+<?php
+
+$loader = require dirname(__DIR__).'/vendor/autoload.php';
+$loader->add('KyotoTyphoon\Tests', __DIR__);
Please sign in to comment.
Something went wrong with that request. Please try again.