Componette

Componette

nepada

nepada / presenter-mapping v2.5.1

Improved presenter mapping for PresenterFactory from Nette.

download-cloud-line composer require nepada/presenter-mapping

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']);
  • v2.5.1 2.5.1

    • PHP 8.4 compatibility
  • v2.5.0 2.5.0

    • Drop support for PHP <8.1
    • Drop useless annotations
    • PHP 8.3 compatibility
  • v2.4.3 2.4.3

    • Support nette/utils 4
  • v2.4.2 2.4.2

    • Fix compatibility with default Nette implementation. When string mask does not explicitly specify module mapping, default behavior should be to use '*Module'. This bug was originally introduced in 2.1.0. Thanks @mabar
  • v2.4.1 2.4.1

    • PHP 8.2 compatibility
  • v2.4.0 2.4.0

    • PHP 8.1 compatiblity.
  • v2.3.0 2.3.0

    • PHP 8.0 compatiblity.
  • v2.2.0 2.2.0

    • Requires PHP >=7.4.
    • Uses native property typehints.
  • v2.1.0 2.1.0

    • Requires PHP >=7.2.
    • PHP 7.4 compatibility.
  • v2.0.0 2.0.0

    • Nette 3 support.
  • v1.2.1 1.2.1

    • Added missing return types.
    • CI improvements.
  • v1.2.0 1.2.0

    • Refactored exception hierarchy (drop marker interface, use standard PHP exceptions instead of custom InvalidStateException) - unlikely, but possible BC break.
    • Code style and type safety improvements.
  • v1.1.1 1.1.1

    • Code style improvements.
    • Marker Exception interface extends Throwable.
  • v1.1.0 1.1.0

    • Requires Nette 2.4 and PHP 7.1.
    • Uses declare(strict_types = 1).
    • Uses scalar and return type hints.
    • Compatible with PHP 7.2.
  • v1.0.3 1.0.3

    • Code style improvements.
  • v1.0.2 1.0.2

    • PresenterMapper accepts array module mask.
  • v1.0.1 1.0.1

    • Fixed compatibility with nette/di 2.4.
  • v1.0.0 1.0.0

    • Initial release.
price-tag-2-line

Badges

guide-fill

Dependencies

php (>=7.1.0)
nette/utils (^3.0@dev)
Componette Componette felix@nette.org