Download the PHP package rubenmartindev/prestashop-module-installer without Composer
On this page you can find all versions of the php package rubenmartindev/prestashop-module-installer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rubenmartindev/prestashop-module-installer
More information about rubenmartindev/prestashop-module-installer
Files in rubenmartindev/prestashop-module-installer
Package prestashop-module-installer
Short Description Install and uninstall helpers for PrestaShop modules (hooks, configuration, database and tabs)
License MIT
Informations about the package prestashop-module-installer
PrestaShop Module Installer
rubenmartindev/prestashop-module-installer is a PHP library that provides
install and uninstall helpers for PrestaShop modules.
Overview
This library simplifies common PrestaShop module installation and uninstallation tasks, including:
- hook registration and removal
- configuration entry management
- database table creation and removal
- tab (menu) registration and removal
It is designed to be used inside PrestaShop module lifecycle methods (install and uninstall).
Installation
Install via Composer in your PrestaShop module:
Requirements
- PHP >= 5.6.0
- PrestaShop >=1.6
Usage
RubenMartinDev\PrestaShopModuleInstaller\Installer is designed to be used
inside your module. It defines the resources that will be installed or
uninstalled.
Installer uses a set of handlers (hooks, configuration, database, tabs). Each
handler defines a set of items that are processed during installation and
uninstallation.
Once handlers and their items are configured, you only need to call install()
or uninstall().
Use the helper Installer::createFrom()
The static method Installer::createFrom() makes it easy to create handlers and
items from an array.
Use as a service
If your module uses its own container, for example using
prestashop/module-lib-service-container,
you can create your own service to simplify Installer configuration.
The service factory receives the same arguments as Installer::createFrom().
Then retrieve the service from the container and call install() /
uninstall() in the same way as in the previous example.
Installer Configuration
The Installer has a list of handlers that will be processed during
installation and uninstallation.
To specify which handlers will be used, pass an array with
database,
or tabs, and the items each one contains.
Handlers and Items
Each handler contains a list of items executed during installation and
uninstallation. Both handlers and items have the static method createFrom() to
simplify configuration through an associative array.
Configuration
This handler defines the new configuration entries (ps_configuration) that
will be added to PrestaShop.
Item
Represents a single configuration entry.
| Argument | Type | Default | Description |
|---|---|---|---|
name |
string |
Required | Configuration name. |
value |
callable\|mixed |
Required | Value to store in configuration. |
prefix |
string\|null |
null |
Prefix to add to name. |
If value is a callable, it must return a result.
value transforms its value as follows:
- Booleans are converted to int (0 or 1).
- Arrays are converted to JSON.
- Objects are serialized.
If prefix is null, the module name is used by default. Otherwise, it is
prefixed to name.
Example
Database
This handler is used to create and remove tables in the database.
Item
Represents a single SQL statement.
| Argument | Type | Default | Description |
|---|---|---|---|
tableName |
string |
Required | Table name. |
query |
string\|null |
null |
Raw SQL. |
queryFile |
string\|null |
null |
Path to the SQL file. |
keepData |
bool |
false |
Whether the table should be kept when the module is uninstalled. |
Both query and queryFile support the placeholders {{DB_PREFIX}}
and {{ENGINE_TYPE}}, which correspond to the PrestaShop constants
_DB_PREFIX_ and _MYSQL_ENGINE_ respectively.
If both query and queryFile are set, the latter takes precedence and query
will be ignored.
Example
Hooks
This handler is used to register hooks.
Item
Represents a single hook.
| Argument | Type | Default | Description |
|---|---|---|---|
name |
string |
Required | Hook name. |
prestashopVersion |
string\|array\|null |
null |
PrestaShop version compatible with the hook. |
When prestashopVersion is null, the PrestaShop version is ignored and the hook
will be registered. If it is a string, the PrestaShop version is checked and the
hook will only be registered if the version constraint is satisfied. If it is an
array it must contain at least the min key to specify the minimum PrestaShop
version from which the hook will be registered, and the optional max key to
specify up to which PrestaShop version the hook should be registered.
prestashopVersion internally uses
rubenmartindev/prestashop-version-checker
for version validation and checking.
Example
Tabs
This handler defines and manages tabs (controllers).
Item
Represents a single tab.
| Argument | Type | Default | Description |
|---|---|---|---|
className |
string |
Required | Controller class name. |
name |
string\|array |
Required | Name in the menu. |
parentId |
string\|int |
-1 |
Parent controller ID or class name. |
position |
int |
0 |
Position in the tabs tree. |
isActive |
bool |
true |
Whether the tab is active. |
isEnabled |
bool |
true |
Whether the tab is available. |
routeName |
string\|null |
null |
Symfony route name. |
icon |
string\|null |
null |
Icon name used in the menu. |
wording |
string\|null |
null |
Translation. |
wordingDomain |
string\|null |
null |
Translation domain for the tab. |
When name is an array, it must be a numeric array. The array keys correspond to
id_lang, and the default language ID key (PS_LANG_DEFAULT) must always be
present.
When parentId is a string, the tab ID will be resolved using the class name.
When wording is null, it will be set using the value of name for the default
PrestaShop language.
When wordingDomain is null, it defaults to "Admin.Navigation.Menu".
The isEnabled, routeName, icon, wording, and wordingDomain properties
may be ignored depending on the PrestaShop version.
Example
Custom Handler
Although there are generic handlers for common tasks, you may need to carry out custom actions such as modifying files, creating new records or performing other tasks. To do this, you can create your own handler.
To register our custom handler, we must add it to the list of handlers in our
Installer, using the FQCN of our class as the key.
All versions of prestashop-module-installer with dependencies
rubenmartindev/prestashop-version-checker Version ^1.1
symfony/options-resolver Version ^3.4