nepada / presenter-mapping
Improved presenter mapping for PresenterFactory from Nette.
Installs: 29 436
Dependents: 1
Suggesters: 0
Security: 0
Stars: 7
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=8.1.0 <8.5
- nette/application: ^3.1.4@dev
- nette/utils: ^3.2@dev || ^4.0@dev
Requires (Dev)
- nepada/coding-standard: 7.14.0
- nepada/phpstan-nette-tester: 1.2.1
- nette/bootstrap: >=3.1@dev
- nette/di: ^3.0.6@dev
- nette/http: *@dev
- nette/neon: >=3.3.4@dev
- nette/robot-loader: *@dev
- nette/tester: 2.5.4
- php-parallel-lint/php-parallel-lint: 1.4.0
- phpstan/phpstan: 1.12.5
- phpstan/phpstan-nette: 1.3.8
- phpstan/phpstan-strict-rules: 1.6.1
- shipmonk/phpstan-rules: 3.2.0
- spaze/phpstan-disallowed-calls: 3.4.0
Suggests
- nette/di: for integration with Nette DI container
README
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']);