Skip to content

Commit 51dcb1d

Browse files
committed
lib: intro QuickBase namespace
1 parent b84a7e7 commit 51dcb1d

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Example
1515
-------
1616
```php
1717
try {
18-
$qb = new QuickBase(array(
18+
$qb = new \QuickBase\QuickBase(array(
1919
'realm' => 'www',
2020
'appToken' => '****'
2121
));
@@ -48,7 +48,7 @@ try {
4848
));
4949

5050
var_dump($response['table']['records']);
51-
}catch(QuickBaseError $err){
51+
}catch(\QuickBase\QuickBaseError $err){
5252
echo '('.$err->getCode().') '.$err->getMessage().'. '.$err->getDetails();
5353
}
5454

@@ -62,11 +62,11 @@ php-quickbase throws exceptions whenever an error is detected. You do not have t
6262
```php
6363
try {
6464
// QuickBase API Calls Here
65-
}catch(QuickBaseError $err){
65+
}catch(\QuickBase\QuickBaseError $err){
6666
echo '('.$err->getCode().') '.$err->getMessage().'. '.$err->getDetails();
6767

6868
/*
69-
* class QuickBaseError extends Exception {
69+
* class \QuickBase\QuickBaseError extends \Exception {
7070
*
7171
* protected int $code;
7272
* protected string $message;

quickbase.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
namespace QuickBase {
19+
1820
class QuickBase {
1921

2022
private $defaults = array(
@@ -74,7 +76,7 @@ final public function api($action, $options = array()){
7476

7577
}
7678

77-
class QuickBaseError extends Exception {
79+
class QuickBaseError extends \Exception {
7880

7981
protected $details;
8082

@@ -125,15 +127,15 @@ public function __construct(&$parent, $action = '', $options = array()){
125127
}
126128

127129
final public function actionRequest(){
128-
if(method_exists('QuickBaseRequest', $this->action)){
130+
if(method_exists('\QuickBase\QuickBaseRequest', $this->action)){
129131
QuickBaseRequest::{$this->action}($this);
130132
}
131133

132134
return $this;
133135
}
134136

135137
final public function actionResponse(){
136-
if(method_exists('QuickBaseResponse', $this->action)){
138+
if(method_exists('\QuickBase\QuickBaseResponse', $this->action)){
137139
QuickBaseResponse::{$this->action}($this, $this->response);
138140
}
139141

@@ -168,7 +170,7 @@ final public function constructPayload(){
168170
$this->payload = '';
169171

170172
if($this->settings['flags']['useXML']){
171-
$xmlDoc = new SimpleXMLElement(implode('', array(
173+
$xmlDoc = new \SimpleXMLElement(implode('', array(
172174
'<?xml version="1.0" encoding="',
173175
$this->options['encoding'],
174176
'"?>',
@@ -192,7 +194,7 @@ final public function constructPayload(){
192194
}
193195

194196
final public function checkForAndHandleError(){
195-
if($this->response['errcode'] != $this->settings['status']['errcode']){
197+
if(isset($this->response['errcode']) && $this->response['errcode'] != $this->settings['status']['errcode']){
196198
++$this->nErrors;
197199

198200
if($this->nErrors <= $this->parent->settings['maxErrorRetryAttempts'] && $this->response['errcode'] == 4 && isset($this->parent->settings['username']) && isset($this->parent->settings['password'])){
@@ -234,7 +236,7 @@ final public function processOptions(){
234236
}
235237

236238
foreach($this->options as $key => $value){
237-
if(method_exists('QuickBaseOption', $key)){
239+
if(method_exists('\QuickBase\QuickBaseOption', $key)){
238240
$this->options[$key] = QuickBaseOption::{$key}($value);
239241
}
240242
}
@@ -302,7 +304,7 @@ final public function transmit(){
302304
if($headers['Content-Type'] === 'application/xml'){
303305
$this->response = array();
304306

305-
$xml = new SimpleXmlIterator($body);
307+
$xml = new \SimpleXmlIterator($body);
306308

307309
$this->xml2Arr($xml, $this->response);
308310

@@ -316,7 +318,7 @@ final public function transmit(){
316318

317319
/* Helpers */
318320
final public static function arr2Obj(&$arr, $return = false){
319-
$obj = new stdClass;
321+
$obj = new \stdClass;
320322

321323
foreach($arr as $key => $val){
322324
if(!empty($key)){
@@ -1228,4 +1230,6 @@ final public static function slist($val){
12281230

12291231
}
12301232

1233+
} // End QuickBase Namespace
1234+
12311235
?>

tests/runAll.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
putenv('appid='.$argv[6]);
5959
}
6060

61-
$qb = new QuickBase(array(
61+
$qb = new \QuickBase\QuickBase(array(
6262
'realm' => getenv('realm'),
6363
'appToken' => getenv('appToken')
6464
));

0 commit comments

Comments
 (0)