Packages

A package is Pagekit's concept for extending its functionality. Packages come in two different types: Extensions and Themes.

Package location

All packages reside in the /packages directory, sorted in subdirectories according to their vendor.

Every package belongs to a specific vendor – for example pagekit for all official packages, including the Blog extension and the One theme.

The vendor name is a unique representation of a developer or organization. In the simplest case, it just matches a GitHub username. The package name will also define the name of the directory it is stored in.

Package content

A package contains at least two files.

  • The composer.json contains the metadata for your package and therefore acts as the package definition.
  • The index.php is a so called Module definition and adds actual functionality to Pagekit.The rest of the package content depends on the package's type. To learn more about the actual content of a package, check out the Theme tutorial or the Extension tutorial.

Package definition

A package is defined by its composer.json. This file includes the package name, potential dependencies to be installed by Composer and other information that displays in the Pagekit marketplace.

For a theme, this file can look as follows.

  1. {
  2. "name": "pagekit/theme-hello",
  3. "type": "pagekit-theme",
  4. "version": "0.9.0",
  5. "title": "Hello",
  6. "description": "A blueprint to develop your own themes.",
  7. "license": "MIT",
  8. "authors": [
  9. {
  10. "name": "Pagekit",
  11. "email": "info@pagekit.com",
  12. "homepage": "http://pagekit.com"
  13. }
  14. ],
  15. "extra": {
  16. "image": "image.jpg"
  17. }
  18. }

For more details on this file see the Composer Documentation.

Installation hooks

A package can be either enabled, disabled or not installed. When changing the state, you might need to modify your database schema or run other custom code.

Pagekit offers installation hooks through a custom script file. This file needs to be defined in your Package definition, the composer.json file.

  1. "extra": {
  2. "scripts": "scripts.php"
  3. }

A custom scripts file has to return a PHP array, containing callbacks.

  1. return [
  2.  
  3. 'install' => function ($app) {},
  4. 'uninstall' => function ($app) {},
  5. 'enable' => function ($app) {},
  6. 'disable' => function ($app) {},
  7. 'updates' => [
  8.  
  9. '0.5.0' => function ($app) {},
  10. '0.9.0' => function ($app) {}
  11.  
  12. ]
  13. ];

Install

The install hook is executed after a package was installed.

Uninstall

The uninstall hook is executed before a package was uninstalled.

Pagekit will not modify the tables you have created, even when your extension is disabled or uninstalled in the admin panel. You will have to take care of needed database changes yourself.

Enable

The enable hook is executed after a package was enabled.

Disable

The disable hook is executed before a package was disabled.

Updates

Upon enabling a package, Pagekit checks if newer update hooks than the current version are available. If so, they are executed sequentially.