Download the PHP package 68publishers/smart-nette-component without Composer
On this page you can find all versions of the php package 68publishers/smart-nette-component. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download 68publishers/smart-nette-component
More information about 68publishers/smart-nette-component
Files in 68publishers/smart-nette-component
Package smart-nette-component
Short Description Features for Nette Components and Presenters. Authorization via annotations, template resolving and overloading etc. ...
License MIT
Informations about the package smart-nette-component
Smart Nette Component
This package adds some useful features for Nette Presenters and Components, such as authorization for Presenters, their actions and signals using PHP8 attributes, authorization for component signals using attributes, and resolving of component template files.
Installation
The best way to install 68publishers/smart-nette-component is using Composer:
Authorization attributes
To use the authorization attributes, you need to register a compiler extension.
Attributes can be cached when folding the DI container to avoid using reflection at runtime.
The extension will create a classmap and a map of all attributes automatically, it just needs to know where to look for Presenters and Components.
This is done with the scanDirs
, scanComposer
and scanFilters
options, which behave similarly to nette/application.
Now add the following trait to your BasePresenter
and BaseControl
:
From now, you can use authorization attributes in your Presenters and Components:
The Presenter/Component throws the exception SixtyEightPublishers\SmartNetteComponent\Exception\ForbiddenRequestException
if any of the conditions in the attributes are not met.
The package includes the following attributes:
Allowed
InRole
LoggedIn
LoggedOut
If you would like to react somehow to the thrown exception, you can overwrite the onForbiddenRequest()
method in a Presenter/Component.
Custom authorization attributes
You can register your own attributes in the following way:
Template resolving
You don't need to register any compiler extension to use this feature, just use the TemplateResolverTrait
trait in your BaseControl.
The base render()
method is already declared in the trait.
To assign variables to the template, we can use the beforeRender()
method.
You can also define custom render*()
methods that are called for rendering using {control myControl:foo}
.
The template for the base render method will be resolved as COMPONENT_DIRECTORY/templates/myControl.latte
or COMPONENT_DIRECTORY/templates/MyControl.latte
.
The template for the foo
render method will be resolved as COMPONENT_DIRECTORY/templates/foo.myControl.latte
or COMPONENT_DIRECTORY/templates/foo.MyControl.latte
.
Of course, you can set a template file manually:
Contributing
Before opening a pull request, please check your changes using the following commands
All versions of smart-nette-component with dependencies
nette/application Version ^3.1.0
nette/di Version ^3.0.10
nette/security Version ^3.1.4