PSR-4 compliance & autoloader
parent
6690b9fe55
commit
ab2092e9c3
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BSR\Lib\Exception;
|
||||||
|
|
||||||
|
class BookNotFoundException extends WebException {
|
||||||
|
public function __construct($code) {
|
||||||
|
parent::__construct('BookNotFound', "The book with code $code was not found", -404);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BSR\Lib\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception raised when an invalid attribute name is accessed
|
||||||
|
*/
|
||||||
|
class InvalidAttributeException extends \Exception { }
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BSR\Lib\Exception;
|
||||||
|
|
||||||
|
class SqlException extends \Exception
|
||||||
|
{
|
||||||
|
private $query;
|
||||||
|
|
||||||
|
public function __construct($message = "Sql Error", $query = "")
|
||||||
|
{
|
||||||
|
$this->query = $query;
|
||||||
|
parent::__construct($message, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSqlError()
|
||||||
|
{
|
||||||
|
return $this->getMessage().' while executing: '.$this->query;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BSR\Lib\Exception;
|
||||||
|
|
||||||
|
class WebException extends \Exception
|
||||||
|
{
|
||||||
|
private $excname;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param string $reason
|
||||||
|
* @param int $code
|
||||||
|
*/
|
||||||
|
function __construct($name, $reason, $code)
|
||||||
|
{
|
||||||
|
$this->excname = $name;
|
||||||
|
parent::__construct($reason, $code);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->excname;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace BSR\Lib\Search;
|
||||||
|
|
||||||
|
use BSR\Lib\Configuration;
|
||||||
|
|
||||||
mb_http_output('UTF-8');
|
mb_http_output('UTF-8');
|
||||||
|
|
||||||
class BookSearch
|
class BookSearch
|
||||||
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once('DbMapping.php');
|
namespace BSR\Lib\db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AudioBook is mapped on a Notice from NetBiblio
|
* AudioBook is mapped on a Notice from NetBiblio
|
||||||
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once('DbMapping.php');
|
|
||||||
require_once('AudioBook.php');
|
namespace BSR\Lib\db;
|
||||||
|
use BSR\Lib\Configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User is mapped on the Useraccounts table. Contains user information : id, login, firstName, lastName, displayName.
|
* User is mapped on the Useraccounts table. Contains user information : id, login, firstName, lastName, displayName.
|
||||||
@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class WebException extends Exception
|
|
||||||
{
|
|
||||||
private $excname;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param string $reason
|
|
||||||
* @param int $code
|
|
||||||
*/
|
|
||||||
function __construct($name, $reason, $code)
|
|
||||||
{
|
|
||||||
$this->excname = $name;
|
|
||||||
parent::__construct($reason, $code);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->excname;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SqlException extends Exception
|
|
||||||
{
|
|
||||||
private $query;
|
|
||||||
|
|
||||||
public function __construct($message = "Sql Error", $query = "")
|
|
||||||
{
|
|
||||||
$this->query = $query;
|
|
||||||
parent::__construct($message, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSqlError()
|
|
||||||
{
|
|
||||||
return $this->getMessage().' while executing: '.$this->query;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BookNotFoundException extends WebException {
|
|
||||||
public function __construct($code) {
|
|
||||||
parent::__construct('BookNotFound', "The book with code $code was not found", -404);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception raised when an invalid attribute name is accessed
|
|
||||||
*/
|
|
||||||
class InvalidAttributeException extends Exception { }
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
require_once('exceptions.php');
|
|
||||||
require_once('configuration.php');
|
|
||||||
require_once('lib/Connection.php');
|
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BSR;
|
||||||
|
|
||||||
|
ini_set('display_errors', 'On');
|
||||||
|
|
||||||
|
// register an autoloader to automatically load classes
|
||||||
|
// the namespace for the class must begin with BSR and
|
||||||
|
// otherwise respect the PSR-4 standard
|
||||||
|
spl_autoload_register(function ($class) {
|
||||||
|
$class = substr($class, strlen('BSR'));
|
||||||
|
$path = sprintf('%s/%s.php', __DIR__, str_replace('\\', '/', $class));
|
||||||
|
|
||||||
|
if (file_exists($path)) {
|
||||||
|
require $path;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$web = new NetBiblio();
|
||||||
|
$web->Run();
|
||||||
@ -1,6 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once "mobile.netbiblio.php";
|
// this file is here for compatibility purpose, do not delete
|
||||||
|
require_once('index.php');
|
||||||
$web = new NetBiblio();
|
|
||||||
$web->Run();
|
|
||||||
Loading…
Reference in New Issue