PHPackages                             solcre/zf2-conditional-loader - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. solcre/zf2-conditional-loader

ActiveLibrary[Framework](/categories/framework)

solcre/zf2-conditional-loader
=============================

This package allows to load modules in Zend Framework 2 if some conditions apply.

11.5k2PHP

Since Feb 17Pushed 11y ago3 watchersCompare

[ Source](https://github.com/solcre/zf2-conditional-loader)[ Packagist](https://packagist.org/packages/solcre/zf2-conditional-loader)[ RSS](/packages/solcre-zf2-conditional-loader/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Conditional Module Loader for Zend Framework 2
==============================================

[](#conditional-module-loader-for-zend-framework-2)

Introduction
------------

[](#introduction)

This simple package will allow you to load modules depending on some conditions.

Motivation: We use [AssetManager](https://github.com/RWOverdijk/AssetManager) for a project, and we wanted to load the module only when the request is for an asset.

Installation
------------

[](#installation)

Using Composer (recommended)
----------------------------

[](#using-composer-recommended)

The recommended way to get a working copy of this project is to clone the repository and use `composer` to install dependencies using the `create-project` command:

```
curl -s https://getcomposer.org/installer | php --
php composer.phar create-project solcre/zf2-conditional-loader path/to/install

```

Alternately, clone the repository and manually invoke `composer` using the shipped `composer.phar`:

```
cd my/project/dir
git clone git://github.com/solcre/zf2-conditional-loader.git
cd zf2-conditional-loader
php composer.phar self-update
php composer.phar install

```

(The `self-update` directive is to ensure you have an up-to-date `composer.phar`available.)

Another alternative for downloading the project is to grab it via `curl`, and then pass it to `tar`:

```
cd my/project/dir
curl -#L https://github.com/solcre/zf2-conditional-loader/tarball/master | tar xz --strip-components=1

```

You would then invoke `composer` to install dependencies per the previous example.

Using Git submodules
--------------------

[](#using-git-submodules)

Alternatively, you can install using native git submodules:

```
git clone git://github.com/solcre/zf2-conditional-loader.git --recursive

```

Requirements
------------

[](#requirements)

### Libraries Used

[](#libraries-used)

Zend Framework 2

Configuration
-------------

[](#configuration)

### In application.config.php add:

[](#in-applicationconfigphp-add)

```
    'service_manager' => array(
        'factories' => array(
            'ModuleManager' => 'ConditionalLoader\Service\Factory\ModuleManagerFactory',
        )
    ),
    'modules_condition_resolvers' => array(
        '' => '',
    ),
);

```

\*Remember to create a service for your condition resolver class or define it as an invokable.

### Example config:

[](#example-config)

```
'service_manager' => array(
    'factories' => array(
        'ModuleManager' => 'ConditionalLoader\Service\Factory\ModuleManagerFactory',
    ),
    'invokables' => array(
        'AssetManagerResolver' => 'ColumnisExpress\ConditionResolver\AssetManagerResolver'
    )
),
'modules' => array(
    'AssetManager',
    'Columnis'
),
'modules_condition_resolvers' => array(
    'AssetManager' => 'AssetManagerResolver'
),

```

### Example of a Condition Resolver Class (AssetManagerResolver)

[](#example-of-a-condition-resolver-class-assetmanagerresolver)

```
