Download the PHP package james-harper/data-contracts without Composer

On this page you can find all versions of the php package james-harper/data-contracts. 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 data-contracts

Data Contracts

Data contracts defined here can be shared between multiple services.

This was originally designed for use with Laravel projects in mind, so there are some Laravel-specific convenience methods - dealing with validation rules or automatically converting to API resources, for example.

Todo and User data contracts have been included as examples. The following commands can be run to remove all traces of them.

Installation

This can be included in other packages via composer.

For any serious use, it is recommended to fork this repository and add data contracts that are appropriate to the domain you are working on. And then use the forked version via composer.

Defining Contracts

A data contract is defined in a JSON file which follows the JSON Schema specification.

The schema definition can be validated against the specification using the following command:

The id field of the resource (which will be id by default) will not be returned from the describe() method. If a resource is using something different as its identifier - for example guid - the contract's protected static $id property can be updated to reflect this.

PHP data contracts can be created by extending DataContracts\DataContract and then setting the $schema property as a link to the JSON definition. Schema paths should be relative to the project root. A RuntimeException will be thrown if no schema is defined.

DataContracts can be generated using the following composer command:

Usage

Each DataContract has a static describe() method which will return all of the fields on the contract (that are not considered private) and an all() method that will display everything.

There is also a validationRules() method that can be used to get any validation rules for the contract. These should use Laravel validation rules so that the output can be used directly for Request validation in Laravel projects. Transformers must be applied to get valid Laravel rules from a JSON Schema: these can be found in src/Rules.

Some helpers exist to make working with validation rules easier. validationRulesOptional() gets all rules but removes any required rules. This is useful for partial updates when not all fields would be expected. And rulesExcept($rule) can be used to filter out the chosen rule.

DataContracts can be used anywhere, but should be defined in this repository for shareability purposes.

Usage with Laravel Eloquent models

A DataContract can be used to filter Eloquent models down to only fields that are on the DataContract

Usage with Laravel API Resources

Simarly, DataContracts can be used to filter Laravel API Resources down to only fields that are on the DataContract

If any additional transformation needs to be performed, it is a case of simply overwriting the default transformation

CLI Tool

A CLI tool has been created to simplify common tasks and encourage the use of consistent patterns. It has been designed in a similar way to Laravel's artisan so it should feel familiar to use. It can be run using ./cli or php cli. Running the tool without any additional arguments will show the help screen which lists all available commands.

The following commands can be used:

For additional help with any command the following command can be run:

CLI documentation is stored in markdown files in console/docs

Tab completion for the CLI can be enabled by running the following command:

Notes


All versions of data-contracts with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
illuminate/cache Version ^8.12
illuminate/container Version ^8.12
illuminate/database Version ^8.12
illuminate/filesystem Version ^8.12
illuminate/http Version ^8.12
opis/json-schema Version ^1.0.19
psr/simple-cache Version ^1.0
symfony/console Version ^5.2
symfony/process Version ^5.2
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 james-harper/data-contracts contains the following files

Loading the files please wait ....