Nette Documentation Preview

syntax
Nette NEON
**********

<div class=perex>

NEON は人にやさしいデータの直列化の言語です。Nette では設定ファイルに使われます。[api:Nette\Neon\Neon]は NEON を扱う静的なクラスです。

[NEON の形式|format]を知って、[試してみてください |https://fiddle.nette.org/neon/]。

</div>

すべての例で、次の別名が定義されているものとします。

```php
use Nette\Neon\Neon;
```


インストール
------

パッケージは [Composer|best-practices:composer]でダウンロードしてインストールします。

```shell
composer require nette/neon
```

`*.neon` のファイルに構文の誤りがないかは、`neon-lint` のコンソールのコマンドで確かめられます。

```shell
vendor/bin/neon-lint [--debug] <path>
```


encode(mixed $value, bool $blockMode=false, string $indentation="\t"): string .[method]
---------------------------------------------------------------------------------------

`$value` を NEON に変えて返します。`$blockMode` のパラメータに `true` を渡すと、複数行の出力を作れます。`$indentation` のパラメータは字下げに使う文字を指定します(既定はタブ)。

```php
Neon::encode($value); // $value を NEON に変えて返します
Neon::encode($value, true); // $value を複数行の NEON に変えて返します
```

`encode()` メソッドはエラーの場合に `Nette\Neon\Exception` を投げます。

```php
try {
	$neon = Neon::encode($value);
} catch (Nette\Neon\Exception $e) {
	// 例外の処理
}
```


decode(string $input): mixed .[method]
--------------------------------------

渡された NEON の文字列を PHP の値に変えます。

スカラー、配列、[日付 |format#日付]は DateTimeImmutable オブジェクトとして、[エンティティ |format#エンティティ]は [api:Nette\Neon\Entity]オブジェクトとして返します。

```php
Neon::decode('hello: world'); // 配列 ['hello' => 'world'] を返します
```

`decode()` メソッドはエラーの場合に `Nette\Neon\Exception` を投げます。

```php
try {
	$value = Neon::decode($neon);
} catch (Nette\Neon\Exception $e) {
	// 例外の処理
}
```


decodeFile(string $file): mixed .[method]
-----------------------------------------

ファイルの中身を NEON から PHP へ変え、BOM があれば取り除きます。

```php
Neon::decodeFile('config.neon');
```

`decodeFile()` メソッドはエラーの場合に `Nette\Neon\Exception` を投げます。


新しい版へ上げるなら、[アップグレード |upgrading]のページをご覧ください。

Nette NEON

NEON は人にやさしいデータの直列化の言語です。Nette では設定ファイルに使われます。Nette\Neon\Neonは NEON を扱う静的なクラスです。

NEON の形式を知って、試してみてください

すべての例で、次の別名が定義されているものとします。

use Nette\Neon\Neon;

インストール

パッケージは Composerでダウンロードしてインストールします。

composer require nette/neon

*.neon のファイルに構文の誤りがないかは、neon-lint のコンソールのコマンドで確かめられます。

vendor/bin/neon-lint [--debug] <path>

encode(mixed $value, bool $blockMode=false, string $indentation="\t")string

$value を NEON に変えて返します。$blockMode のパラメータに true を渡すと、複数行の出力を作れます。$indentation のパラメータは字下げに使う文字を指定します(既定はタブ)。

Neon::encode($value); // $value を NEON に変えて返します
Neon::encode($value, true); // $value を複数行の NEON に変えて返します

encode() メソッドはエラーの場合に Nette\Neon\Exception を投げます。

try {
	$neon = Neon::encode($value);
} catch (Nette\Neon\Exception $e) {
	// 例外の処理
}

decode(string $input): mixed

渡された NEON の文字列を PHP の値に変えます。

スカラー、配列、日付は DateTimeImmutable オブジェクトとして、エンティティNette\Neon\Entityオブジェクトとして返します。

Neon::decode('hello: world'); // 配列 ['hello' => 'world'] を返します

decode() メソッドはエラーの場合に Nette\Neon\Exception を投げます。

try {
	$value = Neon::decode($neon);
} catch (Nette\Neon\Exception $e) {
	// 例外の処理
}

decodeFile(string $file)mixed

ファイルの中身を NEON から PHP へ変え、BOM があれば取り除きます。

Neon::decodeFile('config.neon');

decodeFile() メソッドはエラーの場合に Nette\Neon\Exception を投げます。

新しい版へ上げるなら、アップグレードのページをご覧ください。