Skip to content
Improved presenter mapping for PresenterFactory from Nette.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitattributes
.gitignore
.phpcs.xml.dist
.travis.yml
LICENSE.md
README.md
composer.json
phpstan.neon.dist
phpstan.tests.neon.dist

README.md

Presenter Mapping

Build Status Coverage Status Downloads this Month Latest stable

Installation

Via Composer:

$ composer require nepada/presenter-mapping

Register the extension in config.neon:

extensions:
    - Nepada\Bridges\PresenterMappingDI\PresenterMappingExtension

Usage

The extension replaces standard PresenterFactory provided by ApplicationExtension and adds extended support for presenter mapping. The new presenter mapping system is fully compatible with simple mapping from Nette.

Submodule mapping

Nette supports mapping based only on the root module name, this package adds support for separate mapping for submodules. You can define different mapping for submodule Foo:Bar and it will take precendence over the mapping defined for Foo and * respectively.

Example:

application:
    mapping:
        '*': ['App', 'Module\*', 'Presenter\*']
        'Foo': Foo\*Module\*Presenter
        'Foo:Bar': Bar\*Module\*Presenter

Presenter class mapping

You can define mapping between presenter name and class directly for individual presenters. This is especially useful when you need to override a single presenter from a module provided for example by external composer package.

Example:

application:
    mapping:
        'Foo:Bar:Baz': FooBar\BazPresenter

Configuration from another CompilerExtension

Some extensions may need to setup their own presenter mappings, this can be done in beforeCompile() phase by customizing setup of PresenterMapper.

$presenterMapper = $containerBuilder->getByType(Nepada\PresenterMapping\PresenterMapper::class);
$containerBuilder->getDefinition($presenterMapper)
    ->addSetup('setPresenterMapping', ['Foo:Bar:Baz', FooBar\BazPresenter::class])
    ->addSetup('setModuleMapping', ['Foo:Bar', 'Bar\*Module\*Presenter'])
    ->addSetup('setModuleMapping', ['Foo', 'Foo\*Module\*Presenter']);
You can’t perform that action at this time.