Download the PHP package peroks/model without Composer

On this page you can find all versions of the php package peroks/model. 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 model

Models: Classes with built-in data validation

The Model class extends the built-in PHP ArrayObject class with internal data validation and json support.

Reason why

Models can be used in any context, but they are especially useful in REST API applications, where validating incoming and outgoing data is often time-consuming, inconsistent, error-prone and hard to read/maintain.

Instead of bloating your project with code for validating data, you can let models validate themselves based on their property definition. You just define the properties and constraints of each model in one single place, and then validate model instances throughout your application in a consistent, efficient and clear manner.

Models are similar to database tables, where each model property corresponds to a table column. Install the Model Store package to automatically create database tables based on your models.

How to use

Create a model class

You define the model properties and constraints in a separate class for each model. Each model class must contain the static $properties property and extend the Model class or a subclass.

In the example below, we create a geo point model with two properties: latitude and longitude. Both properties are required, and they must be floating numbers in the range of -90 to 90 (latitude) and -180 to 180 (longitude).

You can extend models like any other class. The properties are inherited from the parent classes.

Create a model instance

There are several ways to create a model instance. The model constructor takes an assoc array, an object (including a model instance) or a json string. All the options below produce the same result.

Or you just create an empty model and add the property values later on.

Just like the ArrayObject parent class, you can also set (and get) model properties like an array.

Model validation

Since each model knows its property definitions and constraints, validating a model is a breeze.

Alternatively, you can let the validation throw a ModelException on failure.

Models are not validated on creation, only when Model::validate() is called.

Getting the model data

You can access the model data as an object or array

or get the model data as an assoc array.

JSON encoding

You can easily convert a model to JSON.

Nested models

Models can contain other models. You just add model with a class name to an object or array property.

If you add default values for sub-models, they are also created when the main model is created. On validation, sub-models are validated recursively too.

Nested models are especially useful for importing complex data structures from external sources. With models, decoding, converting and validating external data is a one-liner.

Supported property items

The PRIMARY, INDEX, UNIQUE, FOREIGN and MATCH property items are only used by peroks/model-store, a separate package for storing models in databases. There, they are used for creating indices and constraints.

VALUE and PROPERTIES are ony used for exporting model data including the model definition with Model::data( ModelData::PROPERTIES ).

Supported property types

Installing

You need composer to download and install this package. Just run composer require peroks/model in your project.


All versions of model with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
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 peroks/model contains the following files

Loading the files please wait ....