Download the PHP package ipagdevs/schema-builder without Composer

On this page you can find all versions of the php package ipagdevs/schema-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package schema-builder

PHP Schema Builder

Latest Version on Packagist Build Status Total Downloads

A powerful and intuitive library for building schema-driven data models in PHP. Validate, parse, and serialize complex data structures with ease, ensuring your data models are robust and reliable.

Features

Installation

Install the library via Composer:

Core Concepts

1. Model

The Model is the heart of the library. You extend the base IpagDevs\Model\Model class to create your own data models. Each model is responsible for defining its structure through a schema.

2. Schema

The Schema defines the "shape" of your data: its attributes, types, and validation rules. You define the schema within your model by implementing the schema() method.

3. Mutators

Mutators allow you to apply custom transformations to data when an attribute is set or retrieved. This is perfect for formatting, sanitizing, or deriving values.

Getting Started: A Simple Example

Let's create a simple Review model.

Now, let's use it to parse and handle data:

JSON Output:

Advanced Usage & Features

Here's a more comprehensive Product model that showcases many of the library's features.

Parsing Complex Data

You can now parse a complete data structure that matches the schema.

Attribute Types and Validation

Method Description
->required() The attribute must be present in the input data.
->nullable() The attribute can be null.
->default($value) Sets a default value if the attribute is not provided.
->min($value) For float or int, sets a minimum value.
->max($value) For float or int, sets a maximum value.
->limit($chars) For string, enforces a maximum character length.
->truncate($chars) For string, truncates the string if it exceeds the character limit.
->between($min, $max) For string, enforces a min and max character length.
->positives([...]) For bool, defines values that should be parsed as true.
->negatives([...]) For bool, defines values that should be parsed as false.
->list() or ->array() Converts an attribute into an array of its original type. Chainable.
->hidden() Hides the attribute from jsonSerialize() output.
->hiddenIf(callable $check) Hides the attribute from jsonSerialize() if the callback returns true.
->hiddenIfNull() A shortcut for hiding an attribute if its value is null.

Serialization

The library provides two ways to convert a model to an array.

jsonSerialize()

This method is automatically called by json_encode(). It respects the hidden(), hiddenIf(), and hiddenIfNull() rules, making it safe for public API responses. It also serializes nested models and collections.

toArray()

This method converts the model and all its relations into a "raw" array, including all attributes (even hidden ones). It's useful for debugging or internal data transfer.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs or feature requests.

License

The MIT License (MIT). Please see License File for more information.


All versions of schema-builder with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
symfony/polyfill-php81 Version ^1.28
symfony/polyfill-php80 Version ^1.28
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ipagdevs/schema-builder contains the following files

Loading the files please wait ...