Skip to content
This repository has been archived by the owner on Aug 20, 2022. It is now read-only.

Commit

Permalink
Updated to 1.0.6 version
Browse files Browse the repository at this point in the history
  • Loading branch information
josantonius committed May 16, 2017
1 parent 295659e commit c21f27d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# CHANGELOG

## 1.0.6 - 2017-05-16

* Added `Eliasis\Model\Model->_getDatabaseInstance` method.

* Added a method for compatibility with the Josantonius\Database\Database library. If it exists, it will get the connection to the database and save it in the $db attribute that will be available on all models.

* Database will get the connection parameters from the Eliasis Framework configuration files. It should have the following structure:

'db' => [

'identifier' => [
'id' => 'identifier',
'prefix' => 'identifier_',
'provider' => 'PDOprovider',
'host' => 'localhost',
'user' => 'db_user',
'name' => 'db_name',
'password' => 'db_password',
'settings' => ['charset' => 'utf8'],
],
]

* Database class url: https://github.com/Josantonius/PHP-Database

## 1.0.5 - 2017-04-29

* Added `Eliasis\Module\Module::getModulesInfo()` method.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eliasis-framework/eliasis",
"version": "1.0.5",
"version": "1.0.6",
"description": "Eliasis PHP Framework",
"type": "library",
"keywords": [
Expand Down
42 changes: 41 additions & 1 deletion src/Model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace Eliasis\Model;

use Eliasis\Model\Exception\ModelException;
use Eliasis\App\App,
Eliasis\Model\Exception\ModelException;

/**
* Model class.
Expand All @@ -29,6 +30,15 @@ abstract class Model {
*/
protected static $instance;

/**
* Database instance.
*
* @since 1.0.6
*
* @var object
*/
protected $db;

/**
* Prevent creating a new model instance.
*
Expand All @@ -50,11 +60,41 @@ public static function getInstance() {
if (!isset(self::$instance[$model])) {

self::$instance[$model] = new $model;

if (is_null(self::$instance[$model]->db)) {

self::$instance[$model]->_getDatabaseInstance();
}
}

return self::$instance[$model];
}

/**
* Get Database connection.
*
* This method will only be used if the Database class exists.
*
* @since 1.0.6
*
* @uses Josantonius\\Database\\Database class
*
* @link https://github.com/Josantonius/PHP-Database
*
* @return object → controller instance
*/
private function _getDatabaseInstance() {

if (class_exists($Database = 'Josantonius\\Database\\Database')) {

$config = App::db();

$id = (is_array($config)) ? array_keys($config)[0] : 'app';

$this->db = $Database::getConnection($id);
}
}

/**
* Prevents the object from being cloned.
*
Expand Down

0 comments on commit c21f27d

Please sign in to comment.