Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12293882
D3774.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
32 KB
Referenced Files
None
Subscribers
None
D3774.diff
View Options
diff --git a/composer.json b/composer.json
--- a/composer.json
+++ b/composer.json
@@ -16,6 +16,10 @@
"email": "dereckson@espace-win.org"
}
],
+ "require": {
+ "keruald/database": "0.5.0",
+ "keruald/omnitools": "0.15.0"
+ },
"require-dev": {
"nasqueron/codestyle": "^0.1.2",
"phpunit/phpunit": "^12.4",
diff --git a/workspaces/composer.json b/workspaces/composer.json
--- a/workspaces/composer.json
+++ b/workspaces/composer.json
@@ -3,6 +3,8 @@
"description": "Core interfaces for Obsidian Workspaces",
"type": "project",
"require": {
+ "keruald/database": "0.5.0",
+ "keruald/omnitools": "0.15.0"
},
"require-dev": {
"phpunit/phpunit": "^12.4",
diff --git a/workspaces/src/includes/Events.php b/workspaces/src/includes/Events.php
deleted file mode 100644
--- a/workspaces/src/includes/Events.php
+++ /dev/null
@@ -1,77 +0,0 @@
-<?php
-
-/**
- * _, __, _, _ __, _ _, _, _
- * / \ |_) (_ | | \ | /_\ |\ |
- * \ / |_) , ) | |_/ | | | | \|
- * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- *
- * Events helper methods class
- *
- * @package ObsidianWorkspaces
- * @subpackage Keruald
- * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
- * @license http://www.opensource.org/licenses/bsd-license.php BSD
- * @filesource
- *
- */
-
- /**
- * Events
- */
-class Events {
- /**
- * Grabs the first exception among specified items.
- *
- * @param Travesable $items The items to check
- * @return Exception|null If an exception has been found, the first encountered : otherwise, null.
- */
- public static function grabException (Traversable $items) {
- foreach ($items as $item) {
- if ($item instanceof Exception) {
- return $item;
- }
- }
- return null;
- }
-
- /**
- * Calls a set of functions with the specified parameters.
- * This is intended for callback purpose.
- *
- * @param array The functions to call, each item a callable
- * @param array The parameters to pass to the functions [optional]
- */
- public static function call ($callables, $parameters = []) {
- foreach ($callables as $callable) {
- if (!is_callable($callable)) {
- $ex = static::grabException($parameters);
- throw new InvalidArgumentException("Callback for this method.", 0, $previousEx);
- }
- call_user_func_array($callable, $parameters);
- }
- }
-
- /**
- * Calls a set of functions with the specified parameters.
- * If no function is present, throws an exception.
- *
- * @param array The functions to call, each item a callable
- * @param array The parameters to pass to the functions [optional]
- * @param Exception The exception to throw if no callback is provided
- */
- public static function callOrThrow ($callables, $parameters = [], $exception = null) {
- if (!count($callables)) {
- //Throws an exception
- if ($exception === null) {
- $exception = static::grabException($parameters);
- }
- if ($exception === null) {
- $exception = new RuntimeException();
- }
- throw $exception;
- }
-
- static::call($callables, $parameters);
- }
-}
diff --git a/workspaces/src/includes/config.php b/workspaces/src/includes/config.php
--- a/workspaces/src/includes/config.php
+++ b/workspaces/src/includes/config.php
@@ -19,6 +19,8 @@
*
*/
+use Keruald\Database\Engines\MySQLiEngine;
+
////////////////////////////////////////////////////////////////////////////////
/// ///
/// I. SQL configuration ///
@@ -26,7 +28,8 @@
////////////////////////////////////////////////////////////////////////////////
//SQL configuration
-$Config['sql']['engine'] = 'MySQL'; //Only MySQL is currently implemented
+
+$Config['sql']['engine'] = MySQLiEngine::class;
$Config['sql']['host'] = 'localhost';
$Config['sql']['username'] = 'obsidian';
$Config['sql']['password'] = 'obsidian';
diff --git a/workspaces/src/includes/database/Database.php b/workspaces/src/includes/database/Database.php
deleted file mode 100644
--- a/workspaces/src/includes/database/Database.php
+++ /dev/null
@@ -1,214 +0,0 @@
-<?php
-
-/**
- * _, __, _, _ __, _ _, _, _
- * / \ |_) (_ | | \ | /_\ |\ |
- * \ / |_) , ) | |_/ | | | | \|
- * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- *
- * Database base class
- *
- * @package ObsidianWorkspaces
- * @subpackage Keruald
- * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
- * @license http://www.opensource.org/licenses/bsd-license.php BSD
- * @filesource
- *
- */
-
-abstract class Database implements LoadableWithContext {
- ///
- /// Singleton pattern, LoadableWithContext implementation
- ///
-
- /**
- * @var Database the singleton instance
- */
- private static $instance = null;
-
- /**
- * Loads a new instance of the relevant Database object
- *
- * @param ?Context $context The application context
- * @return Database The database instance
- */
- public static function load (?Context $context = null) {
- if (self::$instance === null ) {
- if (!isset($context->config['sql']['engine'])) {
- throw new InvalidArgumentException("To load a database, you need to add in your configuration a parameter block like:
-
- 'sql' => [
- 'engine' => 'TheSQLEngineYouWant',
- //... configuration specific to the database
- ]"
- );
- }
-
- $className = $context->config['sql']['engine'] . 'Database';
- if (!class_exists($className)) {
- throw new InvalidArgumentException("The class matching your engine doesn't exist: $className");
- }
-
- self::$instance = $className::load($context);
- }
-
- return self::$instance;
- }
-
- ///
- /// The methods to implement
- ///
-
- /**
- * Executes a query
- *
- * @param string $query The query to execute
- * @return DatabaseResult The query result
- */
- public abstract function query ($query);
-
- /**
- * Retrieves the id generated by the last statement
- *
- * @return int The last id generated
- */
- public abstract function nextId ();
-
- /**
- * Escapes the expression
- *
- * @param $expression The expression to escape
- * @return string The escaped expression
- */
- public abstract function escape ($expression);
-
- ///
- /// Generic methods
- ///
-
- /**
- * Fetches a row of the result
- *
- * @param DatabaseResult $result The query result
- * @return array An associative array with the databae result
- */
- public function fetchRow (DatabaseResult $result) {
- return $result->fetchRow();
- }
-
- /**
- * Gets number of rows in result
- *
- * @param DatabaseResult $result The query result
- * @return int The number of rows in the specified result
- */
- public function numRows (DatabaseResult $result) {
- return $result->numRows();
- }
-
- /**
- * Runs a query and fetches a scalar result. Dies if an error occurs.
- *
- * @param string $query the query
- * @param string $errorMessage The error message to print when dying. [optional, by default CantExecuteQuery L10n message]
- * @return string The result of the query
- */
- public function queryScalar ($query = '', $errorMessage = '') {
- if ($errorMessage === '') {
- $errorMessage = Language::get('CantExecuteQuery');
- }
-
- if ($query === '' || $query === false || $query === null) {
- //No query, no value
- return '';
- } elseif (!$result = $this->query($query)) {
- //An error have occured
- message_die(SQL_ERROR, $error_message, '', '', '', $query);
- } elseif (!$row = $this->fetchRow($result)) {
- return '';
- } else {
- return $row[0];
- }
- }
-
- ///
- /// Events
- ///
-
- /**
- * @var Array
- * @event CantConnectToHost Functions to call when it's not possible to connect to the database host
- * @eventparam Database $db The current database instance
- */
- public $cantConnectToHostEvents = [];
-
- /**
- * @var Array
- * @event QueryError Functions to call when a query fails.
- * @eventparam Database $db The current database instance
- * @eventparam string $query The failed query
- * @eventparam DatabaseException $ex The exception describing the query error
- */
- public $queryErrorEvents = [];
-
- /**
- * Called on connect failure
- */
- protected abstract function onCantConnectToHost();
-
- /**
- * Called on query error
- *
- * @param string $query The query executed when the error occured
- */
- protected abstract function onQueryError ($query);
-
- ///
- /// Compatibility feature
- ///
-
- /**
- * Allows the legacy use of sql_query, sql_fetchrow, sql_escape, etc.
- *
- * @param $name The name of the inaccessible method called
- * @param $arguments The method arguments
- * @return mixed The result of the method called
- * @throws BadMethodCallException when the method name doesn't match a legacy method
- * @deprecated
- */
- public function __call ($name, $arguments) {
- if (substr($name, 0, 4) == 'sql_') {
- switch ($name) {
- case 'sql_nextid':
- $newMethodName = 'nextId';
- break;
-
- case 'sql_query_express':
- $newMethodName = 'queryScalar';
- break;
-
- case 'sql_fetchrow':
- $newMethodName = 'fetchRow';
- break;
-
- case 'sql_numrows':
- $newMethodName = 'numRows';
- break;
-
- default:
- $newMethodName = substr($name, 4);
- }
-
- if (method_exists($this, $newMethodName)) {
- //trigger_error("\$db->$name calls shall be replaced by \$db->$newMethodName calls.", E_USER_DEPRECATED);
- return call_user_func_array(
- array($this, $newMethodName),
- $arguments
- );
- }
- }
-
- $className = get_class($this);
- throw new BadMethodCallException("Method doesn't exist: $className::$name");
- }
-}
diff --git a/workspaces/src/includes/database/DatabaseException.php b/workspaces/src/includes/database/DatabaseException.php
deleted file mode 100644
--- a/workspaces/src/includes/database/DatabaseException.php
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
-
-/**
- * _, __, _, _ __, _ _, _, _
- * / \ |_) (_ | | \ | /_\ |\ |
- * \ / |_) , ) | |_/ | | | | \|
- * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- *
- * Database exception class
- *
- * @package ObsidianWorkspaces
- * @subpackage Keruald
- * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
- * @license http://www.opensource.org/licenses/bsd-license.php BSD
- * @filesource
- *
- */
-
-/**
- * DatabaseException class.
- *
- * Used to throw exception running queries.
- */
-class DatabaseException extends RuntimeException {
- /**
- * @var string the SQL query
- */
- protected $query = null;
-
- /**
- * Initializes a new instance of the DatabaseException class
- *
- * @param string|null $query The query executed. Null if the exception occured outside a query.
- * @param string $message The message to throw.
- * @param int $code The code.
- * @param ?Exception $previous The previous exception used for the exception chaining.
- */
- public function __construct ($query = null, $message = '', $code = 0, ?Exception $previous = null) {
- $this->query = $query;
- parent::__construct($message, $code, $previous);
- }
-
- /**
- * Gets the the SQL query
- *
- * @return string|null The SQL query or null if the exception were thrown outside a query context.
- */
- public final function getQuery () {
- return $this->query;
- }
-}
diff --git a/workspaces/src/includes/database/DatabaseResult.php b/workspaces/src/includes/database/DatabaseResult.php
deleted file mode 100644
--- a/workspaces/src/includes/database/DatabaseResult.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-
-/**
- * _, __, _, _ __, _ _, _, _
- * / \ |_) (_ | | \ | /_\ |\ |
- * \ / |_) , ) | |_/ | | | | \|
- * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- *
- * Database result base class
- *
- * @package ObsidianWorkspaces
- * @subpackage Keruald
- * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
- * @license http://www.opensource.org/licenses/bsd-license.php BSD
- * @filesource
- *
- */
-
-/**
- * Represents a database result
- */
-abstract class DatabaseResult implements IteratorAggregate {
- ///
- /// The methods to implement
- ///
-
- /**
- * Gets number of rows in result
- *
- * @return int The number of rows in the specified result
- */
- public abstract function numRows ();
-
- /**
- * Fetches a row of the result
- *
- * @param DatabaseResult $result The query result
- * @return array An associative array with the database result
- */
- public abstract function fetchRow ();
-}
diff --git a/workspaces/src/includes/database/EmptyDatabaseResult.php b/workspaces/src/includes/database/EmptyDatabaseResult.php
deleted file mode 100644
--- a/workspaces/src/includes/database/EmptyDatabaseResult.php
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php
-
-/**
- * _, __, _, _ __, _ _, _, _
- * / \ |_) (_ | | \ | /_\ |\ |
- * \ / |_) , ) | |_/ | | | | \|
- * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- *
- * Empty database result class
- *
- * @package ObsidianWorkspaces
- * @subpackage Keruald
- * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
- * @license http://www.opensource.org/licenses/bsd-license.php BSD
- * @filesource
- *
- */
-
-/**
- * Represents an empty database result
- */
-class EmptyDatabaseResult extends DatabaseResult {
- ///
- /// The methods to implement
- ///
-
- /**
- * Gets number of rows in result
- *
- * @return int 0
- */
- public function numRows () { return 0; }
-
- /**
- * Fetches a row of the result
- *
- * @param DatabaseResult $result The query result
- * @return array An associative array with the databae result
- */
- public function fetchRow () { return null; }
-
- ///
- /// IteratorAggregate implementation
- ///
-
- /**
- * Gets an iterator
- *
- * @return Generator an iterator on the query result
- */
- public function getIterator () {
- return;
- yield; //This unreachable code indicates to the PHP parser this method is a generator
- }
-
-}
diff --git a/workspaces/src/includes/database/MySQLDatabase.php b/workspaces/src/includes/database/MySQLDatabase.php
deleted file mode 100644
--- a/workspaces/src/includes/database/MySQLDatabase.php
+++ /dev/null
@@ -1,145 +0,0 @@
-<?php
-
-/**
- * _, __, _, _ __, _ _, _, _
- * / \ |_) (_ | | \ | /_\ |\ |
- * \ / |_) , ) | |_/ | | | | \|
- * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- *
- * Database implementation for legacy MySQL extension class
- *
- * @package ObsidianWorkspaces
- * @subpackage Keruald
- * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
- * @license http://www.opensource.org/licenses/bsd-license.php BSD
- * @filesource
- *
- */
-
-class MySQLDatabase extends Database {
- /**
- * @var resource the connection identifier
- */
- private $id;
-
- /**
- * Initializes a new instance of the database abstraction class, for MySQL engine
- *
- * @param string $host The host of the MySQL server [optional, default: localhost]
- * @param string $username The username used to connect [optional, default: root]
- * @param string $password The password used to connect [optional, default: empty]
- * @param string $database The database to select [optional]
- */
- public function __construct($host = 'localhost', $username = 'root', $password = '', $database = '') {
- if (!$this->id = @mysql_connect($host, $username, $password)) {
- $this->onCantConnectToHost();
- }
-
- //Selects database
- if ($database !== '') {
- mysql_select_db($database, $this->id);
- }
- }
-
- /**
- * Loads a new instance of the MySQLDatabase object
- *
- * @param Context $context The application context
- * @return MySQLDatabase The MySQLDatabase instance
- */
- public static function load (Context $context) {
- if (!array_key_exists('sql', $context->config)) {
- throw new InvalidArgumentException("To load a MySQL database, you need to add in your configuration a parameter block like:
-
- 'sql' => [
- 'engine' => 'MySQL',
- 'host' => 'localhost',
- 'username' => 'obsidian',
- 'password' => 'somePassword',
- 'database' => 'obsidian'
- ]"
- );
- }
-
- $config = $context->config['sql'];
- return new MySQLDatabase(
- $context->config['sql']['host'],
- $context->config['sql']['username'],
- $context->config['sql']['password'],
- $context->config['sql']['database']
- );
- }
-
- /**
- * Executes a query
- *
- * @param string $query The query to execute
- * @param int $resultType The result type (MYSQL_ASSOC, MYSQL_NUM, MYSQL_BOTH)
- * @return DatabaseResult The query result
- */
- public function query ($query, $resultType = MYSQL_BOTH) {
- $result = mysql_query($query, $this->id);
- if ($result) {
- if (is_resource($result)) {
- return new MySQLDatabaseResult($result, $resultType);
- }
- return new EmptyDatabaseResult();
- }
- $this->onQueryError($query);
- }
-
- /**
- * Fetches a row of the result
- *
- * @param DatabaseResult $result The query result
- * @return array An associative array with the databae result
- */
- public function fetchRow (DatabaseResult $result) {
- return $result->fetchRow();
- }
-
- /**
- * Retrieves the id generated by the last statement
- *
- * @return int The last id generated
- */
- public function nextId () {
- return mysql_insert_id($this->id);
- }
-
- /**
- * Escapes the expression
- *
- * @param $expression The expression to escape
- * @return string The escaped expression
- */
- public function escape ($expression) {
- return mysql_real_escape_string($expression, $this->id);
- }
-
- ///
- /// Events
- ///
-
- /**
- * Called on connect failure
- */
- protected function onCantConnectToHost () {
- $ex = new RuntimeException("Can't connect to SQL server.");
- Events::callOrThrow($this->cantConnectToHostEvents, $this, $ex);
- }
-
- /**
- * Called on query error
- *
- * @param string $query The query executed when the error occured
- */
- protected function onQueryError ($query) {
- $ex = new DatabaseException(
- $query,
- mysql_error($this->id),
- mysql_errno($this->id)
- );
- Events::callOrThrow($this->queryErrorEvents, [$this, $query, $ex], $ex);
- }
-}
diff --git a/workspaces/src/includes/database/MySQLDatabaseResult.php b/workspaces/src/includes/database/MySQLDatabaseResult.php
deleted file mode 100644
--- a/workspaces/src/includes/database/MySQLDatabaseResult.php
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php
-
-/**
- * _, __, _, _ __, _ _, _, _
- * / \ |_) (_ | | \ | /_\ |\ |
- * \ / |_) , ) | |_/ | | | | \|
- * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- *
- * Database result for MySQL legacy extension class
- *
- * @package ObsidianWorkspaces
- * @subpackage Keruald
- * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
- * @license http://www.opensource.org/licenses/bsd-license.php BSD
- * @filesource
- *
- */
-
-class MySQLDatabaseResult extends DatabaseResult {
- ///
- /// Private members
- ///
-
- /**
- * @var resource The resource to the MySQL result
- */
- private $result;
-
- /**
- * @var int The type of result to return
- */
- private $resultType;
-
-
- ///
- /// Constructor
- ///
- /**
- * Initializes a new instance of the MySQLDatabaseResult class
- *
- * @param resource $result the resource to the MySQL result
- * @param int $resultType The result type (MYSQL_ASSOC, MYSQL_NUM, MYSQL_BOTH)
- */
- public function __construct ($result, $resultType = MYSQL_BOTH) {
- $this->result = $result;
- $this->resultType = $resultType;
- }
-
- ///
- /// DatabaseResult implementation
- ///
-
- /**
- * Gets number of rows in result
- *
- * @return int The number of rows in the specified result
- */
- public function numRows () {
- return mysql_num_rows($this->result);
- }
-
- /**
- * Fetches a row of the result
- *
- * @param DatabaseResult $result The query result
- * @return array An associative array with the databae result
- */
- public function fetchRow () {
- return mysql_fetch_array($this->result, $this->resultType);
- }
-
- ///
- /// IteratorAggregate implementation
- ///
-
- /**
- * Gets an iterator
- *
- * @return Generator an iterator on the query result
- */
- public function getIterator () {
- while ($row = $this->fetchRow()) {
- yield $row;
- }
- }
-}
\ No newline at end of file
diff --git a/workspaces/src/includes/database/MySQLiDatabase.php b/workspaces/src/includes/database/MySQLiDatabase.php
deleted file mode 100644
--- a/workspaces/src/includes/database/MySQLiDatabase.php
+++ /dev/null
@@ -1,142 +0,0 @@
-<?php
-
-/**
- * _, __, _, _ __, _ _, _, _
- * / \ |_) (_ | | \ | /_\ |\ |
- * \ / |_) , ) | |_/ | | | | \|
- * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- *
- * Database implementation for MySQLi extension class
- *
- * @package ObsidianWorkspaces
- * @subpackage Keruald
- * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
- * @license http://www.opensource.org/licenses/bsd-license.php BSD
- * @filesource
- *
- */
-
-class MySQLiDatabase extends Database {
- /**
- * @var mysqli Represents a connection between PHP and a MySQL database.
- */
- private $db;
-
- /**
- * Initializes a new instance of the database abstraction class, for MySQL engine
- *
- * @param string $host The host of the MySQL server [optional, default: localhost]
- * @param string $username The username used to connect [optional, default: root]
- * @param string $password The password used to connect [optional, default: empty]
- * @param string $database The database to select [optional]
- */
- public function __construct($host = 'localhost', $username = 'root', $password = '', $database = '') {
- $this->db = new mysqli($host, $username, $password, $database);
-
- if ($this->db->connect_error) {
- $this->onCantConnectToHost();
- }
- }
-
- /**
- * Loads a new instance of the MySQLDatabase object
- *
- * @param Context $context The application context
- * @return MySQLDatabase The MySQLDatabase instance
- */
- public static function load (Context $context) {
- if (!array_key_exists('sql', $context->config)) {
- throw new InvalidArgumentException("To load a MySQL database, you need to add in your configuration a parameter block like:
-
- 'sql' => [
- 'engine' => 'MySQLi',
- 'host' => 'localhost',
- 'username' => 'obsidian',
- 'password' => 'somePassword',
- 'database' => 'obsidian'
- ]"
- );
- }
-
- $config = $context->config['sql'];
- return new MySQLiDatabase(
- $config['host'],
- $config['username'],
- $config['password'],
- $config['database']
- );
- }
-
- /**
- * Executes a query
- *
- * @param string $query The query to execute
- * @param int $resultType The result type (MYSQLI_ASSOC, MYSQLI_NUM, MYSQLI_BOTH)
- * @return DatabaseResult The query result
- */
- public function query ($query, $resultType = MYSQLI_BOTH) {
- $result = $this->db->query($query);
- if ($result) {
- if ($result === TRUE) {
- return new EmptyDatabaseResult();
- }
- return new MySQLiDatabaseResult($result, $resultType);
- }
- $this->onQueryError($query);
- }
-
- /**
- * Fetches a row of the result
- *
- * @param DatabaseResult $result The query result
- * @return array An associative array with the databae result
- */
- public function fetchRow (DatabaseResult $result) {
- return $result->fetchRow();
- }
-
- /**
- * Retrieves the id generated by the last statement
- *
- * @return int The last id generated
- */
- public function nextId () {
- return $this->db->insert_id;
- }
-
- /**
- * Escapes the expression
- *
- * @param $expression The expression to escape
- * @return string The escaped expression
- */
- public function escape ($expression) {
- return $this->db->real_escape_string($expression);
- }
-
- ///
- /// Events
- ///
-
- /**
- * Called on connect failure
- */
- protected function onCantConnectToHost () {
- $ex = new RuntimeException("Can't connect to SQL server: " . $this->db->connect_error);
- Events::callOrThrow($this->cantConnectToHostEvents, $this, $ex);
- }
-
- /**
- * Called on query error
- *
- * @param string $query The query executed when the error occured
- */
- protected function onQueryError ($query) {
- $ex = new DatabaseException(
- $query,
- $this->db->error,
- $this->db->errno
- );
- Events::callOrThrow($this->queryErrorEvents, [$this, $query, $ex], $ex);
- }
-}
diff --git a/workspaces/src/includes/database/MySQLiDatabaseResult.php b/workspaces/src/includes/database/MySQLiDatabaseResult.php
deleted file mode 100644
--- a/workspaces/src/includes/database/MySQLiDatabaseResult.php
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-
-/**
- * _, __, _, _ __, _ _, _, _
- * / \ |_) (_ | | \ | /_\ |\ |
- * \ / |_) , ) | |_/ | | | | \|
- * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- *
- * Database result for MySQL legacy extension class
- *
- * @package ObsidianWorkspaces
- * @subpackage Keruald
- * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
- * @license http://www.opensource.org/licenses/bsd-license.php BSD
- * @filesource
- *
- */
-
-class MySQLiDatabaseResult extends DatabaseResult {
- ///
- /// Private members
- ///
-
- /**
- * @var mysqli_result Represents the result set obtained from a query against the database.
- */
- private $result;
-
- /**
- * @var int The type of result to return
- */
- private $resultType;
-
- ///
- /// Constructor
- ///
- /**
- * Initializes a new instance of the MySQLDatabaseResult class
- *
- * @param resource $result the resource to the MySQL result
- * @param int $resultType The result type (MYSQLI_ASSOC, MYSQLI_NUM, MYSQLI_BOTH)
- */
- public function __construct ($result, $resultType = MYSQLI_BOTH) {
- $this->result = $result;
- $this->resultType = $resultType;
- }
-
- ///
- /// DatabaseResult implementation
- ///
-
- /**
- * Gets number of rows in result
- *
- * @return int The number of rows in the specified result
- */
- public function numRows () {
- return $this->result->num_rows;
- }
-
- /**
- * Fetches a row of the result
- *
- * @param DatabaseResult $result The query result
- * @return array An associative array with the databae result
- */
- public function fetchRow () {
- return $this->result->fetch_array($this->resultType);
- }
-
- ///
- /// IteratorAggregate implementation
- ///
-
- /**
- * Gets an iterator
- *
- * @return Generator an iterator on the query result
- */
- public function getIterator () {
- while ($row = $this->fetchRow()) {
- yield $row;
- }
- }
-}
\ No newline at end of file
diff --git a/workspaces/src/index.php b/workspaces/src/index.php
--- a/workspaces/src/index.php
+++ b/workspaces/src/index.php
@@ -16,18 +16,21 @@
*
*/
+use Keruald\Database\Database;
+
////////////////////////////////////////////////////////////////////////////////
///
/// Initialization
///
//Keruald and Obsidian Workspaces libraries
+
include('includes/core.php');
//Prepares the site context
$context = new Context();
$context->config = $Config;
-$context->db = $db = Database::load($context);
+$context->db = $db = Database::load($Config["sql"]);
$context->session = Session::load();
$context->url = get_current_url_fragments();
$context->initializeTemplateEngine($context->config['Theme']);
diff --git a/workspaces/tests/includes/database/DatabaseExceptionTest.php b/workspaces/tests/includes/database/DatabaseExceptionTest.php
deleted file mode 100644
--- a/workspaces/tests/includes/database/DatabaseExceptionTest.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-
-/**
- * _, __, _, _ __, _ _, _, _
- * / \ |_) (_ | | \ | /_\ |\ |
- * \ / |_) , ) | |_/ | | | | \|
- * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- *
- * Unit testing — FilesCollection class
- *
- * @package ObsidianWorkspaces
- * @subpackage Tests
- * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
- * @license http://www.opensource.org/licenses/bsd-license.php BSD
- * @filesource
- */
-
-use PHPUnit\Framework\TestCase;
-
-require_once(__DIR__ . '/../../../src/includes/database/DatabaseException.php');
-
-/**
- * Tests DatabaseException class
- */
-class DatabaseExceptionTest extends TestCase {
- public function testGetQuery () {
- $sql = 'SELECT 1+';
- $ex = new DatabaseException($sql, 'Syntax error', 1064);
- $this->assertEquals(
- $sql,
- $ex->getQuery(),
- ""
- );
-
- $ex = new DatabaseException();
- $this->assertNull(
- $ex->getQuery(),
- "If the query isn't specified during the constructor call, getQuery shall return null."
- );
-
- $ex = new DatabaseException('');
- $this->assertEquals(
- '',
- $ex->getQuery(),
- "If the query isn't specified during the constructor call, getQuery shall not return null but must return an empty string too."
- );
- }
-}
diff --git a/workspaces/tests/includes/database/MySQLDatabaseTest.php b/workspaces/tests/includes/database/MySQLDatabaseTest.php
deleted file mode 100644
--- a/workspaces/tests/includes/database/MySQLDatabaseTest.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-
-/**
- * _, __, _, _ __, _ _, _, _
- * / \ |_) (_ | | \ | /_\ |\ |
- * \ / |_) , ) | |_/ | | | | \|
- * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- *
- * Unit testing — MysqlDatabaseTest class
- *
- * @package ObsidianWorkspaces
- * @subpackage Tests
- * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
- * @license http://www.opensource.org/licenses/bsd-license.php BSD
- * @filesource
- */
-
-use PHPUnit\Framework\TestCase;
-
-//require '../src/includes/database/MysqlDatabase.php';
-
-/**
- * Tests DatabaseTest
- */
-class MySQLDatabaseTest extends TestCase {
- /**
- * @var MysqlDatabase
- */
- private $db;
-
- /**
- * Creates the objects against which we will test.
- */
- public function setUp () : void {
- $this->db = new MySQLDatabase(
- UNITTESTING_MYSQL_HOST,
- UNITTESTING_MYSQL_USERNAME,
- UNITTESTING_MYSQL_PASSWORD,
- UNITTESTING_MYSQL_DATABASE
- );
- }
-
- /**
- * Tests string escape
- */
- public function testEscape () {
- $toEscapeExpressions = [
- "",
- "Lorem ipsum dolor",
- "L'arbre",
- "''",
- "cœur"
- ];
- $escapedExpressions = [
- "",
- "Lorem ipsum dolor",
- "L\\'arbre",
- "\\'\\'",
- "cœur"
- ];
-
- for ($i = 0 ; $i < count($toEscapeExpressions) ; $i++) {
- $this->assertEquals(
- $escapedExpressions[$i],
- $this->db->escape($toEscapeExpressions[$i]),
- "The following string isn't properly escaped: '$toEscapeExpressions[$i]'"
- );
- }
- }
-}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Oct 20, 22:24 (14 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3090635
Default Alt Text
D3774.diff (32 KB)
Attached To
Mode
D3774: Switch events and databases classes to Keruald packages implementations
Attached
Detach File
Event Timeline
Log In to Comment