tccltd/tcc-abstract-module

There is no license information available for the latest version (1.0.0) of this package.

TccAbstractModule Package

1.0.0 2014-03-12 17:08 UTC

This package is not auto-updated.

Last update: 2024-10-26 16:25:58 UTC


README

Provides an AbstractModule class that can be extended by individual Module classes to automatically implement functionality such as autoloading and configuration.

Installation

Simply add tccltd/tcc-abstract-module to your composer.json.

Usage

When creating a new module, extend TccAbstractModule\Module\AbstractModule in your Module.php.

PHP 5.3 NOTE: If you are not using PHP 5.4 then you will need to extend TccAbstractModuleNoTraits instead of TccAbstractModule. The functionality provided is identical.

For simpler modules, you may well find that this is all you need:

namespace MyModule;

use TccAbstractModule\Module\AbstractModule;

class Module extends AbstractModule
{
}

The abstract module configures the following behaviour automatically:

  1. Autoloading: The classmap defined in ./autoload_classmap.php is used in the first instance, falling back to a standard PSR-0 compatible autoloader serving files from ./src/MyModule/.

  2. Module Configuration: All files in ./config/ matching the format module.config{,.*}.php will be loaded. As a matter of good practice, you should separate your routes into module.config.routes.php.

  3. Service Configuration: Where previously you would have defined service manager invokables, services, factories, aliases, initializers and abstract_factories in the getServiceConfig() function of your Module.php, these should now be defined in ./config/service/service.config.php. The format is the same. Note that all files in ./config/service/ matching the format service.config{,.*}.php will be loaded, should you wish to further subdivide your service configuration.

  4. Controller Configuration: Where previously you would have defined controller manager invokables, services, factories, aliases, initializers and abstract_factories in the getControllerConfig() function of your Module.php, these should now be defined in ./config/service/controller.config.php. The format is the same. Note that all files in ./config/service/ matching the format controller.config{,.*}.php will be loaded, should you wish to further subdivide your controller configuration.

  5. View Helper Configuration: Where previously you would have defined view helper manager invokables, services, factories, aliases, initializers and abstract_factories in the getViewHelperConfig() function of your Module.php, these should now be defined in ./config/service/viewhelper.config.php. The format is the same. Note that all files in ./config/service/ matching the format service.config{,.*}.php will be loaded, should you wish to further subdivide your view helper configuration.

A typical file structure (focusing on the aspects related to this module) might be as follows:

module/  
  MyModule/  
    config/  
      service/  
        controller.config.php  
        service.config.php  
        viewhelper.config.php  
      module.config.php  
      module.config.routes.php  
  autoload_classmap.php  
  Module.php  

Overriding

Should you wish to modify the behaviour of the AbstractModule, you can do so by either overriding in your individual Module.php files, or you can extend the entire module and create your own AbstractModule. If you have a suggestion that might benefit all users of this module, please do feel free to suggest it, of course!

Traits

TccAbstractModule is composed of traits. This means that you can, should you wish, cherry-pick the functionality that you would like to use. In this instance you would not override AbstractModule. Instead, you would use the relevant traits within your own Module class. Note that you will need to use ClassDirTrait in order to use any of the other traits, and ClassNamespaceTrait in order to use AutoloaderProviderDefaultTrait.

It is anticipated that most users will not need to cherry-pick.