Skip to content

Commit e214bdc

Browse files
authored
translation into brazilian portuguese (#37)
1 parent b7d8bc1 commit e214bdc

11 files changed

+469
-33
lines changed

LICENSE.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
Copyright © 2008 by Yii Software (https://www.yiiframework.com/)
1+
Copyright © 2008 by Yii Software (<https://www.yiiframework.com/>)
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without
55
modification, are permitted provided that the following conditions
66
are met:
77

8-
* Redistributions of source code must retain the above copyright
8+
* Redistributions of source code must retain the above copyright
99
notice, this list of conditions and the following disclaimer.
10-
* Redistributions in binary form must reproduce the above copyright
10+
* Redistributions in binary form must reproduce the above copyright
1111
notice, this list of conditions and the following disclaimer in
1212
the documentation and/or other materials provided with the
1313
distribution.
14-
* Neither the name of Yii Software nor the names of its
14+
* Neither the name of Yii Software nor the names of its
1515
contributors may be used to endorse or promote products derived
1616
from this software without specific prior written permission.
1717

README.md

+19-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
The package provides [Yii Hydrator](https://github.com/yiisoft/hydrator) attributes
1919
to get data from [PSR-7 HTTP request](https://www.php-fig.org/psr/psr-7/) and adds extra abilities to middlewares
2020
processed by [Yii Middleware Dispatcher](https://github.com/yiisoft/middleware-dispatcher):
21+
2122
- maps data from PSR-7 HTTP request to PHP DTO representing user input;
2223
- uses Yii Hydrator parameter attributes for resolving middleware parameters.
2324

@@ -78,15 +79,20 @@ For other available options, see the [guide](docs/guide/en).
7879

7980
## Documentation
8081

81-
- [Guide](docs/guide/en)
82-
- [Internals](docs/internals.md)
82+
- [English](docs/guide/en/README.md)
83+
- [Português - Brasil](docs/guide/pt-BR/readme.md)
8384

84-
## License
85+
Testing:
8586

86-
The Yii Input HTTP is free software. It is released under the terms of the BSD License.
87-
Please see [`LICENSE`](./LICENSE.md) for more information.
87+
- [English](docs/guide/en/testing.md)
88+
- [Português - Brasil:](docs/guide/pt-BR/testing.md)
8889

89-
Maintained by [Yii Software](https://www.yiiframework.com/).
90+
- [Internals](docs/internals.md)
91+
92+
## Support
93+
94+
If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.
95+
You may also check out other [Yii Community Resources](https://www.yiiframework.com/community).
9096

9197
## Support the project
9298

@@ -99,3 +105,10 @@ Maintained by [Yii Software](https://www.yiiframework.com/).
99105
[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat&logo=telegram)](https://t.me/yii3en)
100106
[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat&logo=facebook&logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)
101107
[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat&logo=slack)](https://yiiframework.com/go/slack)
108+
109+
## License
110+
111+
The Yii Input HTTP is free software. It is released under the terms of the BSD License.
112+
Please see [`LICENSE`](./LICENSE.md) for more information.
113+
114+
Maintained by [Yii Software](https://www.yiiframework.com/).

docs/guide/en/hydrator-attributes.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ This package provides some additional attributes for [hydrator](https://github.c
44

55
## Parameter attributes
66

7-
These attributes are used for a single DTO parameter:
7+
These attributes are used for a single DTO parameter:
88

99
- `#[Query]` - maps with request's query parameter.
1010
- `#[Body]` - maps with request's body parameter.
1111
- `#[Request]` - maps with request's attribute. This is useful when middleware prior writes the value.
12-
- `#[UploadedFiles]` - maps with request's uploaded files.
12+
- `#[UploadedFiles]` - maps with request's uploaded files.
1313

1414
The usage of all available parameters is shown below in the single example:
1515

@@ -112,13 +112,13 @@ final class CreateUserInput
112112
}
113113
```
114114

115-
`SearchInput` will be mapped from query parameters, while `CreateUserInput` will be mapped from parsed request body.
115+
`SearchInput` will be mapped from query parameters, while `CreateUserInput` will be mapped from parsed request body.
116116

117-
### Customization
117+
### Customizing parameter names
118118

119-
Similar to parameter attributes, the names of request's parameters can be customized. Here it's done via a map where
120-
keys are DTO properties' names and values according to request's parameter names, which are expected. Besides that, you
121-
can narrow down the scope where exactly to parse the request parameters from. Also, it's possible to throw the exception
119+
Similar to parameter attributes, the names of request's parameters can be customized. Here it's done via a map where
120+
keys are DTO properties' names and values according to request's parameter names, which are expected. Besides that, you
121+
can narrow down the scope where exactly to parse the request parameters from. Also, it's possible to throw an exception
122122
when there are some parameters present in the selected request's scope that were not specified in the map.
123123

124124
```php
@@ -143,7 +143,7 @@ final class SearchInput
143143
In the above example:
144144

145145
- The query string expected in the format such as - `?search[q]=input&search[c]=package`. `input` value is mapped to
146-
`$query` property, while `package` value - to `$category` property.
147-
- If the query string contains extra parameters within the selected scope, the exception will be thrown -
148-
`?search[q]=input&search[c]=package&search[s]=desc`. Extra parameters outside the scope are allowed though -
146+
`$query` property, while `package` value - to `$category` property.
147+
- If the query string contains extra parameters within the selected scope, the exception will be thrown -
148+
`?search[q]=input&search[c]=package&search[s]=desc`. Extra parameters outside the scope are allowed though -
149149
`?search[q]=input&search[c]=package&user=john`.

docs/guide/en/parameters-resolvers.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Parameters' resolvers
22

33
This package offers multiple
4-
[custom implementations of parameters' resolver](https://github.com/yiisoft/middleware-dispatcher?tab=readme-ov-file#creating-your-own-implementation-of-parameters-resolver)
4+
[custom implementations of parameters' resolver](https://github.com/yiisoft/middleware-dispatcher?tab=readme-ov-file#creating-your-own-implementation-of-parameters-resolver)
55
from [Yii Middleware Dispatcher](https://github.com/yiisoft/middleware-dispatcher) package:
66

77
- [`HydratorAttributeParametersResolver`](#hydratorattributeparametersresolver)
@@ -85,11 +85,11 @@ $resolver = new HydratorAttributeParametersResolver(
8585
$dispatcher = new MiddlewareDispatcher(new MiddlewareFactory($container, $resolver), $eventDispatcher);
8686
```
8787

88-
More info about dependencies from [Yii Hydrator](https://github.com/yiisoft/hydrator) package can be found in its docs
88+
More info about dependencies from [Yii Hydrator](https://github.com/yiisoft/hydrator) package can be found in its docs
8989
and guide:
90-
90+
9191
- [attribute resolver factory](https://github.com/yiisoft/hydrator/blob/master/docs/guide/en/attribute-resolver-factory.md)
92-
- [type casting](https://github.com/yiisoft/hydrator/blob/master/docs/guide/en/typecasting.md)
92+
- [type casting](https://github.com/yiisoft/hydrator/blob/master/docs/guide/en/typecasting.md)
9393
- [hydrator](https://github.com/yiisoft/hydrator)
9494

9595
Using within a group of resolvers:
@@ -153,7 +153,7 @@ final class UpdatePostController
153153

154154
The used DTO is [request input](request-input.md) with [hydrator attribute](hydrator-attributes.md) applied.
155155

156-
> As an alternative, [Yii Validating Hydrator](https://github.com/yiisoft/hydrator-validator) can be used instead for
156+
> As an alternative, [Yii Validating Hydrator](https://github.com/yiisoft/hydrator-validator) can be used instead for
157157
> automatic validation of request input DTO.
158158
159159
### Adding to middleware dispatcher

docs/guide/en/request-input.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ final class UpdatePostInput implements RequestInputInterface
3636

3737
For more available options, see [Hydrator attributes](hydrator-attributes.md) section.
3838

39-
The main concept of request input is to ease automatic filling with according
39+
The main concept of request input is to ease automatic filling with according
4040
[resolver](parameters-resolvers.md#requestinputparametersresolver).
4141
It's possible to use hydrator directly too, though.
4242

4343
## Combining with validation
4444

45-
If you need validation features additionally, extend the DTO from `AbstractInput` class which also implements
45+
If you need validation features additionally, extend the DTO from `AbstractInput` class which also implements
4646
`ValidatedInputInterface`. This way you can use validation attributes for properties:
4747

4848
```php
@@ -86,5 +86,5 @@ $isValid = $result->isValid();
8686
$errorMessagesMap = $result->getErrorMessagesIndexedByPath();
8787
```
8888

89-
More thorough guide for working with the validation result is available in the
90-
[validator guide](https://github.com/yiisoft/validator/blob/1.x/docs/guide/en/result.md).
89+
More thorough guide for working with the validation result is available in the
90+
[validator guide](https://github.com/yiisoft/validator/blob/1.x/docs/guide/en/result.md).

docs/guide/pt-BR/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Yii Input HTTP
2+
3+
- [Hydrator attributes](hydrator-attributes.md)
4+
- [Request input](request-input.md)
5+
- [Parameters' resolvers](parameters-resolvers.md)
+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Atributos do Hydrator
2+
3+
Este pacote fornece alguns atributos adicionais para [hydrator](https://github.com/yiisoft/hydrator).
4+
5+
## Atributos de parâmetro
6+
7+
Esses atributos são usados para um único parâmetro DTO:
8+
9+
- `#[Query]` - mapeia com o parâmetro de consulta da solicitação.
10+
- `#[Body]` - mapeia com o parâmetro body da solicitação.
11+
- `#[Request]` - mapeia com o atributo da solicitação. Isso é útil quando o middleware grava o valor antes.
12+
- `#[UploadedFiles]` - mapeia com os arquivos carregados da solicitação.
13+
14+
O uso de todos os parâmetros disponíveis é mostrado abaixo no exemplo:
15+
16+
```php
17+
use Yiisoft\Input\Http\Attribute\Parameter\Body;
18+
use Yiisoft\Input\Http\Attribute\Parameter\Query;
19+
use Yiisoft\Input\Http\Attribute\Parameter\Request;use \Yiisoft\Input\Http\Attribute\Parameter\UploadedFiles;
20+
21+
final class UpdatePostInput
22+
{
23+
public function __construct(
24+
#[Query]
25+
private string $id,
26+
#[Body]
27+
private string $title,
28+
#[Body]
29+
private string $content,
30+
#[UploadedFiles]
31+
private $uploads,
32+
#[Request]
33+
private string $clientInfo = '';
34+
) {
35+
}
36+
37+
// getters
38+
}
39+
```
40+
41+
Aqui:
42+
43+
- O ID do post será mapeado a partir do parâmetro de consulta da solicitação;
44+
- Título e conteúdo serão mapeados a partir do corpo da solicitação;
45+
- Os uploads serão mapeados a partir dos arquivos carregados da solicitação;
46+
- As informações do cliente serão mapeadas a partir do atributo da solicitação.
47+
48+
### Personalização
49+
50+
Por padrão, espera-se que os parâmetros de solicitação tenham o mesmo nome das propriedades DTO. Para mudar isso, passe o nome
51+
ao anexar o atributo:
52+
53+
```php
54+
use Yiisoft\Input\Http\Attribute\Parameter\Body;
55+
use Yiisoft\Input\Http\Attribute\Parameter\Query;
56+
use Yiisoft\Input\Http\Attribute\Parameter\Request;
57+
use Yiisoft\Input\Http\Attribute\Parameter\UploadedFiles;
58+
59+
final class UpdatePostInput
60+
{
61+
public function __construct(
62+
#[Query('post_id')]
63+
private string $id,
64+
#[Body('post_title')]
65+
private string $title,
66+
#[Body('post_content')]
67+
private string $content,
68+
#[UploadedFiles('post_uploads')]
69+
private $uploads,
70+
#[Request('clientData')]
71+
private string $clientInfo = '';
72+
) {
73+
}
74+
}
75+
```
76+
77+
## Atributos de dados
78+
79+
Eles são mais organizados quando a fonte dos valores é comum:
80+
81+
- `#[FromQuery]` - mapeia com parâmetros de consulta da solicitação.
82+
- `#[FromBody]` - mapeia com os parâmetros do corpo da solicitação.
83+
84+
A diferença aqui é que esses atributos estão vinculados à classe como um todo, e não a um atributo individual:
85+
86+
```php
87+
use Yiisoft\Input\Http\Attribute\Data\FromBody;
88+
use Yiisoft\Input\Http\Attribute\Data\FromQuery;
89+
90+
#[FromQuery]
91+
final class SearchInput
92+
{
93+
public function __construct(
94+
private string $query,
95+
private string $category,
96+
) {
97+
}
98+
99+
// getters
100+
}
101+
102+
#[FromBody]
103+
final class CreateUserInput
104+
{
105+
public function __construct(
106+
private string $username,
107+
private string $email,
108+
) {
109+
}
110+
111+
// getters
112+
}
113+
```
114+
115+
`SearchInput` será mapeado a partir dos parâmetros de consulta, enquanto `CreateUserInput` será mapeado a partir do corpo da solicitação analisado.
116+
117+
### Personalização dos nomes dos parâmetros
118+
119+
Semelhante aos atributos de parâmetro, os nomes dos parâmetros da solicitação podem ser customizados. Aqui isso é feito através de um mapa onde as
120+
chaves são nomes e valores de propriedades DTO de acordo com os nomes dos parâmetros da solicitação, que são esperados. Além disso, você
121+
pode restringir o escopo de onde exatamente analisar os parâmetros da solicitação. Além disso, é possível lançar uma exceção
122+
quando existem alguns parâmetros presentes no escopo da solicitação selecionada que não foram especificados no mapa.
123+
124+
```php
125+
use Yiisoft\Input\Http\Attribute\Data\FromBody;
126+
use Yiisoft\Input\Http\Attribute\Data\FromQuery;
127+
128+
#[FromQuery(
129+
'search', // Use an array for bigger level of nesting, for example, `['client', 'search']`.
130+
['query' => 'q', 'category' => 'c'],
131+
strict: true,
132+
)]
133+
final class SearchInput
134+
{
135+
public function __construct(
136+
private string $query,
137+
private string $category,
138+
) {
139+
}
140+
}
141+
```
142+
143+
No exemplo acima:
144+
145+
- A string de consulta esperada no formato como - `?search[q]=input&search[c]=package`. O valor `input` é mapeado para a
146+
propriedade `$query`, enquanto o valor `package` - para a propriedade `$category`.
147+
- Se a string de consulta contiver parâmetros extras dentro do escopo selecionado, a exceção será lançada -
148+
`?search[q]=input&search[c]=pacote&search[s]=desc`. Parâmetros extras fora do escopo são permitidos -
149+
`?search[q]=input&search[c]=pacote&user=john`.

0 commit comments

Comments
 (0)