-
-
Notifications
You must be signed in to change notification settings - Fork 281
/
@home.texy
90 lines (58 loc) · 2.11 KB
/
@home.texy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
NEON Functions
**************
<div class=perex>
NEON is a human-friendly data serialization language. It is used in Nette for configuration files. [api:Nette\Neon\Neon] is a static class for working with NEON.
Get to know [NEON format|format] and [try it out |https://ne-on.org].
</div>
The following examples use these aliases:
```php
use Nette\Neon\Neon;
```
Installation
------------
Download and install the package using [Composer|best-practices:composer]:
```shell
composer require nette/neon
```
You can check for syntax errors in `*.neon` files using the `neon-lint` console command:
```shell
vendor/bin/neon-lint <path>
```
encode(mixed $value, bool $blockMode=false, string $indentation="\t"): string .[method]
---------------------------------------------------------------------------------------
Returns `$value` converted to NEON. As the parameter `$blockMode` you can pass true, which will create multiline output. The parameter `$indentation` specifies the characters used for indentation (default is tab).
```php
Neon::encode($value); // Returns $value converted to NEON
Neon::encode($value, true); // Returns $value converted to multiline NEON
```
Method `encode()` throws `Nette\Neon\Exception` on error.
```php
try {
$neon = Neon::encode($value);
} catch (Nette\Neon\Exception $e) {
// Exception handling
}
```
decode(string $neon): mixed .[method]
-------------------------------------
Converts given NEON to PHP value.
Returns scalars, arrays, [date|format#dates] as DateTimeImmutable objects, and [entities|format#Entities] as [api:Nette\Neon\Entity] objects.
```php
Neon::decode('hello: world'); // Returns an array ['hello' => 'world']
```
Method `decode()` throws `Nette\Neon\Exception` on error.
```php
try {
$value = Neon::decode($neon);
} catch (Nette\Neon\Exception $e) {
// Exception handling
}
```
decodeFile(string $file): mixed .[method]
-----------------------------------------
Converts the contents of the file from NEON to PHP and removes any BOM.
```php
Neon::decodeFile('config.neon');
```
Method `decodeFile()` throws `Nette\Neon\Exception` on error.
{{leftbar: utils:@left-menu}}