2017 © Pedro PelΓ‘ez
 

library module

Provides module support to ICanBoogie.

image

icanboogie/module

Provides module support to ICanBoogie.

  • Sunday, March 18, 2018
  • by olvlvl
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2,982 Installations
  • PHP
  • 6 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 20 Versions
  • 0 % Grown

The README.md

Module

Release Code Coverage Downloads, (*1)

This package provides support for modules to the framework ICanBoogie., (*2)

A module is like a tiny application inside your application. It provides its own configurations, routes, operations, views, templates… it contains everything it needs to execute a desired functionality., (*3)

Installation

composer require icanboogie/module

Defining a module

It takes at least two files to define a module: a configuration fragment and a module class. The configuration fragment is a module.php file located in the config directory. The class is usually located in the file lib/Module.php. The module directory is usually named with the identifier of the module., (*4)

The following directory structure demonstrates how a very basic nodes module could be defined:, (*5)

nodes
β”œβ”€ config
β”‚  └─ module.php
└─ lib
   └─ Module.php

The following directory structure demonstrates a more advanced module:, (*6)

nodes
β”œβ”€ config
β”‚  └─ module.php
|  └─ <configuration files>
β”œβ”€ lib
|  β”œβ”€ Operation
|  |  └─ <operation classes>
|  └─ Module.php
β”œβ”€ locale
|  └─ <message catalogs>
β”œβ”€ public
|  └─ <public assets>
β”œβ”€ tests
|  └─ <tests>
└─ templates
   └─ <view templates>

The configuration fragment

The configuration fragment describes the module and its models. At the very least the identifier and the class of the module must be defined. The modules configuration takes care of verifying module relationships integrity, computing module weights, and sorting modules according to their weight., (*7)

The following code could be a configuration fragment for a "nodes" module., (*8)

<?php

namespace Acme\Nodes;

use ICanBoogie\Binding\Module\ConfigBuilder;

return fn(ConfigBuilder $config) => $config
    ->add_module(
        id: 'nodes',
        class: Module::class
    );

Operations

Module operations are defined in the "lib/Operation" directory. For example a save operation would be a class named SaveOperation declared within the namespace <module namespace>\Operation, located in a "SaveOperation.php" file., (*9)

Operations are considered inherited. If the save operation is requested on a News module, the framework tries to locate the best matching operation class, according to the modules it extends:, (*10)

  • ..\News\Operation\SaveOperation
  • ..\Contents\Operation\SaveOperation
  • ..\Nodes\Operation\SaveOperation

Working with modules

There's two ways to work with modules: a provider is good enough when all your need is load a module, a collection is better if you need to work on multiple modules such as installation., (*11)

Accessing a module

You can get a module using a module provider:, (*12)

<?php

/* @var \ICanBoogie\Module\ModuleProvider $provider */

$nodes = $provider->module_for_id('nodes');

You can check a module is defined with the has_module method:, (*13)

<?php

/* @var \ICanBoogie\Module\ModuleProvider $provider */

$provider->has_module('nodes');

You can also iterate over the provider, and get modules:, (*14)

<?php

/* @var \ICanBoogie\Module\ModuleProvider $provider */

foreach ($provider as $module_id => $get) {
    $module = $get();

    // …
}

Installing and uninstalling modules

Modules are installed using the install() method, and uninstalled using the uninstall() method. The is_installed() method returns the installation state of the module and also collects the reasons why the module is not installed., (*15)

<?php

use ICanBoogie\ErrorCollection;
use ICanBoogie\Module;

/* @var Module $nodes */

$errors = new ErrorCollection();

if (!$nodes->is_installed($errors)) {
    #
    # $errors might contain messages about why the module is not installed
    #

    $errors->clear();

    if (!$nodes->install($errors)) {
        #
        # $errors might contain the reasons why the module failed to install
        #
    }
}

$nodes->uninstall();

Modules can be installed all at once using a ModuleCollection instance. The ModuleCollectionInstallFailed exception is thrown with all the errors and exceptions collected in a ErrorCollection instance if the installation fails., (*16)

<?php

use ICanBoogie\Module\ModuleCollection;use ICanBoogie\Module\ModuleInstaller\ModuleInstallFailed;

/* @var ModuleCollection $modules */

try {
    $modules->install();
} catch (ModuleInstallFailed $e) {
    echo get_class($e->errors); // ICanBoogie\ErrorCollection
}

Autoconfig

The package supports the autoconfig feature of ICanBoogie., (*17)

Template resolver decorator

A ModuleTemplateResolver instance is used to decorate the template resolver instance defined when the ICanBoogie\Render\BasicTemplateResolver::alter event of class TemplateResolver\AlterEvent is fired, adding support for module defined templates. When the path part of the template name matches an activated module identifier, the template pathname is resolved using the module and its parents., (*18)

Event hooks

  • routing.collect_routes:before: Alter routes defined by modules by adding a module key that holds the identifier of the module that defines the route.

Continuous Integration

The project is continuously tested by GitHub actions., (*19)

Tests Static Analysis Code Style, (*20)

Code of Conduct

This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you're expected to uphold this code., (*21)

Contributing

See CONTRIBUTING for details., (*22)

The Versions

25/01 2015

v2.0.4

2.0.4.0 http://icanboogie.org/

Provides module support to ICanBoogie.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

framework module

17/01 2015
07/11 2014

v2.0.2

2.0.2.0 http://icanboogie.org/

Provides module support to ICanBoogie.

  Sources   Download

BSD-3-Clause

The Requires

 

framework module

02/11 2014

v2.0.1

2.0.1.0 http://icanboogie.org/

Provides module support to ICanBoogie.

  Sources   Download

BSD-3-Clause

The Requires

 

framework module

24/10 2014

v2.0.0

2.0.0.0 http://icanboogie.org/

Provides module support to ICanBoogie.

  Sources   Download

BSD-3-Clause

The Requires

 

framework module