Skip to content

Commit

Permalink
PSR0
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineguiral committed Jul 29, 2013
1 parent d70e668 commit f0d03ca
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 55 deletions.
20 changes: 20 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "pop/pop_hbase",
"type": "library",
"description": "Pop HBase is a PHP client to an HBase server. It use JSON Rest and the Curl extension to communicate with the HBase server and provides a very simple and convenient interface.",
"keywords": ["hbase", "rest", "json","curl"],
"homepage": "https://github.com/pop/pop_hbase",
"authors": [
{
"name" : "Worms David"
}
],
"require": {
"php": ">=5.3.0",
"ext-curl": "*"
},
"autoload": {
"psr-0": {"PhpAmqpLib": ""}
},
"license": "LGPL-2.1"
}
6 changes: 4 additions & 2 deletions src/PopHbaseConnection.php → src/PopHBase/Connection.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace PopHBase;

/**
* Copyright (c) 2008, SARL Adaltas. All rights reserved.
* Code licensed under the BSD License:
Expand All @@ -11,7 +13,7 @@
*
* @author David Worms info(at)adaltas.com
*/
interface PopHbaseConnection{
interface Connection{

/**
* Connection constructor with its related information.
Expand All @@ -30,7 +32,7 @@ public function __construct(array $options = array());
/**
* Send HTTP REST command.
*
* @return PopHbaseResponse Response object parsing the HTTP HBase response.
* @return Response Response object parsing the HTTP HBase response.
*/
public function execute($method,$url,$data=null,$raw=false);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace PopHBase;

/**
* Copyright (c) 2008, SARL Adaltas. All rights reserved.
* Code licensed under the BSD License:
Expand All @@ -11,7 +13,7 @@
*
* @author David Worms info(at)adaltas.com
*/
class PopHbaseConnectionCurl implements PopHbaseConnection{
class ConnectionCurl implements Connection{

public $options;

Expand Down Expand Up @@ -62,7 +64,7 @@ public function __get($property){
/**
* Send HTTP REST command.
*
* @return PopHbaseResponse Response object parsing the HTTP HBase response.
* @return Response Response object parsing the HTTP HBase response.
*/
public function execute($method,$url,$data=null,$raw=false) {
$url = (substr($url, 0, 1) == '/' ? $url : '/'.$url);
Expand Down Expand Up @@ -124,7 +126,7 @@ public function execute($method,$url,$data=null,$raw=false) {
fclose($file);
break;
}
return new PopHbaseResponse($headers,$body,$raw);
return new Response($headers,$body,$raw);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php


namespace PopHBase;

/**
* Copyright (c) 2008, SARL Adaltas. All rights reserved.
* Code licensed under the BSD License:
Expand All @@ -11,7 +14,7 @@
*
* @author David Worms info(at)adaltas.com
*/
class PopHbaseConnectionSock implements PopHbaseConnection{
class ConnectionSock implements Connection{

public $options;

Expand Down Expand Up @@ -72,15 +75,15 @@ public function __get($property){
/**
* Open the connection to the HBase server.
*
* @return PopHbaseConnection Current connection instance
* @return Connection Current connection instance
*/
public function connect() {
if(isset($this->options['sock'])){
$this->disconnect();
}
$this->options['sock'] = fsockopen($this->options['host'], $this->options['port'], $errNum, $errString);
if(!$this->options['sock']) {
throw new PopHbaseException('Failed connecting to '.(!empty($this->options['username'])?$this->options['username'].'@':'').$this->options['host'].':'.$this->options['port'].' ('.$errString.')');
throw new Exception('Failed connecting to '.(!empty($this->options['username'])?$this->options['username'].'@':'').$this->options['host'].':'.$this->options['port'].' ('.$errString.')');
}
return $this;
}
Expand All @@ -95,7 +98,7 @@ public function destruct() {
/**
* Close the connection to the HBase server.
*
* @return PopHbaseConnection Current connection instance
* @return Connection Current connection instance
*/
public function disconnect() {
if(!isset($this->options['sock'])){
Expand All @@ -110,7 +113,7 @@ public function disconnect() {
/**
* Send HTTP REST command.
*
* @return PopHbaseResponse Response object parsing the HTTP HBase response.
* @return Response Response object parsing the HTTP HBase response.
*/
public function execute($method,$url,$data=null,$raw=false) {
$url = (substr($url, 0, 1) == '/' ? $url : '/'.$url);
Expand Down Expand Up @@ -205,7 +208,7 @@ public function execute($method,$url,$data=null,$raw=false) {
// echo '------------------------'."\n";
// print_r($body);
// echo '------------------------'."\n";
return new PopHbaseResponse($headers,$body,$raw);
return new Response($headers,$body,$raw);
}

}
4 changes: 3 additions & 1 deletion src/PopHbaseException.php → src/PopHBase/Exception.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace PopHBase;

/**
* Copyright (c) 2008, SARL Adaltas. All rights reserved.
* Code licensed under the BSD License:
Expand All @@ -11,6 +13,6 @@
*
* @author David Worms info(at)adaltas.com
*/
class PopHbaseException extends Exception{
class Exception extends Exception{

}
4 changes: 3 additions & 1 deletion src/PopHbaseIterator.php → src/PopHBase/Iterator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace PopHBase;

/**
* Copyright (c) 2008, SARL Adaltas. All rights reserved.
* Code licensed under the BSD License:
Expand All @@ -11,7 +13,7 @@
*
* @author David Worms info(at)adaltas.com
*/
abstract class PopHbaseIterator implements Countable, Iterator{
abstract class Iterator implements Countable, Iterator{


//public $data = array();
Expand Down
12 changes: 6 additions & 6 deletions src/PopHbase.php → src/PopHBase/PopHbase.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

namespace PopHBase;
/**
* Copyright (c) 2008, SARL Adaltas. All rights reserved.
* Code licensed under the BSD License:
Expand All @@ -17,9 +17,9 @@ class PopHbase{

public function __construct($options=array()){
if(empty($options['connection'])){
$options['connection'] = 'PopHbaseConnectionCurl';
}else if (class_exists('PopHbaseConnection'.ucfirst($options['connection']))){
$options['connection'] = 'PopHbaseConnection'.ucfirst($options['connection']);
$options['connection'] = 'ConnectionCurl';
}else if (class_exists('Connection'.ucfirst($options['connection']))){
$options['connection'] = 'Connection'.ucfirst($options['connection']);
}else if (!class_exists($options['connection'])){
throw new Exception('Invalid connection class: "'.$options['connection'].'"');
}
Expand All @@ -42,7 +42,7 @@ public function __get($property){
return $this->getTables();
break;
case 'request':
return new PopHbaseRequest($this);
return new Request($this);
break;
}
}
Expand All @@ -66,7 +66,7 @@ public function destruct(){
*/
public function getTables(){
if(isset($this->tables)) return $this->tables;
return $this->tables = new PopHbaseTables($this);
return $this->tables = new Tables($this);
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/PopHbaseRequest.php → src/PopHBase/Request.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace PopHBase;

/**
* Copyright (c) 2008, SARL Adaltas. All rights reserved.
* Code licensed under the BSD License:
Expand All @@ -11,7 +13,7 @@
*
* @author David Worms info(at)adaltas.com
*/
class PopHbaseRequest{
class Request{

public $hbase;

Expand All @@ -27,7 +29,7 @@ function __construct(PopHbase $hbase){
/**
* Create a DELETE HTTP request.
*
* @return PopHbaseResponse Response object
* @return Response Response object
*/
public function delete($command){
return $this->hbase->connection->execute('DELETE',$command);
Expand All @@ -36,7 +38,7 @@ public function delete($command){
/**
* Create a GET HTTP request.
*
* @return PopHbaseResponse Response object
* @return Response Response object
*/
public function get($command){
return $this->hbase->connection->execute('GET',$command);
Expand All @@ -45,7 +47,7 @@ public function get($command){
/**
* Create a POST HTTP request.
*
* @return PopHbaseResponse Response object
* @return Response Response object
*/
public function post($command,$data){
return $this->hbase->connection->execute('POST',$command,$data);
Expand All @@ -54,7 +56,7 @@ public function post($command,$data){
/**
* Create a PUT HTTP request.
*
* @return PopHbaseResponse Response object
* @return Response Response object
*/
public function put($command,$data=null){
return $this->hbase->connection->execute('PUT',$command,$data);
Expand Down
6 changes: 4 additions & 2 deletions src/PopHbaseResponse.php → src/PopHBase/Response.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace PopHBase;

/**
* Copyright (c) 2008, SARL Adaltas. All rights reserved.
* Code licensed under the BSD License:
Expand All @@ -11,7 +13,7 @@
*
* @author David Worms info(at)adaltas.com
*/
class PopHbaseResponse{
class Response{

public function __construct($headers,$body,$raw=false) {
$this->headers = $headers;
Expand All @@ -22,7 +24,7 @@ public function __construct($headers,$body,$raw=false) {
// $status = $matches[1];
// switch($status){
// case '500':
// throw new PopHbaseException(constant('PurHTTP::CODE_'.$status));
// throw new Exception(constant('PurHTTP::CODE_'.$status));
// }
}

Expand Down
4 changes: 3 additions & 1 deletion src/PopHbaseRow.php → src/PopHBase/Row.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace PopHBase;

/**
* Copyright (c) 2008, SARL Adaltas. All rights reserved.
* Code licensed under the BSD License:
Expand All @@ -11,7 +13,7 @@
*
* @author David Worms info(at)adaltas.com
*/
class PopHbaseRow{
class Row{

public $hbase;
public $key;
Expand Down
6 changes: 4 additions & 2 deletions src/PopHbaseTable.php → src/PopHBase/Table.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace PopHBase;

/**
* Copyright (c) 2008, SARL Adaltas. All rights reserved.
* Code licensed under the BSD License:
Expand All @@ -11,7 +13,7 @@
*
* @author David Worms info(at)adaltas.com
*/
class PopHbaseTable{
class Table{

public $hbase;
public $name;
Expand Down Expand Up @@ -42,7 +44,7 @@ public function exists(){
}

public function row($row){
return new PopHbaseRow($this->hbase,$this->name,$row);
return new Row($this->hbase,$this->name,$row);
}

}
8 changes: 5 additions & 3 deletions src/PopHbaseTables.php → src/PopHBase/Tables.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace PopHBase;

/**
* Copyright (c) 2008, SARL Adaltas. All rights reserved.
* Code licensed under the BSD License:
Expand All @@ -11,7 +13,7 @@
*
* @author David Worms info(at)adaltas.com
*/
class PopHbaseTables extends PopHbaseIterator{
class Tables extends Iterator{

public $hbase;

Expand Down Expand Up @@ -51,7 +53,7 @@ public function load(){
return $this;
}
foreach($tables['table'] as $table){
$this->__data['data'][$table['name']] = new PopHbaseTable($this->hbase,$table['name']);
$this->__data['data'][$table['name']] = new Table($this->hbase,$table['name']);
$this->__data['loaded'][$table['name']] = true;
}
return $this;
Expand Down Expand Up @@ -194,7 +196,7 @@ public function names(){
*/
public function table($table){
if(!isset($this->__data['data'][$table])){
$this->__data['data'][$table] = new PopHbaseTable($this->hbase,$table);
$this->__data['data'][$table] = new Table($this->hbase,$table);
}
return $this->__data['data'][$table];
}
Expand Down
19 changes: 0 additions & 19 deletions src/pop_hbase.inc.php

This file was deleted.

Loading

0 comments on commit f0d03ca

Please sign in to comment.