nette/schema
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
nette/utils | v4.0.4 | 61.98 kB | (BSD-3-Clause OR GPL-2.0-only OR GPL-3.0-only) | prod | 1 |
Nette Schema is a pragmatic library specially designed for validation and normalization of data structures against a specific schema. With its intelligent and straightforward API interface, it provides a structured approach to data validation in a PHP environment. It is largely utilized in managing data inputs, such as those received via an API, configuration files, and user-provided data in web forms. This popular PHP Composer package ensures the integrity and accuracy of your data structures, promoting more efficient and less error-prone web applications.
To effectively use the Nette Schema, begin by installing the package via Composer using the command composer require nette/schema
. Once installed, Nette Schema's functionalities can be harnessed by creating validation schemas using the Nette\Schema\Expect
class. Data structures are then processed against these schemas using the Nette\Schema\Processor
class. For instance:
$processor = new Nette\Schema\Processor;
$schema = Expect::structure([
'processRefund' => Expect::bool(),
'refundAmount' => Expect::int(),
]);
$data = [
'processRefund' => true,
'refundAmount' => 17,
];
try {
$normalized = $processor->process($schema, $data);
} catch (Nette\Schema\ValidationException $e) {
echo 'Data is invalid: ' . $e->getMessage();
}
In this example, the $schema
defines the required data structure. The processor then attempts to normalize the $data
against the $schema
. If the $data
does not fit the structure defined in $schema
, a ValidationException
gets thrown.
For comprehensive understanding and detailed explanation of the different functionalities and usage of Nette Schema, refer to the official documentation on the Nette website at https://doc.nette.org/schema. This documentation provides an extensive, yet easy-to-understand, guide to effectively using Nette Schema. It includes clear examples, making the package more approachable for beginners and professionals alike, contributing to its increased usage in data validation and normalization.