From d5912072f2c327bf8b735c24371e01697de13d06 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 27 Sep 2016 08:20:02 +0200 Subject: [PATCH] =?UTF-8?q?Directorios=20reesctructurados,=20integraci?= =?UTF-8?q?=C3=B3n=20total=20con=20PHP=20autoload?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configure.php | 10 ++--- vn/db/conn.php => db/connection.php | 21 +++++---- {vn/db => db}/exception.php | 0 {vn/db => db}/my.cnf | 0 debian/install | 4 +- {vn/lib => lib}/app.php | 11 ++--- {vn/lib => lib}/cli-app.php | 2 - {vn/lib => lib}/exception.php | 0 {vn/lib => lib}/locale.php | 0 {vn/lib => lib}/log.php | 0 {vn/lib => lib}/method.php | 7 ++- lib/type.php | 69 +++++++++++++++++++++++++++++ {vn/lib => lib}/user-exception.php | 2 - {vn/lib => lib}/util.php | 0 vn-autoload.php | 41 +++++++++++++++++ vn/lib/type.php | 64 -------------------------- 16 files changed, 134 insertions(+), 97 deletions(-) rename vn/db/conn.php => db/connection.php (96%) rename {vn/db => db}/exception.php (100%) rename {vn/db => db}/my.cnf (100%) rename {vn/lib => lib}/app.php (93%) rename {vn/lib => lib}/cli-app.php (94%) rename {vn/lib => lib}/exception.php (100%) rename {vn/lib => lib}/locale.php (100%) rename {vn/lib => lib}/log.php (100%) rename {vn/lib => lib}/method.php (88%) create mode 100755 lib/type.php rename {vn/lib => lib}/user-exception.php (89%) rename {vn/lib => lib}/util.php (100%) create mode 100644 vn-autoload.php delete mode 100755 vn/lib/type.php diff --git a/configure.php b/configure.php index 6886043..4a9cf7d 100644 --- a/configure.php +++ b/configure.php @@ -1,9 +1,9 @@ diff --git a/vn/db/conn.php b/db/connection.php similarity index 96% rename from vn/db/conn.php rename to db/connection.php index a08dcf0..19af362 100755 --- a/vn/db/conn.php +++ b/db/connection.php @@ -2,10 +2,9 @@ namespace Vn\Db; -require_once ('vn/lib/type.php'); -require_once ('vn/db/exception.php'); +use Vn\Lib\Type; -class Conn +class Connection { private $conn = NULL; private $isOpen = FALSE; @@ -74,7 +73,7 @@ class Conn /** * Returns the internal database connection handler. This function shoud be * used to set options for specific databases that could not be set using - * the Db\Conn class methods. + * the Connection class methods. * * @return Objetct The connection handler **/ @@ -314,7 +313,7 @@ class Conn /** * Check if there has been an error in the last query or multiquery, - * throwing a @Db\Exception exception if any. + * throwing a @Exception exception if any. **/ function checkError () { @@ -378,17 +377,17 @@ class Conn function renderValue ($value) { if ($value !== NULL) - switch (get_type ($value)) + switch (Type::get ($value)) { - case TYPE_BOOLEAN: + case Type::BOOLEAN: return ($value) ? 'TRUE' : 'FALSE'; - case TYPE_STRING: + case Type::STRING: return '\'' . $this->conn->escape_string ($value) . '\''; - case TYPE_DATE: + case Type::DATE: return strftime ('\'%Y-%m-%d\'', $value->getTimestamp ()); - case TYPE_TIME: + case Type::TIME: return strftime ('\'%T\'', $value->getTimestamp ()); - case TYPE_DATE_TIME: + case Type::DATE_TIME: return strftime ('\'%Y-%m-%d %T\'', $value->getTimestamp ()); default: return '\'' . $this->conn->escape_string ($value) . '\''; diff --git a/vn/db/exception.php b/db/exception.php similarity index 100% rename from vn/db/exception.php rename to db/exception.php diff --git a/vn/db/my.cnf b/db/my.cnf similarity index 100% rename from vn/db/my.cnf rename to db/my.cnf diff --git a/debian/install b/debian/install index c890672..061d44c 100644 --- a/debian/install +++ b/debian/install @@ -1 +1,3 @@ -vn usr/share/php +lib usr/share/php/vn +db usr/share/php/vn +vn-autoload.php usr/share/php diff --git a/vn/lib/app.php b/lib/app.php similarity index 93% rename from vn/lib/app.php rename to lib/app.php index ca81e20..2065766 100644 --- a/vn/lib/app.php +++ b/lib/app.php @@ -2,14 +2,9 @@ namespace Vn\Lib; -require_once (__DIR__.'/method.php'); -require_once (__DIR__.'/exception.php'); -require_once (__DIR__.'/user-exception.php'); -require_once (__DIR__.'/locale.php'); -require_once (__DIR__.'/util.php'); -require_once ('vn/db/conn.php'); +require_once __DIR__.'/util.php'; -use Vn\Db\Conn; +use Vn\Db\Connection; use Vn\Lib\Locale; if (!defined ('_DEBUG_MODE')) @@ -106,7 +101,7 @@ class App if ($persistent) $host = 'p:'.$host; - $conn = new Conn (); + $conn = new Connection (); $conn->open ( $host ,$user diff --git a/vn/lib/cli-app.php b/lib/cli-app.php similarity index 94% rename from vn/lib/cli-app.php rename to lib/cli-app.php index 052bae1..057cda6 100755 --- a/vn/lib/cli-app.php +++ b/lib/cli-app.php @@ -2,8 +2,6 @@ namespace Vn\Lib; -require_once (__DIR__.'/app.php'); - /** * Implements command line applications. **/ diff --git a/vn/lib/exception.php b/lib/exception.php similarity index 100% rename from vn/lib/exception.php rename to lib/exception.php diff --git a/vn/lib/locale.php b/lib/locale.php similarity index 100% rename from vn/lib/locale.php rename to lib/locale.php diff --git a/vn/lib/log.php b/lib/log.php similarity index 100% rename from vn/lib/log.php rename to lib/log.php diff --git a/vn/lib/method.php b/lib/method.php similarity index 88% rename from vn/lib/method.php rename to lib/method.php index 92faf4f..1e9a5b1 100644 --- a/vn/lib/method.php +++ b/lib/method.php @@ -2,8 +2,6 @@ namespace Vn\Lib; -require_once (__DIR__.'/app.php'); - /** * Base class for rest methods. **/ @@ -25,14 +23,15 @@ abstract class Method /** * Executes the method. Shoud be defined by child classes. * + * @param {Db\Conn} $db The main database connection * @return mixed The result of the method **/ - abstract function run (); + abstract function run ($db); /** * Returns the system database connection. * - * return Db\Conn The database connection + * return {Db\Conn} The database connection **/ function getSysConn () { diff --git a/lib/type.php b/lib/type.php new file mode 100755 index 0000000..65e3d03 --- /dev/null +++ b/lib/type.php @@ -0,0 +1,69 @@ + diff --git a/vn/lib/user-exception.php b/lib/user-exception.php similarity index 89% rename from vn/lib/user-exception.php rename to lib/user-exception.php index c234dfd..8e884c7 100755 --- a/vn/lib/user-exception.php +++ b/lib/user-exception.php @@ -2,8 +2,6 @@ namespace Vn\Lib; -require_once (__DIR__.'/exception.php'); - /** * Class used to store information about errors, warnings and info messages, * that end users understood and are allowed to see. diff --git a/vn/lib/util.php b/lib/util.php similarity index 100% rename from vn/lib/util.php rename to lib/util.php diff --git a/vn-autoload.php b/vn-autoload.php new file mode 100644 index 0000000..bfe4bb4 --- /dev/null +++ b/vn-autoload.php @@ -0,0 +1,41 @@ + $location) + { + $prefixLen = strlen ($prefix); + + if (strncmp ($classPath, $prefix, $prefixLen) == 0) + { + $classPath = "$location/". substr ($classPath, $prefixLen); + break; + } + } + + if ($classPath{0} != DIRECTORY_SEPARATOR) + $classPath = stream_resolve_include_path ($classPath); + + if (file_exists ($classPath)) + require_once $classPath; +}); + +?> diff --git a/vn/lib/type.php b/vn/lib/type.php deleted file mode 100755 index f91f5f2..0000000 --- a/vn/lib/type.php +++ /dev/null @@ -1,64 +0,0 @@ -