PHPackages                             68publishers/smart-nette-component - 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. 68publishers/smart-nette-component

ActiveLibrary[Framework](/categories/framework)

68publishers/smart-nette-component
==================================

Features for Nette Components and Presenters. Authorization via annotations, template resolving and overloading etc. ...

v1.0.0(3y ago)27.4k↓45.2%[1 issues](https://github.com/68publishers/smart-nette-component/issues)4MITPHPPHP ^8.1

Since Jun 9Pushed 3y ago1 watchersCompare

[ Source](https://github.com/68publishers/smart-nette-component)[ Packagist](https://packagist.org/packages/68publishers/smart-nette-component)[ RSS](/packages/68publishers-smart-nette-component/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (12)Versions (11)Used By (4)

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.

[![Checks](https://camo.githubusercontent.com/7e8a1a19fdad9cbb8e2f1dc50ff7f25744a40a4aea68396909449360ed72579f/68747470733a2f2f62616467656e2e6e65742f6769746875622f636865636b732f36387075626c6973686572732f736d6172742d6e657474652d636f6d706f6e656e742f6d6173746572)](https://github.com/68publishers/smart-nette-component/actions)[![Coverage Status](https://camo.githubusercontent.com/0bb4322994ee743528be6f2689f5028adb8027215d9dc3fbf815bf0dd4086a3f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f36387075626c6973686572732f736d6172742d6e657474652d636f6d706f6e656e742f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/68publishers/smart-nette-component?branch=master)[![Total Downloads](https://camo.githubusercontent.com/d21bc16adf2a1bc8b391b4a052f435590f232270e2378966584a3d44d83b4c83/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f64742f36387075626c6973686572732f736d6172742d6e657474652d636f6d706f6e656e74)](https://packagist.org/packages/68publishers/smart-nette-component)[![Latest Version](https://camo.githubusercontent.com/91e42af48f3395139846de16bf30613d117fab6730f57833b52eb9d912a0d11b/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f36387075626c6973686572732f736d6172742d6e657474652d636f6d706f6e656e74)](https://packagist.org/packages/68publishers/smart-nette-component)[![PHP Version](https://camo.githubusercontent.com/7767bbf3dba3ecf3db42e3c2a28db33d0622ec9299f2093011e03f808c8697c1/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f7068702f36387075626c6973686572732f736d6172742d6e657474652d636f6d706f6e656e74)](https://packagist.org/packages/68publishers/smart-nette-component)

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

[](#installation)

The best way to install 68publishers/smart-nette-component is using Composer:

```
$ composer require 68publishers/smart-nette-component
```

Authorization attributes
------------------------

[](#authorization-attributes)

To use the authorization attributes, you need to register a compiler extension.

```
extensions:
    component_authorization: SixtyEightPublishers\SmartNetteComponent\Bridge\Nette\DI\ComponentAuthorizationExtension

# The default configuration (you don't need to define it) is as follows:
component_authorization:
    cache: %debugMode%
    scanDirs:
    	- %appDir%
    scanComposer: yes
    scanFilters:
    	- *Presenter
    	- *Control
    	- *Component
```

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](https://doc.nette.org/en/application/configuration#toc-automatic-registration-of-presenters).

Now add the following trait to your `BasePresenter` and `BaseControl`:

```
use Nette\Application\UI\Presenter;
use SixtyEightPublishers\SmartNetteComponent\Bridge\Nette\Application\AuthorizationTrait;

abstract class BasePresenter extends Presenter
{
    use AuthorizationTrait;
}
```

```
use Nette\Application\UI\Control;
use SixtyEightPublishers\SmartNetteComponent\Bridge\Nette\Application\AuthorizationTrait;

abstract class BaseControl extends Control
{
    use AuthorizationTrait;
}
```

From now, you can use authorization attributes in your Presenters and Components:

```
use SixtyEightPublishers\SmartNetteComponent\Attribute\LoggedIn;
use SixtyEightPublishers\SmartNetteComponent\Attribute\Allowed;

#[LoggedIn]
final class AdminProductPresenter extends BasePresenter
{
    #[Allowed('product_resource', 'add')]
    public function actionAdd(): void {}

    #[Allowed('product_resource', 'delete')]
    public function handleDelete(): void {}
}
```

```
use SixtyEightPublishers\SmartNetteComponent\Attribute\LoggedIn;
use SixtyEightPublishers\SmartNetteComponent\Attribute\Allowed;

final class EditOrderControl extends BaseControl
{
    #[Allowed('order_resource', 'delete_item')]
    public function handleDeleteItem(): void {}
}
```

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.

```
protected function onForbiddenRequest(ForbiddenRequestException $exception): void
{
    # `$exception->rule` contains failed attribute

    $this->flashMessage('You don\'t have access here!', 'error');
    $this->redirect('Homepage:');
}
```

### Custom authorization attributes

[](#custom-authorization-attributes)

You can register your own attributes in the following way:

```
use SixtyEightPublishers\SmartNetteComponent\Attribute\AttributeInterface;
use SixtyEightPublishers\SmartNetteComponent\Authorization\RuleInterface;
use SixtyEightPublishers\SmartNetteComponent\Authorization\RuleHandlerInterface;
use SixtyEightPublishers\SmartNetteComponent\Exception\ForbiddenRequestException;

final class CustomRule implements AttributeInterface, RuleInterface
{
    # ...
}

final class CustomRuleHandler implements RuleHandlerInterface
{
    public function canHandle(RuleInterface $rule): bool
    {
        return $rule instanceof CustomRule;
    }

    public function __invoke(RuleInterface $rule): void
    {
        assert($rule instanceof CustomRule);

        if (...) {
            throw new ForbiddenRequestException($rule);
        }
    }
}
```

```
services:
    -
        autowired: no
        factory: CustomRuleHandler
```

Template resolving
------------------

[](#template-resolving)

You don't need to register any compiler extension to use this feature, just use the `TemplateResolverTrait` trait in your BaseControl.

```
use Nette\Application\UI\Control;
use SixtyEightPublishers\SmartNetteComponent\Bridge\Nette\Application\TemplateResolverTrait;

abstract class BaseControl extends Control
{
    use TemplateResolverTrait;
}
```

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}`.

```
final class MyControl extends BaseControl
{
    protected function beforeRender(): void
    {
        # assign variables into the template here
    }

    public function renderFoo(): void
    {
        $this->doRender('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:

```
final class MyPresenter extends BasePresenter
{
    protected function createComponentMyControl() : FooControl
    {
        $control = $this->myControlFactory->create();

        $control->setFile(__DIR__ . '/path/to/file.latte');
        # or relatively from a component's directory:
        $control->setRelativeFile('templates/new/myControl.latte');

        # you can change the template for a specific render type:
        $control->setFile(__DIR__ . '/path/to/myControl.latte', 'foo'); # template for `renderFoo()`

        return $control;
    }
}
```

Contributing
------------

[](#contributing)

Before opening a pull request, please check your changes using the following commands

```
$ make init # to pull and start all docker images

$ make cs.check
$ make stan
$ make tests.all
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~160 days

Recently: every ~301 days

Total

9

Last Release

1254d ago

Major Versions

v0.2.1 → v1.x-dev2022-12-12

PHP version history (3 changes)v0.1PHP ~7.1

v0.2PHP ^7.2

v1.x-devPHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/609005caba54757716c3c037c381376ab298714003da87c9e20aa8c501c97df8?d=identicon)[Jelen](/maintainers/Jelen)

---

Top Contributors

[![tg666](https://avatars.githubusercontent.com/u/24430186?v=4)](https://github.com/tg666 "tg666 (15 commits)")

---

Tags

nettenettecomponentscomponent68publisherssmart-nette-component

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/68publishers-smart-nette-component/health.svg)

```
[![Health](https://phpackages.com/badges/68publishers-smart-nette-component/health.svg)](https://phpackages.com/packages/68publishers-smart-nette-component)
```

###  Alternatives

[contributte/application

Extra contrib to nette/application

352.8M7](/packages/contributte-application)[nette/web-project

Nette: Standard Web Project

10991.8k](/packages/nette-web-project)[kdyby/autowired

Syntax sugar for working with services in Nette Framework

30885.7k9](/packages/kdyby-autowired)[nextras/form-components

Form components for Nette Framework.

10242.9k](/packages/nextras-form-components)[kompo/kompo

Laravel &amp; Vue.js FullStack Components for Rapid Application Development

11812.4k21](/packages/kompo-kompo)[nasext/dependent-select-box

Dependent Select Box for Nette Framework.

21262.8k2](/packages/nasext-dependent-select-box)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
