You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: http/cs/request.texy
+15-8
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,9 @@ HTTP request
4
4
.[perex]
5
5
Nette zapouzdřuje HTTP požadavek do objektů se srozumitelným API a zároveň poskytuje sanitizační filtr.
6
6
7
-
HTTP požadavek představuje objekt [api:Nette\Http\Request], ke kterému se dostanete tak, že si jej necháte předat pomocí [dependency injection |dependency-injection:passing-dependencies]. V presenterech stačí jen zavolat `$httpRequest = $this->getHttpRequest()`.
7
+
HTTP požadavek představuje objekt [api:Nette\Http\Request]. Pokud pracujete s Nette, tento objekt je automaticky vytvořen frameworkem a můžete si jej nechat předat pomocí [dependency injection |dependency-injection:passing-dependencies]. V presenterech stačí jen zavolat metodu `$this->getHttpRequest()`. Pokud pracujete mimo Nette Framework, můžete si vytvořit objekt pomocí [RequestFactory|#RequestFactory].
8
8
9
-
Co je důležité, tak že Nette když [vytváří|#RequestFactory] tento objekt, všechny vstupní parametry GET, POST, COOKIE a také URL pročistí od kontrolních znaků a neplatných UTF-8 sekvencí. Takže s daty pak můžete bezpečně dále pracovat. Očištěná data se následně používají v presenterech a formulářích.
9
+
Velkou předností Nette je, že při vytváření objektu automaticky pročišťuje všechny vstupní parametry GET, POST, COOKIE a také URL od kontrolních znaků a neplatných UTF-8 sekvencí. S těmito daty pak můžete bezpečně dále pracovat. Očištěná data se následně používají v presenterech a formulářích.
10
10
11
11
→ [Instalace a požadavky |@home#Instalace]
12
12
@@ -199,28 +199,35 @@ echo $httpRequest->detectLanguage($langs); // en
199
199
RequestFactory
200
200
==============
201
201
202
-
Objekt aktuálního HTTP requestu vyrobí [api:Nette\Http\RequestFactory]. Pokud píšete aplikaci, která nepoužívá DI kontejner, vyrobíte request takto:
202
+
Třída [api:Nette\Http\RequestFactory] slouží k vytvoření instance `Nette\Http\Request`, která reprezentuje aktuální HTTP požadavek. (Pokud pracujete s Nette, objekt HTTP požadavku je automaticky vytvořen frameworkem.)
203
203
204
204
```php
205
205
$factory = new Nette\Http\RequestFactory;
206
206
$httpRequest = $factory->fromGlobals();
207
207
```
208
208
209
-
RequestFactory lze před zavoláním `fromGlobals()` konfigurovat. Můžeme vypnout sanitizaci vstupních parametrů od kontrolních znaků a neplatných UTF-8 sekvencí pomocí `$factory->setBinary()`. A také nastavit proxy server pomocí `$factory->setProxy(...)`, což je důležité pro správnou detekci IP adresy uživatele.
209
+
Metoda `fromGlobals()` vytvoří objekt požadavku na základě aktuálních globálních proměnných PHP (`$_GET`, `$_POST`, `$_COOKIE`, `$_FILES` a `$_SERVER`). Při vytváření objektu automaticky pročišťuje všechny vstupní parametry GET, POST, COOKIE a také URL od kontrolních znaků a neplatných UTF-8 sekvencí, což zajišťuje bezpečnost při další práci s těmito daty.
210
210
211
-
Pomocí tzv. filtrů lze URL vyčistit od znaků, které se do něj mohou dostat např. kvůli špatně implementovaným komentářovým systémům na různých cizích webech:
211
+
RequestFactory lze před zavoláním `fromGlobals()` konfigurovat:
212
+
213
+
- metodou `$factory->setBinary()` vypnete automatické čištění vstupních parametrů od kontrolních znaků a neplatných UTF-8 sekvencí.
214
+
- metodou `$factory->setProxy(...)` uvedete IP adresu [proxy serveru |configuration#HTTP proxy], což je nezbytné pro správnou detekci IP adresy uživatele.
215
+
216
+
RequestFactory umožňuje definovat filtry, které automaticky transformují části URL požadavku. Tyto filtry odstraňují nežádoucí znaky z URL, které tam mohou být vloženy například nesprávnou implementací komentářových systémů na různých webech:
212
217
213
218
```php
214
-
// odstraníme mezery z cesty
219
+
// odstranění mezer z cesty
215
220
$requestFactory->urlFilters['path']['%20'] = '';
216
221
217
-
// odstraníme tečku, čárku nebo pravou závorku z konce URI
222
+
// odstranění tečky, čárky nebo pravé závorky z konce URI
První klíč `'path'` nebo `'url'` určuje, na kterou část URL se filtr použije. Druhý klíč je regulární výraz, který se má vyhledat, a hodnota je náhrada, která se použije místo nalezeného textu.
Copy file name to clipboardexpand all lines: http/cs/response.texy
+1-1
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ HTTP response
4
4
.[perex]
5
5
Nette zapouzdřuje HTTP odpověď do objektů se srozumitelným API.
6
6
7
-
HTTP odpověď představuje objekt [api:Nette\Http\Response], ke kterému se dostanete tak, že si jej necháte předat pomocí [dependency injection |dependency-injection:passing-dependencies]. V presenterech stačí jen zavolat `$httpResponse = $this->getHttpResponse()`.
7
+
HTTP odpověď představuje objekt [api:Nette\Http\Response]. Pokud pracujete s Nette, tento objekt je automaticky vytvořen frameworkem a můžete si jej nechat předat pomocí [dependency injection |dependency-injection:passing-dependencies]. V presenterech stačí jen zavolat metodu `$this->getHttpResponse()`.
Třída [api:Nette\Http\UrlImmutable] je immutable (neměnnou) alternativou třídy `Url` (podobně jako je v PHP `DateTimeImmutable` neměnnou alternativou `DateTime`). Místo setterů má tzv. withery, které objekt nemění, ale vracejí nové instance s upravenou hodnotou:
134
+
Třída [api:Nette\Http\UrlImmutable] je immutable (neměnnou) alternativou třídy [#Url] (podobně jako je v PHP `DateTimeImmutable` neměnnou alternativou `DateTime`). Místo setterů má tzv. withery, které objekt nemění, ale vracejí nové instance s upravenou hodnotou:
Třída [api:Nette\Http\UrlScript] je potomkem `UrlImmutable` a navíc rozlišuje tyto další logické části URL:
233
+
Třída [api:Nette\Http\UrlScript] je potomkem [#UrlImmutable] a rozšiřuje jej o další virtuální komponenty URL, jako je kořenový adresáři projektu apod. Stejně jako rodičovská třída je immutable (neměnným) objektem.
234
+
235
+
Následující diagram zobrazuje komponenty, které UrlScript rozpoznává:
234
236
235
237
/--pre
236
238
baseUrl basePath relativePath relativeUrl
@@ -242,6 +244,13 @@ Třída [api:Nette\Http\UrlScript] je potomkem `UrlImmutable` a navíc rozlišuj
242
244
scriptPath pathInfo
243
245
\--
244
246
247
+
- `baseUrl` je základní URL adresa aplikace včetně domény a části cesty ke kořenovému adresáři aplikace
248
+
- `basePath` je část cesty ke kořenovému adresáři aplikace
249
+
- `scriptPath` je cesta k aktuálnímu skriptu
250
+
- `relativePath` je název skriptu (případně další segmenty cesty) relativní k basePath
251
+
- `relativeUrl` je celá část URL za baseUrl, včetně query string a fragmentu.
252
+
- `pathInfo` dnes už málo využívaná část URL za názvem skriptu
253
+
245
254
Pro vrácení částí URL jsou k dispozici metody:
246
255
247
256
.[language-php]
@@ -254,4 +263,4 @@ Pro vrácení částí URL jsou k dispozici metody:
Objekty `UrlScript` přímo nevytváříme, ale vrací jej metoda [Nette\Http\Request::getUrl()|request].
266
+
Objekty `UrlScript` obvykle přímo nevytváříme, ale vrací jej metoda [Nette\Http\Request::getUrl()|request] s již správně nastavenými komponentami pro aktuální HTTP požadavek.
Copy file name to clipboardexpand all lines: http/en/request.texy
+15-8
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,9 @@ HTTP Request
4
4
.[perex]
5
5
Nette encapsulates the HTTP request into objects with an understandable API while providing a sanitization filter.
6
6
7
-
An HTTP request is an [api:Nette\Http\Request] object, which you get by passing it using [dependency injection |dependency-injection:passing-dependencies]. In presenters simply call `$httpRequest = $this->getHttpRequest()`.
7
+
HTTP request is represented by the [api:Nette\Http\Request] object. If you work with Nette, this object is automatically created by the framework and you can have it passed to you using [dependency injection |dependency-injection:passing-dependencies]. In presenters, you just need to call the `$this->getHttpRequest()` method. If you work outside the Nette Framework, you can create the object using [RequestFactory|#RequestFactory].
8
8
9
-
What is important is that Nette when [creating|#RequestFactory] this object, it clears all GET, POST and COOKIE input parameters as well as URLs of control characters and invalid UTF-8 sequences. So you can safely continue working with the data. The cleaned data is then used in presenters and forms.
9
+
A major advantage of Nette is that when creating the object, it automatically sanitizes all input parameters GET, POST, COOKIE as well as URL from control characters and invalid UTF-8 sequences. You can then safely work with this data. The sanitized data is subsequently used in presenters and forms.
10
10
11
11
→ [Installation and requirements |@home#Installation]
12
12
@@ -199,28 +199,35 @@ echo $httpRequest->detectLanguage($langs); // en
199
199
RequestFactory
200
200
==============
201
201
202
-
The object of the current HTTP request is created by [api:Nette\Http\RequestFactory]. If you are writing an application that does not use a DI container, you create a request as follows:
202
+
The [api:Nette\Http\RequestFactory] class is used to create an instance of `Nette\Http\Request`, which represents the current HTTP request. (If you work with Nette, the HTTP request object is automatically created by the framework.)
203
203
204
204
```php
205
205
$factory = new Nette\Http\RequestFactory;
206
206
$httpRequest = $factory->fromGlobals();
207
207
```
208
208
209
-
RequestFactory can be configured before calling `fromGlobals()`. We can disable all sanitization of input parameters from invalid UTF-8 sequences using `$factory->setBinary()`. And also set up a proxy server, which is important for the correct detection of the user's IP address using `$factory->setProxy(...)`.
209
+
The `fromGlobals()` method creates a request object based on the current PHP global variables (`$_GET`, `$_POST`, `$_COOKIE`, `$_FILES` and `$_SERVER`). When creating the object, it automatically cleanses all input parameters GET, POST, COOKIE as well as URL from control characters and invalid UTF-8 sequences, which ensures security when working with this data later.
210
210
211
-
It's possible to clean up URLs from characters that can get into them because of poorly implemented comment systems on various other websites by using filters:
211
+
RequestFactory can be configured before calling `fromGlobals()`:
212
+
213
+
- using the method `$factory->setBinary()` you can disable automatic cleansing of input parameters from control characters and invalid UTF-8 sequences.
214
+
- using the method `$factory->setProxy(...)` you specify the IP address of the [proxy server |configuration#HTTP proxy], which is necessary for correct detection of the user's IP address.
215
+
216
+
RequestFactory allows you to define filters that automatically transform parts of the URL request. These filters remove unwanted characters from URLs that may have been inserted, for example, by incorrect implementation of comment systems on various websites:
212
217
213
218
```php
214
-
// remove spaces from path
219
+
// removing spaces from the path
215
220
$requestFactory->urlFilters['path']['%20'] = '';
216
221
217
-
// remove dot, comma or right parenthesis form the end of the URL
222
+
// removing a period, comma, or right parenthesis from the end of the URI
The first key `'path'` or `'url'` determines which part of the URL the filter will be applied to. The second key is a regular expression to be searched for, and the value is the replacement to be used instead of the found text.
Copy file name to clipboardexpand all lines: http/en/response.texy
+1-1
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ HTTP Response
4
4
.[perex]
5
5
Nette encapsulates the HTTP response into objects with an understandable API while providing a sanitization filter.
6
6
7
-
An HTTP response is an [api:Nette\Http\Response] object, which you get by passing it using [dependency injection |dependency-injection:passing-dependencies]. In presenters simply call `$httpResponse = $this->getHttpResponse()`.
7
+
HTTP response is represented by the [api:Nette\Http\Response] object. If you work with Nette, this object is automatically created by the framework and you can have it passed to you using [dependency injection |dependency-injection:passing-dependencies]. In presenters, you just need to call the `$this->getHttpResponse()` method.
8
8
9
9
→ [Installation and requirements |@home#Installation]
The class [api:Nette\Http\UrlImmutable] is an immutable alternative to class `Url` (just as in PHP `DateTimeImmutable` is immutable alternative to `DateTime`). Instead of setters, it has so-called withers, which do not change the object, but return new instances with a modified value:
134
+
The [api:Nette\Http\UrlImmutable] class is an immutable alternative to the [#Url] class (similar to how `DateTimeImmutable` is an immutable alternative to `DateTime` in PHP). Instead of setters, it has withers, which do not change the object but return new instances with the modified value:
The [api:Nette\Http\UrlScript] class is a descendant of `UrlImmutable` and additionally distinguishes these logical parts of the URL:
233
+
The [api:Nette\Http\UrlScript] class is a descendant of [#UrlImmutable] and extends it with additional virtual URL components, such as the root directory of the project, etc. Like its parent class, it is an immutable object.
234
+
235
+
The following diagram shows the components that UrlScript recognizes:
234
236
235
237
/--pre
236
238
baseUrl basePath relativePath relativeUrl
@@ -242,6 +244,13 @@ The [api:Nette\Http\UrlScript] class is a descendant of `UrlImmutable` and addit
242
244
scriptPath pathInfo
243
245
\--
244
246
247
+
- `baseUrl` is the base URL of the application including domain and part of the path to the root directory of the application
248
+
- `basePath` is part of the path to the root directory of the application
249
+
- `scriptPath` is the path to the current script
250
+
- `relativePath` is the script name (and possibly additional path segments) relative to basePath
251
+
- `relativeUrl` is the entire part of the URL after baseUrl, including query string and fragment.
252
+
- `pathInfo` is a now rarely used part of the URL after the script name
253
+
245
254
The following methods are available to get these parts:
246
255
247
256
.[language-php]
@@ -254,5 +263,4 @@ The following methods are available to get these parts:
0 commit comments