Eliasis Complement / documentation · version 1.1.1
PHP library for add addition of complements (components, plugins, modules, templates) for Eliasis Framework.
This library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.
You can install Eliasis Complement into your project using Composer:
composer require eliasis-framework/complement
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/complement --prefer-source
You can add four types of complements in your Eliasis application; components, modules, plugins and templates.
To load complements, simply add them to your default directories and Eliasis will take care of loading them:
And use the complement class in your file:
/** * my-eliasis-app.php */ use Eliasis\Complement\Type\Component; use Eliasis\Complement\Type\Module; use Eliasis\Complement\Type\Plugin; use Eliasis\Complement\Type\Template;
The basic structure of an complement in Eliasis consists of a directory containing a configuration file with the same name as the directory.
The basic parameters of the configuration files are as follows:
/** * components/basic-component/basic-component.json */ { "id": "BasicComponent", "name": "Basic Component", "version": "1.0.0", "description": "Description for 'Basic Component'.", "state": "inactive", "category": "basic-component", "url": "//github.com/Josantonius/" }
/** * modules/basic-module/basic-module.json */ { "id": "BasicModule", "name": "Basic Module", "version": "1.0.0", "description": "Description for 'Basic Module'.", "state": "active", "category": "basic-module", "url": "//github.com/Josantonius/" }
/** * plugins/basic-plugin/basic-plugin.json */ { "id": "BasicPlugin", "name": "Basic Plugin", "version": "1.0.0", "description": "Description for 'Basic Plugin'.", "state": "inactive", "category": "basic-plugin", "url": "//github.com/Josantonius/" }
/** * templates/basic-template/basic-template.json */ { "id": "BasicTemplate", "name": "Basic Template", "version": "1.0.0", "description": "Description for 'Basic Template'.", "state": "uninstalled", "category": "basic-template", "url": "//github.com/Josantonius/" }
Optionally you can add some extra fields:
/** * modules/basic-module/basic-module.json */ { "id": "BasicModule", "name": "Basic Module", "version": "1.0.0", "description": "Description for 'Basic Module'.", "state": "active", "category": "basic-module", "url": "//github.com/Josantonius/", "author": "Josantonius", "author-url": "//josantonius.com/", "license": "GPL-2.0+", "extra": { "a-custom-field": "Value", "another-custom-field": "Value", "more-custom-fields": "Value" } }
These parameters will be available in the complement options.
Topics referred to in this section:
The ID supports the following class conventions: UpperCamelCase, lowerCamelCase & snake_case.
Complements identifiers allow you to interact with multiple complements in Eliasis applications, avoiding collisions and facilitating access to them from anywhere.
To jump from one complement to another, simply pass on the complement ID as a method and access its available methods.
/** * my-eliasis-app.php */ Component::BasicComponent()->getCurrentID(); // BasicComponent Module::BasicModule()->getCurrentID(); // BasicModule Plugin::BasicPlugin()->getCurrentID(); // BasicPlugin Template::BasicTemplate()->getCurrentID(); // BasicTemplate
To access complements from different applications you just need to set the current ID for the application and access the complement as seen above.
/** * my-eliasis-app.php */ App:setCurrentID('MyFirstApp'); // The BasicComponent component of the MyFirstApp application is accessed. Component::BasicComponent()->getCurrentID(); // The BasicComponent component of the MySecondApp application is accessed. App:setCurrentID('MySecondApp'); Component::BasicComponent()->getCurrentID();
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:
You can also load remote complements into an application with Eliasis.
/** * https://site.com/remote-complement.json */ { "id": "RemoteComplement", "name": "Remote Complement", "version": "3.0.0", "description": "Description for 'Remote Complement'.", "state": "uninstalled", "category": "remote-complement", "url": "//github.com/Josantonius/", "url-import": "https://site.com/master/", "installation-files": { "remote-complement": { "0": "LICENSE", "1": "composer.json", "2": "remote-complement.json", "config": [], "public": [], "src": [] } } }
Module::load('https://site.com/remote-complement.json');
To install remote complements you will need to specify the url of the base directory from which it will be imported (url-import) and the structure of the files (installation-files) to be imported.
Once the complement is loaded, you can install it using the install() method.
Module::RemoteComplement()->install();
And this would create a module consisting of three files and three directories:
Methods referred to in this section:
Eliasis Complement uses the vue-module-manager component to display complements on screen:
Simply add the styles and scripts to the directory you want and use the render() method:
Module::render();
Methods referred to in this section:
You can find more information in the sections:
The complement 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:
/** * modules/basic-module/config/settings.php */ return [ 'slug' => 'basic-module', 'email' => [ 'rol' => [ 'admin' => 'admin@site.com', 'editor' => 'editor@site.com' ] ] ];
/** * modules/basic-module/config/paths.php */ use Eliasis\Framework\App; return [ 'path' => [ 'layout' => App::MODULES() . 'src/template/layout/', 'page' => App::MODULES() . 'src/template/page/', ], ];
Topics referred to in this section:
To obtain the configuration parameters from the complement:
Module::BasicModule->getOption('slug'); Module::BasicModule->getOption('email'); Module::BasicModule->getOption('email', 'rol'); Module::BasicModule->getOption('email', 'rol', 'admin');
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 Complement is as follows:
/** * basic-module/src/Controller/Home.php */ namespace BasicModule\Controller; use Eliasis\Framework\Controller; class Home extends Controller { }
You can easily access a controller instance from anywhere in the application using the "getControllerInstance() method".
The "getControllerInstance()" method uses the namespaces stored in namespaces index to get the instances of the controllers, therefore they must have been previously added in the "config/namespaces.php" file:
/** * basic-module/config/namespaces.php */ return [ 'namespaces' => [ 'controller' => 'BasicModule\\Controller\\' ], ];
Or through the "setOption()" method:
Module::BasicModule()->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:
Module::BasicModule()->getControllerInstance('Home');
Module::BasicModule()->getControllerInstance('Home', 'controller');
Methods referred to in this section:
By default, when an complement changes state, the following methods are executed:
Eliasis will search for these methods in the "Launcher" controller if exists. To use another controller, just specify it in the configuration:
/** * modules/basic-module/basic-module.json */ { "id": "BasicModule", "name": "Basic Module", "version": "1.0.0", "description": "Description for 'Basic Module'.", "state": "active", "category": "basic-module", "url": "//github.com/Josantonius/", "author": "Josantonius", "author-url": "//josantonius.com/", "license": "GPL-2.0+", "hooks-controller": "Hook", "extra": { "a-custom-field": "Value", "another-custom-field": "Value", "more-custom-fields": "Value" } }
Add the controller:
The contents of the file would look like this:
/** * modules/basic-module/src/Controller/Hook.php */ namespace BasicModule\Controller; use Eliasis\Framework\Controller; /** * Hook controller. */ class Hook extends Controller { /** * Actions for activation hook. */ public function activation() { } /** * Actions for deactivation hook. */ public function deactivation() { } /** * Actions for installation hook. */ public function installation() { } /** * Actions for uninstallation hook. */ public function uninstallation() { } }
Topics referred to in this section:
The models must be created in the complement's "src/Model" directory, be at the same level as the controller and have the same name:
The basic model structure is as follows:
/** * basic-module/src/Model/Home.php */ namespace BasicModule\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:
/** * basic-module/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:
/** * basic-module/src/template/layout/header.php * * Header content. */
/** * basic-module/src/template/page/home.php * * Home page content. */
/** * basic-module/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:
/** * basic-module/src/Controller/Home.php */ public function render() { $page = Module::BasicModule->getOption('page'); $layout = Module::BasicModule->getOption('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:
/** * basic-module/src/template/layout/header.php */ use Eliasis\Framework\View; View::getOption('data'); // Header
/** * basic-module/src/template/page/home.php */ use Eliasis\Framework\View; View::getOption('data'); // Home
/** * basic-module/src/template/layout/footer.php */ use Eliasis\Framework\View; View::getOption(); // ['data' => 'Footer']
Methods referred to in this section:
App::ROOT(); # /my-eliasis-app/ App::CORE(); # /my-eliasis-app/vendor/eliasis-framework/eliasis/ App::PUBLIC(); # /my-eliasis-app/public/ App::TEMPLATES(); # /my-eliasis-app/templates/ App::MODULES(); # /my-eliasis-app/modules/ App::PLUGINS(); # /my-eliasis-app/plugins/ App::COMPONENTS(); # /my-eliasis-app/components/
List of "constants" for path management:
App::ROOT(); # /my-eliasis-app/ App::CORE(); # /my-eliasis-app/vendor/eliasis-framework/eliasis/ App::PUBLIC(); # /my-eliasis-app/public/ App::TEMPLATES(); # /my-eliasis-app/templates/ App::MODULES(); # /my-eliasis-app/modules/ App::PLUGINS(); # /my-eliasis-app/plugins/ App::COMPONENTS(); # /my-eliasis-app/components/
List of "constants" for URLs management:
App::PUBLIC_URL(); # https://site.com/my-eliasis-app/public/ App::TEMPLATES_URL(); # https://site.com/my-eliasis-app/templates/ App::MODULES_URL(); # https://site.com/my-eliasis-app/modules/ App::PLUGINS_URL(); # https://site.com/my-eliasis-app/plugins/ App::COMPONENTS_URL(); # https://site.com/my-eliasis-app/components/
Component::load($configurationFile); Module::load($configurationFile); Plugin::load($configurationFile); Template::load($configurationFile);
Attribute | Description | Data type | Required | Default |
---|---|---|---|---|
$configurationFile | Path or url to the complement configuration file. | string | yes |
@return (boolean true)
Load remote complement:
Module::load('https://site.com/remote-complement.json');
Load local complement:
Module::load('var/www/site.com/remote-complement.json');
You can find more information in the sections:
Component::exists($complementID); Module::exists($complementID); Plugin::exists($complementID); Template::exists($complementID);
Attribute | Description | Data type | Required | Default |
---|---|---|---|---|
$complementID | Complement ID. | string | yes |
@return (boolean)
Check if module exists:
Module::exists('BasicModule');
Component::list($filter, $sort); Module::list($filter, $sort); Plugin::list($filter, $sort); Template::list($filter, $sort);
Attribute | Description | Data type | Required | Default |
---|---|---|---|---|
$filter | Filter by category. | string | no | 'all' |
$sort | PHP sorting function to complements sort. | string | no | 'asort' |
@return (array) → Complements list
Get a list of complements with filters and default sorting:
Module::getList();
Get complements list by caregory:
Module::getList('basic-module');
Get complements list and sort by:
Module::getList('all', 'asort'); Module::getList('all', 'arsort'); Module::getList('all', 'krsort'); Module::getList('all', 'ksort'); Module::getList('all', 'rsort'); Module::getList('all', 'shuffle'); Module::getList('all', 'sort');
Component::script($pathUrl, $vue, $vueResource); Module::script($pathUrl, $vue, $vueResource); Plugin::script($pathUrl, $vue, $vueResource); Template::script($pathUrl, $vue, $vueResource);
Attribute | Description | Data type | Required | Default |
---|---|---|---|---|
$pathUrl | Path url where JS files will be created & loaded. | string | no | null |
$vue | Include Vue.js in the script. | boolean | no | true |
$vueResource | Include vue-resource in the script. | boolean | no | true |
@return (string) → Script url
Set and get url for full script.
If no url path is specified, will be used the setting (path-url) in the configuration files.
/** * modules/basic-module/config/urls.php */ return [ 'path-url' => [ 'js' => 'https://example.org/public/js/' ] ];
Module::script(); // Return: https://example.org/public/js/vue+vue-resource+eliasis-complement.min-1-1-1.js
Set and get url for full script with custom path url:
Module::script('https://example.org/public/js/'); // Return: https://example.org/public/js/vue+vue-resource+eliasis-complement.min-1-1-1.js
Set and get url for script without Vue without VueResource:
Module::script(null, false, false); // Return: https://example.org/public/js/eliasis-complement.min-1-1-1.js
Set and get url for script with Vue without VueResource:
Module::script(null, true, false); // Return: https://example.org/public/js/vue+eliasis-complement.min-1-1-1.js
Set and get url for script without Vue with VueResource:
Module::script(null, false, true); // Return: https://example.org/public/js/vue-resource+eliasis-complement.min-1-1-1.js
Component::style($pathUrl); Module::style($pathUrl); Plugin::style($pathUrl); Template::style($pathUrl);
Attribute | Description | Data type | Required | Default |
---|---|---|---|---|
$pathUrl | Path url where CSS files will be created & loaded. | string | no | null |
@return (string) → Style url
Set and get url for full style.
If no url path is specified, will be used the setting (path-url) in the configuration files:
/** * modules/basic-module/config/urls.php */ return [ 'path-url' => [ 'css' => 'https://example.org/public/css/', 'js' => 'https://example.org/public/js/' ] ];
Module::style(); // Return: https://example.org/public/css/eliasis-complement.min-1-1-1.css
Set and get url for full style with custom path url:
Module::style('https://example.org/public/css/'); // Return: https://example.org/public/css/eliasis-complement.min-1-1-1.css
Component::render($filter, $remote, $sort, $translations); Module::render($filter, $remote, $sort, $translations); Plugin::render($filter, $remote, $sort, $translations); Template::render($filter, $remote, $sort, $translations);
Attribute | Description | Data type | Required | Default |
---|---|---|---|---|
$filter | Complements category to display. | string | no | 'all' |
$remote | Urls of the remote optional complements. | array | no | 'asort' |
$sort | PHP sorting function to complements sort. | string | no | null |
$translations | Translations for button texts. | array | no | null |
@return (boolean true)
Renderizate local complements specifying a category to filter:
Module::render('basic-module');
Renderizate local complements and adding also remote complementes:
Module::render( 'basic-module', [ 'ComplementOne' => http:/example.org/complement-one.json', 'ComplementTwo' => http:/example.org/complement-two.json', 'ComplementThree' => http:/example.org/complement-three.json' ] );
Renderizate local complements and sort them by:
Module::render('all', null, 'asort'); Module::render('all', null, 'arsort'); Module::render('all', null, 'krsort'); Module::render('all', null, 'ksort'); Module::render('all', null, 'rsort'); Module::render('all', null, 'shuffle'); Module::render('all', null, 'sort');
Renderizate local complements and set up Spanish translations for the buttons:
Module::render( 'all', null, 'asort', [ 'active' => 'activo', 'activate' => 'activar', 'install' => 'instalar', 'update' => 'actualizar', 'uninstall' => 'desinstalar' ] );
Component::setCurrentID($id); Module::setCurrentID($id); Plugin::setCurrentID($id); Template::setCurrentID($id);
Atttribute | Description | Data type | Required | Default |
---|---|---|---|---|
$id | Application ID. | string | yes |
@return (boolean)
Define the current application ID:
Module::setCurrentID('BasicModule'); Module::setCurrentID('RemoteComplement');
You can find more information in the sections:
Component::getCurrentID(); Module::getCurrentID(); Plugin::getCurrentID(); Template::getCurrentID();
@return (string) → Application ID.
Get the current application ID:
Module::getCurrentID();
You can find more information in the sections:
Component::getLibraryVersion(); Module::getLibraryVersion(); Plugin::getLibraryVersion(); Template::getLibraryVersion();
Get Eliasis library version:
Module::getLibraryVersion();
Component::getInstance(); Module::getInstance(); Plugin::getInstance(); Template::getInstance();
Get complement instance:
Module::getInstance();
Component::BasicComponent->setOption($option, $value); Module::BasicModule->setOption($option, $value); Plugin::BasicPlugin->setOption($option, $value); Template::BasicTemplate->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:
Module::BasicModule->setOption('string-test', 'string'); Module::BasicModule->setOption('int-test', 8); Module::BasicModule->setOption('bool-test', true); Module::BasicModule->setOption('array-test', []);
You can find more information in the sections:
Component::BasicComponent->getOption(...$params); Module::BasicModule->getOption(...$params); Plugin::BasicPlugin->getOption(...$params); Template::BasicTemplate->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:
Module::BasicModule->getOption('index'); Module::BasicModule->getOption('index', 'index-1'); Module::BasicModule->getOption('index', 'index-1', 'index-2');
You can find more information in the sections:
Component::BasicComponent->getControllerInstance($class, $namespace); Module::BasicModule->getControllerInstance($class, $namespace); Plugin::BasicPlugin->getControllerInstance($class, $namespace); Template::BasicTemplate->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:
Module::BasicModule->getControllerInstance('Home'); Module::BasicModule->getControllerInstance('Home', 'controller');
You can find more information in the sections:
Component::BasicComponent->setAction($action); Module::BasicModule->setAction($action); Plugin::BasicPlugin->setAction($action); Template::BasicTemplate->setAction($action);
Atttribute | Description | Data type | Required | Default |
---|---|---|---|---|
$action | Complement action. | string | yes |
@return (string) → Action set.
Set complement activation action:
Module::BasicModule->setAction('activation');
Set complement deactivation action:
Module::BasicModule->setAction('deactivation');
Set complement installation action:
Module::BasicModule->setAction('installation');
Set complement uninstallation action:
Module::BasicModule->setAction('uninstallation');
Component::BasicComponent->getAction($action); Module::BasicModule->getAction($action); Plugin::BasicPlugin->getAction($action); Template::BasicTemplate->getAction($action);
Atttribute | Description | Data type | Required | Default |
---|---|---|---|---|
$state | Complement state. | string | yes |
@return (string) → Action set.
Get complement action from state:
Module::BasicModule->getAction('active');
Component::BasicComponent->doAction($action); Module::BasicModule->doAction($action); Plugin::BasicPlugin->doAction($action); Template::BasicTemplate->doAction($action);
Atttribute | Description | Data type | Required | Default |
---|---|---|---|---|
$action | Action to be executed. | string | yes |
@return (boolean)
Do action for activation hook:
Module::BasicModule->doAction('activation');
Do action for deactivation hook:
Module::BasicModule->doAction('deactivation');
Do action for installation hook:
Module::BasicModule->doAction('installation');
Do action for uninstallation hook:
Module::BasicModule->doAction('uninstallation');
Component::BasicComponent->setState($state); Module::BasicModule->setState($state); Plugin::BasicPlugin->setState($state); Template::BasicTemplate->setState($state);
Atttribute | Description | Data type | Required | Default |
---|---|---|---|---|
$state | Complement state to set. | string | yes |
@return (string) → State set.
Set complement state to active:
Module::BasicModule->setState('active');
Set complement state to inactive:
Module::BasicModule->setState('inactive');
Set complement state to installed:
Module::BasicModule->setState('installed');
Set complement state to uninstalled:
Module::BasicModule->setState('uninstalled');
Component::BasicComponent->getState(); Module::BasicModule->getState(); Plugin::BasicPlugin->getState(); Template::BasicTemplate->getState();
@return (string) → Complement state.
Get current complement state:
Module::BasicModule->getState();
Component::BasicComponent->getStates($action); Module::BasicModule->getStates($action); Plugin::BasicPlugin->getStates($action); Template::BasicTemplate->getStates($action);
@return (array) → Complement states.
Get current complement states:
Module::BasicModule->getStates();
Component::BasicComponent->changeState(); Module::BasicModule->changeState(); Plugin::BasicPlugin->changeState(); Template::BasicTemplate->changeState();
@return (string) → New state.
Change complement state from active state:
Module::BasicModule->changeState(); // inactive
Change complement state from inactive state:
Module::BasicModule->changeState(); // active
Change complement state from uninstalled state:
Module::BasicModule->changeState(); // installed
Change complement state from installed state:
Module::BasicModule->changeState(); // inactive
Change complement state from outdated state:
Module::BasicModule->changeState(); // updated
Change complement state from updated state:
Module::BasicModule->changeState(); // active
Component::RemoteComplement->install(); Module::RemoteComplement->install(); Plugin::RemoteComplement->install(); Template::RemoteComplement->install();
@return (boolean)
Install remote complement:
Module::RemoteComplement->install();
Component::BasicComponent->remove(); Module::BasicModule->remove(); Plugin::BasicPlugin->remove(); Template::BasicTemplate->remove();
@return (boolean true)
Remove complement:
Module::BasicModule->remove();
Component::RemoteComplement->hasNewVersion(); Module::RemoteComplement->hasNewVersion(); Plugin::RemoteComplement->hasNewVersion(); Template::RemoteComplement->hasNewVersion();
@return (boolean)
Check if the remote complement has a new version:
Module::RemoteComplement->hasNewVersion();
Component::getRepositoryVersion->getRepositoryVersion(); Module::getRepositoryVersion->getRepositoryVersion(); Plugin::getRepositoryVersion->getRepositoryVersion(); Template::getRepositoryVersion->getRepositoryVersion();
@return (string) → Current repository version.
Get repository version:
Module::getRepositoryVersion->getRepositoryVersion();
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:
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 complement settings:
/** * basic-module/config/assets.php */ use Eliasis\Complement\Type\Module; $public = App::PUBLIC_URL() . 'modules/basic-module/public/; return [ 'assets' => [ 'js' => [ 'complements' => [ 'name' => 'complements', 'url' => Module::script($public), 'attr' => 'defer', 'version' => '1.1.0', 'footer' => true ], 'myCustomScript' => [ 'name' => 'myCustomScript', 'url' => $public . 'js/scripts.js', 'attr' => 'defer', 'version' => '1.1.3', 'footer' => false ] ], 'css' => [ 'complements' => [ 'name' => 'complements', 'url' => Module::style($public), 'version' => '1.1.0' ], 'myCustomStyle' => [ 'name' => 'myCustomStyle', 'url' => $public . 'css/styles.css', 'version' => '1.1.1' ] ] ] ];
Add styles:
/** * basic-module/public/css/styles.css */
/** * basic-module/src/Controller/Home.php */ use Josantonius\Asset\Asset; public function css() { Asset::add('style', App::assets('css')['complements'] ); Asset::add('style', App::assets('css')['myFirstStyle'] ); }
Add scripts:
/** * basic-module/public/js/scripts.js */
/** * basic-module/src/Controller/Home.php */ use Josantonius\Asset\Asset; public function js() { Asset::add('script', App::assets('js')['complements'] ); Asset::add('script', App::assets('js')['myFirstScript'] ); }
To minimize and|or unify scripts and styles just place the following command before being added:
/** * basic-module/my-custom-app.php */ use Josantonius\Asset\Asset; $public = App::PUBLIC_URL(); Asset::unify('UniqueID', $public . '/', true);
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'], ], ], ];p>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.
/** * basic-module/src/Model/Home.php */ namespace BasicModule\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:
/** * basic-module/my-custom-app.php */ $instance = Module::BasicModule()->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:
/** * basic-module/config/set-hooks.php */ use Eliasis\Complement\Type\Module; $namespace = Module::BasicModule()->getOption('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:
/** * basic-module/src/Controller/Home.php */ public function header() { return ''; } public function footer() { return ''; }
And they run anywhere in the application:
/** * basic-module/src/template/layout/header.php */ use Eliasis\Framework\View; use Josantonius\Hook\Hook; Hook::doAction('css'); Hook::doAction('header'); View::getOption('data');
/** * basic-module/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:
/** * basic-module/config/set-routes.php */ use Eliasis\Complement\Type\Module; $namespace = Module::BasicModule()->getOption('namespaces', 'controller'); return [ 'routes' => [ 'my-route/' => $namespace . 'Home@render' ], ];
Add the method to the controller:
/** * basic/src/Controller/Home.php */ namespace BasicModule\Controller; use Eliasis\Framework\Controller; use Eliasis\Complement\Type\Module; 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')['complements'] ); Asset::add('style', App::assets('css')['myFirstStyle'] ); } public function js() { Asset::add('script', App::assets('js')['complements'] ); 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']); Module::render( 'basic-module', [ 'ComplementOne' => http:/example.org/complement-one.json', 'ComplementTwo' => http:/example.org/complement-two.json', 'ComplementThree' => http:/example.org/complement-three.json' ] ); $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 complements developed with Eliasis Complement:
2017 - 2018 Josantonius.
Code released under the MIT license.