Eliasis PHP Framework / documentation · version 1.1.3
Eliasis is an open-source HMVC web framework for development dynamic web sites with PHP. Lightweight, modular and optimized for the development of WordPress plugins.
This framework is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.
You can install Eliasis PHP Framework into your project using Composer. If you're starting a new project, we recommend using the basic app as a starting point:
composer create-project --prefer-dist eliasis-framework/app
cd app
composer install
For existing applications you can run the following:
composer require eliasis-framework/eliasis
The previous command will only install the necessary files, if you prefer to download the entire source code, including tests, vendor folder, exceptions not used, docs, etc, you can use:
composer require eliasis-framework/eliasis-framework --prefer-source
You just need a PHP file in which you include the autoloader of classes of Composer to get started to create your first application with Eliasis Framework.
/** * my-custom-app.php */ require __DIR__ . '/vendor/autoload.php';
To create an application with Eliasis simply:
/** * my-custom-app.php */ use Eliasis\Framework\App; App::run(__DIR__);
If no ID is specified, the default identifier of the application will be "Default".
Methods referred to in this section:
The identifier supports the following class conventions: UpperCamelCase, lowerCamelCase & snake_case.
Application identifiers allow you to create multiple applications on a same website avoiding collisions between them and facilitating access to them from anywhere:
App::run(__DIR__, 'app', 'MyApplication');
Ideally designed to use different instances of Eliasis Framework in multiple WordPress plugins running at the same time:
/** * wp-content/plugins/my-first-plugin/my-first-plugin.php */ require __DIR__ . '/vendor/autoload.php'; use Eliasis\Framework\App; App::run(__DIR__, 'wordpress-plugin', 'MyFirstPlugin');
/** * wp-content/plugins/my-second-plugin/my-second-plugin.php */ require __DIR__ . '/vendor/autoload.php'; use Eliasis\Framework\App; App::run(__DIR__, 'wordpress-plugin', 'MySecondPlugin');
Methods referred to in this section:
You have two options to jump from one application to another. Passing the application ID as a method (recommended):
App::MyFirstApp->getCurrentID(); // MyFirstApp App::MySecondApp->getCurrentID(); // MySecondApp
Or through the App::setCurrentID() method:
App:setCurrentID('MyFirstApp'); App::getCurrentID(); // MyFirstApp App:setCurrentID('MySecondApp'); App::getCurrentID(); // MySecondApp
If you only use one application on the website, there is no need to specify or set the application ID.
Methods referred to in this section:
The application will collect all configuration files found in the "config" directory:
Configuration files must return an indexed array and they may contain any kind of data:
/** * config/settings.php */ return [ 'slug' => 'my-custom-app', 'email' => [ 'rol' => [ 'admin' => 'admin@site.com', 'editor' => 'editor@site.com' ] ] ];
/** * config/paths.php */ use Eliasis\Framework\App; return [ 'path' => [ 'layout' => App::ROOT() . 'src/template/layout/', 'page' => App::ROOT() . 'src/template/page/', ], ];
Topics referred to in this section:
To obtain the configuration parameters from the application you have several options.
Passing the index as a method:
App::slug(); App::email(); App::email('rol'); App::email('rol', 'admin');
Using the "getOption()" method:
App::getOption('slug'); App::getOption('email'); App::getOption('email', 'rol'); App::getOption('email', 'rol', 'admin');
Passing the application ID as method and using the "getOption()" method:
App::MyCustomApp()->getOption('slug'); App::MyCustomApp()->getOption('email'); App::MyCustomApp()->getOption('email', 'rol'); App::MyCustomApp()->getOption('email', 'rol', 'admin');
Either of the three options will return the same result:
/* string(13) "my-custom-app" array(1) { ["rol"] => array(1) { ["admin"] => string(14) "admin@site.com" } } array(1) { ["admin"] => string(14) "admin@site.com" } string(14) "admin@site.com" */
Methods referred to in this section:
The controllers must be placed in the "src/Controller" directory of the application:
The basic controller structure in Eliasis Framework is as follows:
/** * src/Controller/Home.php */ namespace App\Controller; use Eliasis\Framework\Controller; class Home extends Controller { }
You can easily access a controller instance from anywhere in the application using the "App:: getControllerInstance() "method".
The "App::getControllerInstance()" method uses the namespaces stored in "App::namespaces()" to get the instances of the drivers, therefore they must have been previously added in the "config/namespaces.php" file:
/** * config/namespaces.php */ return [ 'namespaces' => [ 'controller' => 'App\\Controller\\' ], ];
Or through the "App::setOption()" method:
App::setOption('namespaces', [ 'controller' => 'App\\Controller\\' ];
To get the instance you simply have to indicate the class name of the driver class and the ID of the namespace. This last parameter is optional, although it is advisable to use it when repeating class names:
App::getControllerInstance('Home');
App::getControllerInstance('Home', 'controller');
Methods referred to in this section:
The models must be created in the application's "src/Model" directory, be at the same level as the controller and have the same name:
The basic model structure in Eliasis Framework is as follows:
/** * src/Model/Home.php */ namespace App\Model; use Eliasis\Framework\Model; class Home extends Model { }
When you instantiate a controller, the model is automatically instantiated if it exists. Can access the model instance from the controller using the "model" attribute in the controller methods:
/** * src/Controller/Home.php */ public function createTables() { return $this->model->createTables(); }
The templates can be created in any directory although it is recommended to create them in the "src/template" directory:
Basic templates structure:
/** * src/template/layout/header.php * * Header content. */
/** * src/template/page/home.php * * Home page content. */
/** * src/template/layout/footer.php * * Footer content. */
You can access the view instance from the controller using the "view" attribute in the controller methods.
Use the "renderizate" method to render templates and send you custom parameters:
/** * src/Controller/Home.php */ public function render() { $page = App::path('page'); $layout = App::path('layout'); $this->view->renderizate($layout, 'header', ['data' => 'Header']); $this->view->renderizate($page, 'home', ['data' => 'Home']); $this->view->renderizate($layout, 'footer', ['data' => 'Footer']); }
From each template you will be able to use the options sent from the "renderizate" method through the "View::getOption()" method:
/** * src/template/layout/header.php */ use Eliasis\Framework\View; View::getOption('data'); // Header
/** * src/template/page/home.php */ use Eliasis\Framework\View; View::getOption('data'); // Home
/** * src/template/layout/footer.php */ use Eliasis\Framework\View; View::getOption(); // ['data' => 'Footer']
Methods referred to in this section:
List of "constants" for path management:
App::ROOT(); # /root/ App::CORE(); # /root/vendor/eliasis-framework/eliasis/ App::PUBLIC(); # /root/public/ App::TEMPLATES(); # /root/templates/ App::MODULES(); # /root/modules/ App::PLUGINS(); # /root/plugins/ App::COMPONENTS(); # /root/components/
You can also access these parameters through the different methods available in Eliasis.
Topics referred to in this section:
List of "constants" for URLs management:
App::PUBLIC_URL(); # https://site.com/root/public/ App::TEMPLATES_URL(); # https://site.com/root/templates/ App::MODULES_URL(); # https://site.com/root/modules/ App::PLUGINS_URL(); # https://site.com/root/plugins/ App::COMPONENTS_URL(); # https://site.com/root/components/
You can also access these parameters through the different methods available in Eliasis.
Topics referred to in this section:
App::run($baseDirectory, $type, $id);
Atttribute | Description | Data type | Required | Default |
---|---|---|---|---|
$baseDirectory | Root directory. | string | yes | |
$type | Application type: "app" | "wordpress.plugin". | string | no | "app" |
$id | Unique id for the application. | string | no | "Default" |
@return (boolean true)
Run application:
App::run(__DIR__);
Run application with specific ID:
App::run(__DIR__, 'app', 'FirstApplication')
Run WordPress plugin with specific ID:
App::run(__DIR__, 'wordpress-plugin', 'FirstApplication')
You can find more information in the sections:
App::setOption($option, $value);
Atttribute | Description | Data type | Required | Default |
---|---|---|---|---|
$option | Option name. | string | yes | |
$value | Option value. | mixed | yes |
@return (mixed) → Option set.
Set options:
App::setOption('string-test', 'string'); App::setOption('int-test', 8); App::setOption('bool-test', true); App::setOption('array-test', []);
Set options from multiple applications:
App::MyApplicationOne()->setOption('test', 'One'); App::MyApplicationTwo()->setOption('test', 'Two'); App::setCurrentID('MyApplicationThree'); App::setOption('test', 'Three'); App::MyApplicationFour()->setOption('test', 'Four');
You can find more information in the sections:
App::getOption(...$params);
Atttribute | Description | Data type | Required | Default |
---|---|---|---|---|
$params | Index or indexes of the parameter to be obtained. | array | yes |
@return (mixed) → Requested parameters.
Get options:
App::getOption('index'); App::getOption('index', 'index-1'); App::getOption('index', 'index-1', 'index-2');
Get options from multiple applications:
App::MyApplicationOne()->getOption('test'); App::MyApplicationTwo()->getOption('test'); App::setCurrentID('MyApplicationThree'); App::getOption('test'); App::MyApplicationFour()->getOption('test');
You can find more information in the sections:
App::getControllerInstance($class, $namespace);
Atttribute | Description | Data type | Required | Default |
---|---|---|---|---|
$class | Class name. | string | yes | |
$namespace | Namespace index. | string | no | '' |
@return (object|false) → Class instance or false.
Get controller instance:
App::getControllerInstance('Home'); App::getControllerInstance('Home', 'controller');
You can find more information in the sections:
App::setCurrentID($id);
Atttribute | Description | Data type | Required | Default |
---|---|---|---|---|
$id | Application ID. | string | yes |
@return (boolean)
Define the current application ID:
App::setCurrentID('MyApplicationOne'); App::setCurrentID('MyApplicationTwo');
You can find more information in the sections:
App::getCurrentID();
@return (string) → Application ID.
Get the current application ID:
App::getCurrentID();
You can find more information in the sections:
View::getInstance();
@return (object)
Get View instance:
View::getInstance();
View::addHeader($header);
Atttribute | Description | Data type | Required | Default |
---|---|---|---|---|
$header | HTTP header. | string | yes |
@return (boolean true)
Add header:
View::addHeader('HTTP/1.0 404 Not Found');
You can find more information in the sections:
View::addHeaders($headers);
Atttribute | Description | Data type | Required | Default |
---|---|---|---|---|
$headers | HTTP headers. | array | yes |
@return (boolean true)
Add headers:
View::addHeaders([ 'WWW-Authenticate: Negotiate', 'HTTP/1.0 404 Not Found' ]);
You can find more information in the sections:
View::sendHeaders();
@return (boolean)
You can find more information in the sections:
View::renderizate($path, $file, $data);
Atttribute | Description | Data type | Required | Default |
---|---|---|---|---|
$path | Filepath. | string | yes | |
$file | Filename. | string | yes | |
$data | Options for view. | array | no | null |
@return (boolean true)
Render template:
View::renderizate('path/to/file', 'template-name');
Render template with custom parameters:
View::renderizate( 'path/to/file', 'template-name', ['test' => 'value'] ););
You can find more information in the sections:
View::getOption(...$params);
Atttribute | Description | Data type | Required | Default |
---|---|---|---|---|
$params | Index or indexes of the parameter to be obtained. | array | yes |
@return (mixed) → Requested parameters.
Get options:
View::getOption('index'); View::getOption('index', 'index-1'); View::getOption('index', 'index-1', 'index-2');
You can find more information in the sections:
You'll need to install the eliasis-framework/complement to create components.
composer require eliasis-framework/complement
You'll need to install the to create modules.
composer require eliasis-framework/complement
You'll need to install the to create plugins.
composer require eliasis-framework/complement
You'll need to install the to create templates.
composer require eliasis-framework/complement
Eliasis Framework is focused on scalability, allowing you to develop from an application with a simple controller to a complete system.
To do this, it offers a series of optional libraries that when installed in your project are integrated into the core of Eliasis:
To install, simply:
composer require Josantonius/Asset
This library contains static methods and isn't implemented in the core of Eliasis.
Add scripts and styles to the application settings:
/** * config/assets.php */ use Eliasis\Framework\App; $public = App::PUBLIC_URL(); return [ 'assets' => [ 'js' => [ 'myCustomScript' => [ 'name' => 'myCustomScript', 'url' => $public . 'js/scripts.js', 'attr' => 'defer', 'version' => '1.1.3', 'footer' => false ] ], 'css' => [ 'myCustomStyle' => [ 'name' => 'myCustomStyle', 'url' => $public . 'css/styles.css', 'version' => '1.1.1' ] ] ] ];
Add styles:
/** * public/css/styles.css */
/** * src/Controller/Home.php */ use Josantonius\Asset\Asset; public function css() { Asset::add('style', App::assets('css')['myFirstStyle'] ); }
Add scripts:
/** * public/js/scripts.js */
/** * src/Controller/Home.php */ use Josantonius\Asset\Asset; public function js() { Asset::add('script', App::assets('js')['myFirstScript'] ); }
To minimize and|or unify scripts and styles just place the following command before being added:
/** * my-custom-app.php */ use Josantonius\Asset\Asset; $public = App::PUBLIC_URL(); Asset::unify('UniqueID', $public . '/', true);
To install, simply:
composer require eliasis-framework/complement
This library is instantiated directly by Eliasis.
Topics referred to in this section:
To install, simply:
composer require Josantonius/Cookie
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/Curl
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/Database
Eliasis will connect to the database using the first configuration found in the app configuration parameter "db":
/** * config/database.php */ return [ 'db' => [ 'app' => [ 'provider' => 'PDOprovider', 'host' => 'localhost', 'user' => 'db_user', 'name' => 'db_name', 'password' => 'db_password', 'settings' => ['charset' => 'utf8'], ], 'api-rest' => [ 'provider' => 'PDOprovider', 'host' => 'localhost', 'user' => 'db_user', 'name' => 'db_name', 'password' => 'db_password', 'settings' => ['charset' => 'utf8'], ], ], ];
You can access the database instance using the "db" attribute in the models methods. To change the database connection simply use the "changeDatabaseConnection()" model method.
/** * src/Model/Home.php */ namespace App\Model; use Eliasis\Framework\Model; class Home extends Model { public function createTables() { $params = [ 'id' => 'INT(6) PRIMARY KEY', 'name' => 'VARCHAR(30) NOT NULL', 'email' => 'VARCHAR(50)' ]; $this->db->create($params) ->table('test') ->execute(); $this-model->changeDatabaseConnection('api-rest'); $this->db->create($params) ->table('test_two') ->foreing('id') ->reference('id') ->on('test') ->actions('ON DELETE CASCADE ON UPDATE CASCADE') ->engine('innodb') ->charset('utf8') ->execute(); } }
To install, simply:
composer require Josantonius/ErrorHandler
This library is instantiated directly by Eliasis.
You can set custom methods that will be called when there is an error or exception:
/** * my-custom-app.php */ $instance = App::getControllerInstance('Home', 'controller'); $method = 'errorHandler'; ErrorHandler::setCustomMethod($instance, $method);
To install, simply:
composer require Josantonius/File
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/Hook
When installing this library, Eliasis will load the action hooks found in the index "hooks" of the configuration files:
/** * config/set-hooks.php */ use Eliasis\Framework\App; $namespace = App::namespaces('controller'); $class = $namespace . 'Home'; return [ 'hooks' => [ ['header', [$class, 'header'], 8, 0], ['footer', [$class, 'footer'], 8, 0], ['css', [$class, 'css'], 8, 0], ['js', [$class, 'js'], 8, 0], ], ];
Add the methods to the controller:
/** * src/Controller/Home.php */ public function header() { return ''; } public function footer() { return ''; }
And they run anywhere in the application:
/** * src/template/layout/header.php */ use Eliasis\Framework\View; use Josantonius\Hook\Hook; Hook::doAction('css'); Hook::doAction('header'); View::getOption('data');
/** * src/template/page/home.php */ use Eliasis\Framework\View; use Josantonius\Hook\Hook; Hook::doAction('home'); View::getOption('data');
/** * src/template/layout/footer.php */ use Eliasis\Framework\View; use Josantonius\Hook\Hook; Hook::doAction('footer'); Hook::doAction('js'); View::getOption('data');
To install, simply:
composer require Josantonius/HTTPStatusCode
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/Ip
And to get the user's IP address, simply:
App::IP();
To install, simply:
composer require Josantonius/Json
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/LanguageCode
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/LoadTime
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/Logger
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/MimeType
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/Request
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/Router
When installing this library, Eliasis will load the routes found in the index "routes" of the configuration files:
/** * config/set-routes.php */ use Eliasis\Framework\App; $namespace = App::namespaces('controller'); return [ 'routes' => [ 'my-route/' => $namespace . 'Home@render' ], ];
Add the method to the controller:
/** * src/Controller/Home.php */ namespace App\Controller; use Eliasis\Framework\Controller; use Josantonius\Asset\Asset; class Home extends Controller { public function header() { return ''; } public function footer() { return ''; } public function css() { Asset::add('style', App::assets('css')['myFirstStyle'] ); } public function js() { Asset::add('script', App::assets('js')['myFirstScript'] ); } public function createTables() { return $this->model->createTables(); } public function render() { $page = App::path('page'); $layout = App::path('layout'); $this->view->renderizate($layout, 'header', ['data' => 'Header']); $this->view->renderizate($page, 'home', ['data' => 'Home']); $this->view->renderizate($layout, 'footer', ['data' => 'Footer']); } }
When you access the URL "https://site.com/my-route/", the "home" method will be executed and it will execute the "render" method.
To install, simply:
composer require Josantonius/Session
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/Str
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/Url
This library is integrated in the core of Eliasis.
Optional library series for WordPress that you can integrate into Eliasis:
To install, simply:
composer require Josantonius/WP_Image
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/WP_Menu
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/WP_Notice
This library contains static methods and isn't implemented in the core of Eliasis.
To install, simply:
composer require Josantonius/WP_Register
This library contains static methods and isn't implemented in the core of Eliasis.
List of applications and plugins for WordPress developed with Eliasis Framework.
2017 - 2018 Josantonius.
Code released under the MIT license.