Skip to content

Commit

Permalink
Autoloader bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex014 committed May 9, 2017
1 parent ad54335 commit 9c112b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 10 additions & 5 deletions autoloader.php
Expand Up @@ -6,7 +6,7 @@ class libAutoloader {

public function __construct() {
if(!self::$registered) {
spl_autoload_register(array($this, 'loader'), true, true);
spl_autoload_register(array($this, 'loader'), true, false);
self::$registered = true;
}
}
Expand All @@ -15,8 +15,13 @@ private function loader($className) {
$path = explode('\\', $className);
$path = implode('/', $path);
$fileName = __DIR__.'/'.$path.'.php';

require_once $fileName;
return true;

if(file_exists($fileName)) {
require_once $fileName;
return true;
}
else {
return false;
}
}
}
}
10 changes: 5 additions & 5 deletions darkblog/lib/jsonRPCclient.php
Expand Up @@ -99,15 +99,15 @@ public function __call($method,$params) {

// check
if (!is_scalar($method)) {
throw new Exception('Method name has no scalar value');
throw new \Exception('Method name has no scalar value');
}

// check
if (is_array($params)) {
// no keys
$params = array_values($params);
} else {
throw new Exception('Params must be given as array');
throw new \Exception('Params must be given as array');
}

// sets notification or request task
Expand Down Expand Up @@ -137,7 +137,7 @@ public function __call($method,$params) {
$responce = curl_exec($ch);

if(!is_string($responce)) {
throw new Exception("Can't connect to: ".$this->url.' '.curl_error ( $ch ));
throw new \Exception("Can't connect to: ".$this->url.' '.curl_error ( $ch ));
}

$responce = json_decode($responce,true);
Expand All @@ -152,11 +152,11 @@ public function __call($method,$params) {
if (!$this->notification) {
// check
if ($responce['id'] != $currentId) {
throw new Exception('Incorrect response id (request id: '.$currentId.', response id: '.$responce['id'].')');
throw new \Exception('Incorrect response id (request id: '.$currentId.', response id: '.$responce['id'].')');
}
if (!is_null($responce['error'])) {
jsonRPCClient::$error = $responce['error'];
throw new Exception('Request error: '.$responce['error']);
throw new \Exception('Request error: '.$responce['error']['message']);
}

return $responce['result'];
Expand Down

0 comments on commit 9c112b8

Please sign in to comment.