Download the PHP package hedgehoglab-engineering/php-declared-data without Composer

On this page you can find all versions of the php package hedgehoglab-engineering/php-declared-data. 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 php-declared-data

PHP Declared Data

This package provides attributes, contracts, and behaviors that simplify the creation and management of data classes in PHP applications.

In particular, it enables the use of sparse objects that can be hydrated from optional data submitted via PATCH requests in a RESTful API, allowing missing or nullable fields to be handled appropriately.

Table of Contents

Installation

Install the package via Composer:

Usage

Defining Data Classes

The easiest way to start to define a declared data object is to extend the AbstractDeclaredData class. Alternatively, you can compose your own using the provided contracts and traits. Then just define your properties in the constructor.

Interfaces

Interfaces define behaviors that can be implemented by data classes for different functionality.

ResolvableData

Implementing the ResolvableData interface allows a class to resolve its properties using the specified property type or a PHP 8 attribute.

LenientData

The LenientData interface allows the data object to ignore extra properties that are not defined in the class.

SparseData

The SparseData interface allows the data object to be instantiated without all required properties. The primary use case for this is transforming PATCH request data where missing properties without defaults may remain unset - i.e.: indicating that the field's value is not being modified.

Traits

Traits provide reusable functionality that can be applied to your data classes.

ArraysData

The ArraysData trait provides a toArray method to recursively convert a data instance into an array.

CollectsData

The CollectsData trait provides a static collect method which can convert an iterable value into a Illuminate\Support\Collection of instances of the defined class.

CreatesData

The CreatesData trait provides a static create method which can convert data into an instance of the defined class.

DeclaresData

The DeclaresData trait provides has, missing, only and except methods, which are useful for handling instances of declared data.

Attributes

The use of PHP attributes provides a mechanism for hinting how properties should be resolved.

CollectionOf

Transforms an array into an instance of Illuminate\Support\Collection containing instances of the specified class.

DateTimeFromFormat

Parses a date string into a DateTime object using a specified format and/or timezone.

JsonDecode

Decodes a JSON string into a PHP array or object.

MapArgumentName

Maps an input field name to a different property name in the data object.

Examples

Using Attributes in Data Classes

Here's an example of a data class using various attributes:

Testing

Code Formatting

Code Analysing

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.


All versions of php-declared-data with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version ^9.1 || ^10.0
php Version ^8.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 hedgehoglab-engineering/php-declared-data contains the following files

Loading the files please wait ...