Download the PHP package prestashop/module-lib-service-container without Composer
On this page you can find all versions of the php package prestashop/module-lib-service-container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download prestashop/module-lib-service-container
More information about prestashop/module-lib-service-container
Files in prestashop/module-lib-service-container
Package module-lib-service-container
Short Description Service container to use on prestashop modules
License AFL-3.0
Informations about the package module-lib-service-container
PrestaShop Service Container for Modules
This repository includes the service container from Symfony that you can use in your PrestaShop Module.
Pre-requisites
You should install this library only on a PrestaShop environment and with PHP 5.6.0 minimum.
Installation
When this project is successfully added to your dependencies, you can add the new ServiceContainer to your module and use it. PrestaShop runs with Symfony components from version 1.7, so dependancies are not required anymore here. I you plan to run your module on PrestaShop, Symfony dependencies must be required separately.
Usage
To use this library, it's simple :
- First, declare your new service Container in your root module PHP file (like mymodule.php at your root project folder) :
-
And instantiate it in the constructor with the module name and its local path :
-
You can add a new function on your root module PHP file, like getService, to retrieve your service name in the new service container :
- Then, you have to declare your service in the services.yml file. You must declare your services in the config/ folder. From Symfony 4, services must be explicitely declared as public to be loaded with the method
getService()
;
We split the services in two folders in the config : /front and /admin folders. So the tree should be like :
- Of course, you can include a common file, with common services that are use in front and admin project by an import in the services.yml file :
Now you can add your services in the services.yml like you were in a Symfony project ;)