← ClaudeAtlas

nette-schemalisted

Provides Nette Schema for data validation and normalization. Use when validating configuration, API inputs, or any data structures with Expect class. Covers Expect::structure(), Expect::from(), anyOf, arrayOf, listOf, assert, transform, castTo, otherItems, and Processor. This is about nette/schema – not Nette Forms validation (addRule), not Nette\Utils\Validators, and not JSON Schema.
nette/agent-plugins · ★ 44 · API & Backend · score 81
Install: claude install-skill nette/agent-plugins
## Nette Schema A library for validating and normalizing data structures against a defined schema. Declare what correct data looks like, and Schema verifies and transforms input in one step. ```shell composer require nette/schema ``` ### When to Use Schema - **Configuration validation** – validate config arrays loaded from .neon files - **API input validation** – validate request data before processing - **Data import/transform** – normalize external data into typed structures - **DI extension config** – validate extension configuration in `loadConfiguration()` Schema is complementary to Nette Forms (which handles user input with UI) and database constraints (which enforce storage-level rules). Use Schema for programmatic data validation where there's no form UI. ### Basic Usage ```php use Nette\Schema\Expect; use Nette\Schema\Processor; $schema = Expect::structure([ 'name' => Expect::string()->required(), 'email' => Expect::email(), 'age' => Expect::int()->min(0)->max(120), ]); $processor = new Processor; try { $normalized = $processor->process($schema, $data); // $normalized is stdClass with validated data } catch (Nette\Schema\ValidationException $e) { echo 'Invalid: ' . $e->getMessage(); // $e->getMessages() returns array of all errors } ``` ### Data Types ```php Expect::string() // string, default null Expect::string('default') // string with default value Expect::int() // integer Expect::float() // float