Git hook, dependencies fixed, linting, bugfixes
This commit is contained in:
parent
363f1718be
commit
193f67b570
|
@ -23,12 +23,11 @@ class Connection
|
||||||
* @param string $name The default schema name
|
* @param string $name The default schema name
|
||||||
*
|
*
|
||||||
* @return boolean %TRUE on success, %FALSE otherwise
|
* @return boolean %TRUE on success, %FALSE otherwise
|
||||||
**/
|
*/
|
||||||
function open ($host, $user, $pass, $name, $port = NULL)
|
function open ($host, $user, $pass, $name, $port = NULL)
|
||||||
{
|
{
|
||||||
$conn = $this->initHandler ();
|
$conn = $this->initHandler ();
|
||||||
$conn->options (MYSQLI_OPT_LOCAL_INFILE, TRUE);
|
$conn->options (MYSQLI_OPT_LOCAL_INFILE, TRUE);
|
||||||
$conn->options (MYSQLI_READ_DEFAULT_FILE, __DIR__.'/my.cnf');
|
|
||||||
$conn->real_connect ($host, $user, $pass, $name, $port);
|
$conn->real_connect ($host, $user, $pass, $name, $port);
|
||||||
|
|
||||||
if (mysqli_connect_errno ())
|
if (mysqli_connect_errno ())
|
||||||
|
@ -45,7 +44,7 @@ class Connection
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the current connection, if it's closed does nothing.
|
* Closes the current connection, if it's closed does nothing.
|
||||||
**/
|
*/
|
||||||
function close ()
|
function close ()
|
||||||
{
|
{
|
||||||
if ($this->isOpen)
|
if ($this->isOpen)
|
||||||
|
@ -61,7 +60,7 @@ class Connection
|
||||||
* Initializes the internal database connection handler.
|
* Initializes the internal database connection handler.
|
||||||
*
|
*
|
||||||
* @return Objetct The connection handler
|
* @return Objetct The connection handler
|
||||||
**/
|
*/
|
||||||
function initHandler ()
|
function initHandler ()
|
||||||
{
|
{
|
||||||
if (!$this->conn)
|
if (!$this->conn)
|
||||||
|
@ -76,7 +75,7 @@ class Connection
|
||||||
* the Connection class methods.
|
* the Connection class methods.
|
||||||
*
|
*
|
||||||
* @return Objetct The connection handler
|
* @return Objetct The connection handler
|
||||||
**/
|
*/
|
||||||
function getHandler ()
|
function getHandler ()
|
||||||
{
|
{
|
||||||
return $this->conn;
|
return $this->conn;
|
||||||
|
@ -87,7 +86,7 @@ class Connection
|
||||||
*
|
*
|
||||||
* @param string $schema The schema name
|
* @param string $schema The schema name
|
||||||
* @return boolean %TRUE if success, %FALSE otherwise
|
* @return boolean %TRUE if success, %FALSE otherwise
|
||||||
**/
|
*/
|
||||||
function selectDb ($dbName)
|
function selectDb ($dbName)
|
||||||
{
|
{
|
||||||
return $this->conn->select_db ($dbName);
|
return $this->conn->select_db ($dbName);
|
||||||
|
@ -100,7 +99,7 @@ class Connection
|
||||||
* @param mixed[] $params The query parameters
|
* @param mixed[] $params The query parameters
|
||||||
*
|
*
|
||||||
* @return mixed The value or %NULL if error
|
* @return mixed The value or %NULL if error
|
||||||
**/
|
*/
|
||||||
function query ($query, $params = NULL)
|
function query ($query, $params = NULL)
|
||||||
{
|
{
|
||||||
$result = $this->conn->query ($this->render ($query, $params));
|
$result = $this->conn->query ($this->render ($query, $params));
|
||||||
|
@ -118,7 +117,7 @@ class Connection
|
||||||
* Checks whether the connection is open.
|
* Checks whether the connection is open.
|
||||||
*
|
*
|
||||||
* @return boolean %TRUE if connection is open, %FALSE otherwise
|
* @return boolean %TRUE if connection is open, %FALSE otherwise
|
||||||
**/
|
*/
|
||||||
function isOpen ()
|
function isOpen ()
|
||||||
{
|
{
|
||||||
return $this->isOpen;
|
return $this->isOpen;
|
||||||
|
@ -130,7 +129,7 @@ class Connection
|
||||||
* @param resource $result The database result
|
* @param resource $result The database result
|
||||||
*
|
*
|
||||||
* @return mixed[] An associative array with the first row, %NULL if error
|
* @return mixed[] An associative array with the first row, %NULL if error
|
||||||
**/
|
*/
|
||||||
function getRowFromResult ($result)
|
function getRowFromResult ($result)
|
||||||
{
|
{
|
||||||
if ($result)
|
if ($result)
|
||||||
|
@ -149,7 +148,7 @@ class Connection
|
||||||
* @param resource $result The database result
|
* @param resource $result The database result
|
||||||
*
|
*
|
||||||
* @return object An object with the first row, %NULL if error
|
* @return object An object with the first row, %NULL if error
|
||||||
**/
|
*/
|
||||||
function getObjectFromResult ($result)
|
function getObjectFromResult ($result)
|
||||||
{
|
{
|
||||||
if ($result)
|
if ($result)
|
||||||
|
@ -168,7 +167,7 @@ class Connection
|
||||||
* @param resource $result The database result
|
* @param resource $result The database result
|
||||||
*
|
*
|
||||||
* @return mixed The value or %NULL if error
|
* @return mixed The value or %NULL if error
|
||||||
**/
|
*/
|
||||||
function getValueFromResult ($result)
|
function getValueFromResult ($result)
|
||||||
{
|
{
|
||||||
$value = NULL;
|
$value = NULL;
|
||||||
|
@ -193,7 +192,7 @@ class Connection
|
||||||
* @param mixed[] $params The query parameters
|
* @param mixed[] $params The query parameters
|
||||||
*
|
*
|
||||||
* @return mixed[] An associative array with the first row, %NULL if error
|
* @return mixed[] An associative array with the first row, %NULL if error
|
||||||
**/
|
*/
|
||||||
function getRow ($query, $params = NULL)
|
function getRow ($query, $params = NULL)
|
||||||
{
|
{
|
||||||
$result = $this->query ($query, $params);
|
$result = $this->query ($query, $params);
|
||||||
|
@ -207,7 +206,7 @@ class Connection
|
||||||
* @param mixed[] $params The query parameters
|
* @param mixed[] $params The query parameters
|
||||||
*
|
*
|
||||||
* @return object An object with the first row, %NULL if error
|
* @return object An object with the first row, %NULL if error
|
||||||
**/
|
*/
|
||||||
function getObject ($query, $params = NULL)
|
function getObject ($query, $params = NULL)
|
||||||
{
|
{
|
||||||
$result = $this->query ($query, $params);
|
$result = $this->query ($query, $params);
|
||||||
|
@ -221,7 +220,7 @@ class Connection
|
||||||
* @param mixed[] $params The query parameters
|
* @param mixed[] $params The query parameters
|
||||||
*
|
*
|
||||||
* @return mixed The value or %NULL if error
|
* @return mixed The value or %NULL if error
|
||||||
**/
|
*/
|
||||||
function getValue ($query, $params = NULL)
|
function getValue ($query, $params = NULL)
|
||||||
{
|
{
|
||||||
$result = $this->query ($query, $params);
|
$result = $this->query ($query, $params);
|
||||||
|
@ -235,7 +234,7 @@ class Connection
|
||||||
* @param mixed[] $params The query parameters
|
* @param mixed[] $params The query parameters
|
||||||
*
|
*
|
||||||
* @return mixed The query string
|
* @return mixed The query string
|
||||||
**/
|
*/
|
||||||
function loadFromFile ($file, $params = NULL)
|
function loadFromFile ($file, $params = NULL)
|
||||||
{
|
{
|
||||||
$query = file_get_contents ($file .'.sql');
|
$query = file_get_contents ($file .'.sql');
|
||||||
|
@ -253,7 +252,7 @@ class Connection
|
||||||
* @param mixed[] $params The query parameters
|
* @param mixed[] $params The query parameters
|
||||||
*
|
*
|
||||||
* @return mixed The value or %NULL if error
|
* @return mixed The value or %NULL if error
|
||||||
**/
|
*/
|
||||||
function queryFromFile ($file, $params = NULL)
|
function queryFromFile ($file, $params = NULL)
|
||||||
{
|
{
|
||||||
$query = $this->loadFromFile ($file, $params);
|
$query = $this->loadFromFile ($file, $params);
|
||||||
|
@ -271,7 +270,7 @@ class Connection
|
||||||
* @param mixed[] $params The query parameters
|
* @param mixed[] $params The query parameters
|
||||||
*
|
*
|
||||||
* @return mixed[] An associative array with the first row, %NULL if error
|
* @return mixed[] An associative array with the first row, %NULL if error
|
||||||
**/
|
*/
|
||||||
function getRowFromFile ($file, $params = NULL)
|
function getRowFromFile ($file, $params = NULL)
|
||||||
{
|
{
|
||||||
$result = $this->queryFromFile ($file, $params);
|
$result = $this->queryFromFile ($file, $params);
|
||||||
|
@ -285,7 +284,7 @@ class Connection
|
||||||
* @param mixed[] $params The query parameters
|
* @param mixed[] $params The query parameters
|
||||||
*
|
*
|
||||||
* @return mixed The value or %NULL if error
|
* @return mixed The value or %NULL if error
|
||||||
**/
|
*/
|
||||||
function getValueFromFile ($file, $params = NULL)
|
function getValueFromFile ($file, $params = NULL)
|
||||||
{
|
{
|
||||||
$result = $this->queryFromFile ($file, $params);
|
$result = $this->queryFromFile ($file, $params);
|
||||||
|
@ -299,7 +298,7 @@ class Connection
|
||||||
* @param mixed[] $params The query parameters
|
* @param mixed[] $params The query parameters
|
||||||
*
|
*
|
||||||
* @return mixed The value or %NULL if error
|
* @return mixed The value or %NULL if error
|
||||||
**/
|
*/
|
||||||
function multiQuery ($query, $params = NULL)
|
function multiQuery ($query, $params = NULL)
|
||||||
{
|
{
|
||||||
$success = $this->conn->multi_query ($this->render ($query, $params));
|
$success = $this->conn->multi_query ($this->render ($query, $params));
|
||||||
|
@ -316,7 +315,7 @@ class Connection
|
||||||
* @param string $query The SQL query
|
* @param string $query The SQL query
|
||||||
*
|
*
|
||||||
* @return mixed The statement object or %FALSE if an error occurred
|
* @return mixed The statement object or %FALSE if an error occurred
|
||||||
**/
|
*/
|
||||||
function prepare ($query)
|
function prepare ($query)
|
||||||
{
|
{
|
||||||
return $this->conn->prepare ($query);
|
return $this->conn->prepare ($query);
|
||||||
|
@ -347,7 +346,7 @@ class Connection
|
||||||
/**
|
/**
|
||||||
* Check if there has been an error in the last query or multiquery,
|
* Check if there has been an error in the last query or multiquery,
|
||||||
* throwing a @Exception exception if any.
|
* throwing a @Exception exception if any.
|
||||||
**/
|
*/
|
||||||
function checkError ()
|
function checkError ()
|
||||||
{
|
{
|
||||||
if ($this->conn->errno)
|
if ($this->conn->errno)
|
||||||
|
@ -358,7 +357,7 @@ class Connection
|
||||||
* Check if there have been warnings in the last query.
|
* Check if there have been warnings in the last query.
|
||||||
*
|
*
|
||||||
* @return boolean %TRUE if there have been warnings %FALSE otherwise
|
* @return boolean %TRUE if there have been warnings %FALSE otherwise
|
||||||
**/
|
*/
|
||||||
function checkWarnings ()
|
function checkWarnings ()
|
||||||
{
|
{
|
||||||
return $this->conn->warning_count > 0;
|
return $this->conn->warning_count > 0;
|
||||||
|
@ -371,7 +370,7 @@ class Connection
|
||||||
* @param mixed[] $paramsMap The query parameters
|
* @param mixed[] $paramsMap The query parameters
|
||||||
*
|
*
|
||||||
* @return string The rendered SQL string
|
* @return string The rendered SQL string
|
||||||
**/
|
*/
|
||||||
function render ($query, $paramsMap = NULL)
|
function render ($query, $paramsMap = NULL)
|
||||||
{
|
{
|
||||||
if (isset ($paramsMap) && is_array ($paramsMap) && count ($paramsMap) > 0)
|
if (isset ($paramsMap) && is_array ($paramsMap) && count ($paramsMap) > 0)
|
||||||
|
@ -406,7 +405,7 @@ class Connection
|
||||||
* @param mixed $value The value
|
* @param mixed $value The value
|
||||||
*
|
*
|
||||||
* @return string The SQL value
|
* @return string The SQL value
|
||||||
**/
|
*/
|
||||||
function renderValue ($value)
|
function renderValue ($value)
|
||||||
{
|
{
|
||||||
if ($value !== NULL)
|
if ($value !== NULL)
|
||||||
|
@ -429,4 +428,3 @@ class Connection
|
||||||
return 'NULL';
|
return 'NULL';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,4 +16,3 @@ class Exception extends \Exception
|
||||||
parent::__construct ($message, $code);
|
parent::__construct ($message, $code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
php-vn-lib (2.1.2) stable; urgency=low
|
php-vn-lib (2.1.3) stable; urgency=low
|
||||||
|
|
||||||
* Initial Release.
|
* Initial Release.
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,11 @@ Build-Depends: build-essential, debhelper
|
||||||
Standards-Version: 3.9.3
|
Standards-Version: 3.9.3
|
||||||
Section: misc
|
Section: misc
|
||||||
Homepage: http://www.verdnatura.es
|
Homepage: http://www.verdnatura.es
|
||||||
Vcs-Git: git://www.verdnatura.es/var/git/php-vn-lib
|
Vcs-Git: https://gitverdnatura.es/php-vn-lib
|
||||||
|
|
||||||
Package: php-vn-lib
|
Package: php-vn-lib
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: php5-mysql
|
Depends: php-mysql
|
||||||
Section: misc
|
Section: misc
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Description: PHP libraries
|
Description: PHP libraries
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Format: http://dep.debian.net/deps/dep5
|
Format: http://dep.debian.net/deps/dep5
|
||||||
Name: php-vn-lib
|
Name: php-vn-lib
|
||||||
Source: git://www.verdnatura.es/var/git/php-vn-lib
|
Source: https://git.verdnatura.es/php-vn-lib
|
||||||
|
|
||||||
Files: *
|
Files: *
|
||||||
Copyright: 2011-2015 Juan Ferrer Toribio <juan@verdnatura.es>
|
Copyright: 2011-2015 Juan Ferrer Toribio <juan@verdnatura.es>
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
vn-debuild
|
||||||
|
vn-deploy root@www1.static root@www2.static
|
|
@ -5,4 +5,3 @@ set_include_path (__DIR__.PATH_SEPARATOR.get_include_path ());
|
||||||
$vnAutoloadMap = [];
|
$vnAutoloadMap = [];
|
||||||
$vnAutoloadMap['vn/lib'] = __DIR__.'/lib';
|
$vnAutoloadMap['vn/lib'] = __DIR__.'/lib';
|
||||||
$vnAutoloadMap['vn/db'] = __DIR__.'/db';
|
$vnAutoloadMap['vn/db'] = __DIR__.'/db';
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ if (!defined ('_DATA_DIR'))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for applications.
|
* Base class for applications.
|
||||||
**/
|
*/
|
||||||
class App
|
class App
|
||||||
{
|
{
|
||||||
protected $name;
|
protected $name;
|
||||||
|
@ -32,7 +32,7 @@ class App
|
||||||
* Creates a new application object.
|
* Creates a new application object.
|
||||||
*
|
*
|
||||||
* @param name string The application name
|
* @param name string The application name
|
||||||
**/
|
*/
|
||||||
function __construct ($name, $methodDir = NULL)
|
function __construct ($name, $methodDir = NULL)
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
|
@ -43,7 +43,7 @@ class App
|
||||||
* Returns the name of the application.
|
* Returns the name of the application.
|
||||||
*
|
*
|
||||||
* @return The application name
|
* @return The application name
|
||||||
**/
|
*/
|
||||||
function getName ()
|
function getName ()
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
|
@ -53,7 +53,7 @@ class App
|
||||||
* Returns the configuration object.
|
* Returns the configuration object.
|
||||||
*
|
*
|
||||||
* @return The config object
|
* @return The config object
|
||||||
**/
|
*/
|
||||||
function getConf ()
|
function getConf ()
|
||||||
{
|
{
|
||||||
return $this->conf;
|
return $this->conf;
|
||||||
|
@ -62,7 +62,7 @@ class App
|
||||||
/**
|
/**
|
||||||
* Initializes Application. Should be the first called function in any
|
* Initializes Application. Should be the first called function in any
|
||||||
* application that uses this class.
|
* application that uses this class.
|
||||||
**/
|
*/
|
||||||
function init ()
|
function init ()
|
||||||
{
|
{
|
||||||
ini_set ('log_errors', TRUE);
|
ini_set ('log_errors', TRUE);
|
||||||
|
@ -77,7 +77,7 @@ class App
|
||||||
/**
|
/**
|
||||||
* Deinitializes the Application. When init method is called, this
|
* Deinitializes the Application. When init method is called, this
|
||||||
* function is called automatically at the end of the script.
|
* function is called automatically at the end of the script.
|
||||||
**/
|
*/
|
||||||
function deinit ()
|
function deinit ()
|
||||||
{
|
{
|
||||||
if ($this->sysConn)
|
if ($this->sysConn)
|
||||||
|
@ -89,13 +89,15 @@ class App
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the configuration file name.
|
* Gets the configuration file name.
|
||||||
**/
|
*/
|
||||||
function getConfigFile ()
|
function getConfigFile ()
|
||||||
{
|
{
|
||||||
$configDir = _CONFIG_DIR .'/'. $this->name;
|
$configDir = _CONFIG_DIR .'/'. $this->name;
|
||||||
$customFile = "$configDir/config.my.php";
|
$customFile = "$configDir/config.my.php";
|
||||||
|
|
||||||
if (file_exists ($customFile))
|
if (file_exists ('config.php'))
|
||||||
|
return 'config.php';
|
||||||
|
else if (file_exists ($customFile))
|
||||||
return $customFile;
|
return $customFile;
|
||||||
else
|
else
|
||||||
return "$configDir/config.php";
|
return "$configDir/config.php";
|
||||||
|
@ -104,7 +106,7 @@ class App
|
||||||
/**
|
/**
|
||||||
* Creates a new connection object using the configuration parameters and
|
* Creates a new connection object using the configuration parameters and
|
||||||
* the passed user and password.
|
* the passed user and password.
|
||||||
**/
|
*/
|
||||||
function createConnection ($user, $password, $persistent = FALSE)
|
function createConnection ($user, $password, $persistent = FALSE)
|
||||||
{
|
{
|
||||||
$dbConf = $this->conf['db'];
|
$dbConf = $this->conf['db'];
|
||||||
|
@ -129,7 +131,7 @@ class App
|
||||||
* Opens the system database connection.
|
* Opens the system database connection.
|
||||||
*
|
*
|
||||||
* @return Vn\Db\Conn The connection
|
* @return Vn\Db\Conn The connection
|
||||||
**/
|
*/
|
||||||
function getSysConn ()
|
function getSysConn ()
|
||||||
{
|
{
|
||||||
if (!$this->sysConn)
|
if (!$this->sysConn)
|
||||||
|
@ -144,12 +146,12 @@ class App
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the application. Should be implemented by child classes.
|
* Starts the application. Should be implemented by child classes.
|
||||||
**/
|
*/
|
||||||
function run () {}
|
function run () {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs a method.
|
* Runs a method.
|
||||||
**/
|
*/
|
||||||
function loadMethod ($methodUri = NULL, $checkClass = NULL, $baseDir = NULL)
|
function loadMethod ($methodUri = NULL, $checkClass = NULL, $baseDir = NULL)
|
||||||
{
|
{
|
||||||
// XXX: Partially implemented
|
// XXX: Partially implemented
|
||||||
|
@ -190,4 +192,3 @@ class App
|
||||||
return new $className ($this);
|
return new $className ($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,4 +71,3 @@ class Log
|
||||||
self::$count = 0;
|
self::$count = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ namespace Vn\Lib;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for rest methods.
|
* Base class for rest methods.
|
||||||
**/
|
*/
|
||||||
abstract class Method
|
abstract class Method
|
||||||
{
|
{
|
||||||
protected $app;
|
protected $app;
|
||||||
|
@ -14,7 +14,7 @@ abstract class Method
|
||||||
* Initializes the method.
|
* Initializes the method.
|
||||||
*
|
*
|
||||||
* @param app Lib\App The application
|
* @param app Lib\App The application
|
||||||
**/
|
*/
|
||||||
function __construct ($app)
|
function __construct ($app)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
|
@ -25,14 +25,14 @@ abstract class Method
|
||||||
*
|
*
|
||||||
* @param {Db\Conn} $db The main database connection
|
* @param {Db\Conn} $db The main database connection
|
||||||
* @return mixed The result of the method
|
* @return mixed The result of the method
|
||||||
**/
|
*/
|
||||||
abstract function run ($db);
|
abstract function run ($db);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the system database connection.
|
* Returns the system database connection.
|
||||||
*
|
*
|
||||||
* return {Db\Conn} The database connection
|
* return {Db\Conn} The database connection
|
||||||
**/
|
*/
|
||||||
function getSysConn ()
|
function getSysConn ()
|
||||||
{
|
{
|
||||||
return $this->app->getSysConn ();
|
return $this->app->getSysConn ();
|
||||||
|
@ -45,7 +45,7 @@ abstract class Method
|
||||||
* @param {string} $map The map to check
|
* @param {string} $map The map to check
|
||||||
* @param {array} $params The list of keys to check
|
* @param {array} $params The list of keys to check
|
||||||
* @return {boolean} %TRUE if all key are defined, %FALSE otherwise
|
* @return {boolean} %TRUE if all key are defined, %FALSE otherwise
|
||||||
**/
|
*/
|
||||||
function checkParams ($map, $params)
|
function checkParams ($map, $params)
|
||||||
{
|
{
|
||||||
if (!isset ($map))
|
if (!isset ($map))
|
||||||
|
|
|
@ -37,4 +37,3 @@ spl_autoload_register (function ($className)
|
||||||
if (file_exists ($classPath))
|
if (file_exists ($classPath))
|
||||||
require_once $classPath;
|
require_once $classPath;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue