strucura / schema
Build standardized schema definitions
Fund package maintenance!
Strucura
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9.2|^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^8.22.2|^9.0|^10.0
- pestphp/pest: ^2.34.6|^3.7
- pestphp/pest-plugin-laravel: ^2.3|^3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1.4|^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
README
Warning
This is not ready for production usage.
The Schema package provides a flexible and intuitive way to define and manage data schemas in PHP. It allows developers to create structured schemas with various property types, including strings, integers, booleans, arrays, objects, and enums. The package supports nested schemas, inline enums, and backed enums, making it ideal for building complex data structures. Designed for Laravel, it integrates seamlessly with the framework and includes tools for configuration, migrations, and views.
Installation
You can install the package via composer:
composer require strucura/schema
Usage
<?php use Strucura\Schema\Facades\Schema; use Strucura\Schema\Enums\PropertyTypeEnum; // Create an object schema $schema = Schema::object() // Add properties to the schema ->string('name', true) // Required string property ->integer('age', false) // Optional integer property ->enum('status', ['active', 'inactive'], true) // Required enum property ->float('price', true) // Required float property ->date('created_at', true) // Required date property ->object('address', function ($nested) { $nested->string('street', true); $nested->string('city', true); }, false); // Optional nested object // Convert the schema to an array $schemaArray = $schema->toArray(); // Output the schema print_r($schemaArray); // Renders [ 'type' => 'object', 'properties' => [ 'name' => [ 'type' => 'string', 'required' => true, ], 'age' => [ 'type' => 'integer', 'required' => false, ], 'status' => [ 'type' => 'enum', 'required' => true, 'enum' => ['active', 'inactive'], ], 'price' => [ 'type' => 'float', 'required' => true, ], 'created_at' => [ 'type' => 'date', 'required' => true, ], 'address' => [ 'type' => 'object', 'required' => false, 'properties' => [ 'street' => [ 'type' => 'string', 'required' => true, ], 'city' => [ 'type' => 'string', 'required' => true, ], ], ], ], ];
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.