diff --git a/configuration.php b/Lib/Configuration.php similarity index 89% rename from configuration.php rename to Lib/Configuration.php index 0528b6d..75dd2b8 100644 --- a/configuration.php +++ b/Lib/Configuration.php @@ -1,5 +1,7 @@ custom_config); if(! isset($configuration) || ! is_array($configuration)) { - throw new RuntimeException("You custom configuration in '{$this->custom_config}' must be in a variable named '\$configuration' and be an array."); + throw new \RuntimeException("You custom configuration in '{$this->custom_config}' must be in a variable named '\$configuration' and be an array."); } $this->values = array_replace_recursive($this->values, $configuration); @@ -74,7 +76,7 @@ class Configuration { $keys = explode('.', $key); foreach ($keys as $k) { if (!is_array($data)) { - throw new Exception("Try to access non-array as array, key '$key''"); + throw new \Exception("Try to access non-array as array, key '$key''"); } if (!isset($data[$k])) { return $default; diff --git a/Lib/Exception/BookNotFoundException.php b/Lib/Exception/BookNotFoundException.php new file mode 100644 index 0000000..f8eec20 --- /dev/null +++ b/Lib/Exception/BookNotFoundException.php @@ -0,0 +1,9 @@ +query = $query; + parent::__construct($message, 0); + } + + public function getSqlError() + { + return $this->getMessage().' while executing: '.$this->query; + } +} diff --git a/Lib/Exception/WebException.php b/Lib/Exception/WebException.php new file mode 100644 index 0000000..7476e72 --- /dev/null +++ b/Lib/Exception/WebException.php @@ -0,0 +1,24 @@ +excname = $name; + parent::__construct($reason, $code); + } + + public function getName() + { + return $this->excname; + } +} diff --git a/lib/BookSearch.php b/Lib/Search/BookSearch.php similarity index 94% rename from lib/BookSearch.php rename to Lib/Search/BookSearch.php index 80db9f7..d0d344b 100644 --- a/lib/BookSearch.php +++ b/Lib/Search/BookSearch.php @@ -1,5 +1,9 @@ getName(); $data["error"]["reason"] = $e->getMessage(); $this->log(sprintf("Failure : [%s] %s", $e->getCode(), $e->getName())); - } catch (Exception $e) { + } catch (\Exception $e) { $data["unexpected error"]["message"] = $e->getMessage(); $this->log(sprintf("Unexpected exception : %s", $e->getMessage())); } @@ -74,7 +78,7 @@ abstract class WebService throw new WebException ("CallFunction", "'func' method not available", -3); } - $rm = new ReflectionMethod ($this, $this->func); + $rm = new \ReflectionMethod($this, $this->func); $nbParams = count($params); $nbArgsFix = $rm->getNumberOfRequiredParameters(); $nbArgs = $rm->getNumberOfParameters(); diff --git a/lib/AudioBook.php b/Lib/db/AudioBook.php similarity index 97% rename from lib/AudioBook.php rename to Lib/db/AudioBook.php index 19a2f61..281350f 100644 --- a/lib/AudioBook.php +++ b/Lib/db/AudioBook.php @@ -1,6 +1,6 @@ results[] = $data; } }; - } catch (Exception $e) { + } catch (\Exception $e) { print($e->getMessage()); } @@ -137,7 +142,7 @@ class OdbcResultSet implements Iterator, ArrayAccess public function offsetUnset($offset) { - throw new RuntimeException("This makes no sense at all."); + throw new \RuntimeException("This makes no sense at all."); } // Iterator diff --git a/lib/DbMapping.php b/Lib/db/DbMapping.php similarity index 91% rename from lib/DbMapping.php rename to Lib/db/DbMapping.php index 416c763..219abc8 100644 --- a/lib/DbMapping.php +++ b/Lib/db/DbMapping.php @@ -1,5 +1,9 @@ addSortField('author', SolrQuery::ORDER_ASC); - $bs->addSortField('title', SolrQuery::ORDER_ASC); + $bs->addSortField('author', \SolrQuery::ORDER_ASC); + $bs->addSortField('title', \SolrQuery::ORDER_ASC); $bs->addSortField('producerCode'); - $bs->addSortField('mediaType', SolrQuery::ORDER_ASC); + $bs->addSortField('mediaType', \SolrQuery::ORDER_ASC); } else { $bs->addSortField('availabilityDate'); - $bs->addSortField('author', SolrQuery::ORDER_ASC); - $bs->addSortField('title', SolrQuery::ORDER_ASC); + $bs->addSortField('author', \SolrQuery::ORDER_ASC); + $bs->addSortField('title', \SolrQuery::ORDER_ASC); } if (isset($queryArray['queryText']) && strlen($queryArray['queryText']) > 0) { @@ -443,7 +440,7 @@ class NetBiblio extends WebService }); if (count($selectedGenres) > 0) { $selectedGenres = array_map(function ($c) { - return 'genreCode:'.SolrUtils::escapeQueryChars($c); + return 'genreCode:'.\SolrUtils::escapeQueryChars($c); }, $selectedGenres); $bs->addQuery('('.implode(' OR ', $selectedGenres).')', null, false); } @@ -516,7 +513,7 @@ class NetBiblio extends WebService try { $results = $s->getResults(0, $itemsByGroup); - } catch(SolrClientException $e) { + } catch(\SolrClientException $e) { throw new WebException ("SolrError", $e->getMessage(), -710); } diff --git a/exceptions.php b/exceptions.php deleted file mode 100644 index 28b9d6e..0000000 --- a/exceptions.php +++ /dev/null @@ -1,49 +0,0 @@ -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 { } diff --git a/global.php b/global.php deleted file mode 100644 index 1900ebf..0000000 --- a/global.php +++ /dev/null @@ -1,5 +0,0 @@ -Run(); diff --git a/mobile.php b/mobile.php index f8a5a0a..a600d04 100644 --- a/mobile.php +++ b/mobile.php @@ -1,6 +1,4 @@ Run(); +// this file is here for compatibility purpose, do not delete +require_once('index.php'); \ No newline at end of file