-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sergei Predvoditelev <[email protected]>
- Loading branch information
1 parent
e0d7405
commit e454355
Showing
9 changed files
with
185 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Yii View | ||
|
||
The package provides two use cases for managing view templates: | ||
|
||
- [Basic functionality](basic-functionality.md) for use in any environment. | ||
- [Advanced functionality](use-in-web-environment.md) for use in a web environment. |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
## Uso geral | ||
|
||
O pacote fornece dois casos de uso para gerenciamento de modelos de visualização: | ||
|
||
- [Funcionalidade básica](basic-functionality.md) para uso em qualquer ambiente. | ||
- [Funcionalidade avançada](use-in-web-environment.md) para uso em ambiente web. | ||
|
||
### Estado dos serviços `View` e `WebView` | ||
|
||
Embora sejam imutáveis e, por si só, sem estado, os serviços `View` e `WebView` possuem conjuntos de serviços com estado e dados mutáveis. | ||
|
||
Serviço `View`: | ||
- parâmetros, | ||
- blocos, | ||
- tema, | ||
- local. | ||
|
||
Serviço `WebView`: | ||
- parâmetros, | ||
- blocos, | ||
- tema, | ||
- localidade, | ||
- título, | ||
- meta tags e links, | ||
- strings JS/CSS, | ||
- Arquivos JS/CSS. | ||
|
||
O estado de `View` e `WebView` não são clonados quando os serviços são clonados. Então quando | ||
usar com `with*()`, instâncias novas e antigas compartilharão o mesmo conjunto de dados mutáveis com estado. Permitem, por exemplo, | ||
obter `WebView` por meio de dicas de tipo em um controlador e alterar o caminho do contexto: | ||
|
||
```php | ||
final class BlogController { | ||
private WebView $view; | ||
public function __construct (WebView $view) { | ||
$this->view = $view->withContextPath(__DIR__.'/views'); | ||
} | ||
} | ||
``` | ||
|
||
e então registrar CSS em um widget: | ||
|
||
```php | ||
final class LastPosts extends Widget | ||
{ | ||
private WebView $view; | ||
public function __construct (WebView $view) { | ||
$this->view = $view; | ||
} | ||
protected function run(): string | ||
{ | ||
... | ||
$this->view->registerCss('.lastPosts { background: #f1f1f1; }'); | ||
... | ||
} | ||
} | ||
``` | ||
|
||
#### Estado Locale (internacionalização) | ||
|
||
Você pode alterar a localidade usando `setLocale()`, que será aplicado a todas as outras instâncias que usaram o estado atual | ||
incluindo os existentes. Se você precisar alterar a localidade apenas para uma única instância, poderá usar o método imutável | ||
`withLocale()`. A localidade será aplicada a todas as visualizações renderizadas nas visualizações com chamadas `render()`. | ||
|
||
Exemplo com método mutável: | ||
|
||
```php | ||
final class LocaleMiddleware implements MiddlewareInterface | ||
{ | ||
... | ||
private WebView $view; | ||
... | ||
public function __construct ( | ||
... | ||
WebView $view | ||
... | ||
) { | ||
$this->view = $view; | ||
} | ||
|
||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
... | ||
$this->view->setLocale($locale); | ||
... | ||
} | ||
} | ||
``` | ||
|
||
Exemplo com método imutável: | ||
|
||
```php | ||
final class BlogController { | ||
|
||
private WebView $view; | ||
|
||
public function __construct (WebView $view) { | ||
$this->view = $view; | ||
} | ||
|
||
public function index() { | ||
return $this->view->withLocale('es')->render('index'); | ||
} | ||
} | ||
``` | ||
|
||
#### Redefinir o estado | ||
|
||
Para obter um `View` ou `WebView` clonado profundamente, use `withClearedState()`: | ||
|
||
```php | ||
$view = $view->withClearedState(); | ||
``` | ||
|
||
## Extensões | ||
|
||
- [yiisoft/yii-view](https://github.com/yiisoft/yii-view) - um wrapper usado na [Estrutura Yii](https://www.yiiframework.com/). | ||
Adiciona funcionalidade extra para um ambiente web e compatibilidade | ||
com interfaces [PSR-7](https://www.php-fig.org/psr/psr-7). | ||
- [yiisoft/view-twig](https://github.com/yiisoft/view-twig) - uma extensão que fornece um renderizador de visualização que | ||
permite que você use o mecanismo de modelo de visualização [Twig](https://twig.symfony.com), em vez do renderizador PHP padrão. |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Internals | ||
|
||
## Unit testing | ||
|
||
The package is tested with [PHPUnit](https://phpunit.de/). To run tests: | ||
|
||
```shell | ||
./vendor/bin/phpunit | ||
``` | ||
|
||
## Mutation testing | ||
|
||
The package tests are checked with [Infection](https://infection.github.io/) mutation framework with | ||
[Infection Static Analysis Plugin](https://github.com/Roave/infection-static-analysis-plugin). To run it: | ||
|
||
```shell | ||
./vendor/bin/roave-infection-static-analysis-plugin | ||
``` | ||
|
||
## Static analysis | ||
|
||
The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis: | ||
|
||
```shell | ||
./vendor/bin/psalm | ||
``` | ||
|
||
## Code style | ||
|
||
Use [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or | ||
use either newest or any specific version of PHP: | ||
|
||
```shell | ||
./vendor/bin/rector | ||
``` | ||
|
||
## Dependencies | ||
|
||
This package uses [composer-require-checker](https://github.com/maglnet/ComposerRequireChecker) to check if | ||
all dependencies are correctly defined in `composer.json`. To run the checker, execute the following command: | ||
|
||
```shell | ||
./vendor/bin/composer-require-checker | ||
``` |