Download the PHP package czim/laravel-dataobject without Composer

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

Laravel Data Object

Latest Version on Packagist Build Status Coverage Status Latest Stable Version SensioLabsInsight

Basic framework for making standardized but flexible data objects. This provides a class (and interfaces) to use to standardize your dependencies or return values with a generic dataobject.

All this really is, is a data storage class with magic getters and setters. It is Arrayable, Jsonable and validatable.

Also provided are the means to make nested validation possible for data objects (containing futher data objects).

Version Compatibility

Laravel Package PHP
5.1 1.0
5.2 1.0
5.3 1.3
5.4 1.4
5.5 and up 1.4, 2.0
9 and up 3.0 8.0 and up

Install

Via Composer

Usage

Simply create your own extension of the base dataobject, and:

Optionally add your own getters and setters

Basic stuff of course, but if you want your IDE to know what your objects contain, you can simply write getters and setters like this:

Additionally, if you want to block any type of magic assignment (meaning all assignment would have to be done through the setAttribute() or setAttributes() methods, or your own setters), you can disable magic assignment as follows:

Attempts to set attributes on the DataObject by magic or array access will then throw an UnassignableAttributeException.

Optionally add validation rules for attributes

Validating the data can be done as follows:

Messages are a MessageBag object generated by the Validator (whatever is behind the Laravel Facade Validator).

Validation

To use the extra Validation features for nested DataObject validation rules and better array validation, load the ServiceProvider for this package. This is the only reason to load the ServiceProvider; this package does not itself require the Provider to function.

Add this line of code to the providers array located in your config/app.php file:

Note that this will rebind the Validator facade, so if you have done this yourself, you may instead want to use the provided validation Traits to add to your own extended validator class.

Read more information about the validation (traits) here.

Castable Data Object

You may opt to extend the Czim\DataObject\CastableDataObject. Besides the standard features, this also includes the possibility of casting its properties to scalar values or (nested) data objects. This works similarly to Eloquent's $casts property (with some minor differences).

By overriding a protected casts() method, it is possible to set a cast type per attribute key:

This has the effect of casting each property to its set type before returning it.

toArray Casting

Cast types are also applied for the toArray() method of the data object. This means that unset properties will be present in the array as their default value (false for boolean, 0.0 for float, etc.).

To disable this behaviour, set $castToArray to false. This will entirely disable casting values on toArray().

Nested Object Casting

More useful than scalar-casting, is object casting. This will allow you to create a tree of nested objects that, if set, can be invoked fluently.

Given casts that are set as follows:

And with the following data example, you can access the data by property:

Note that unset or null values will return null, not an empty data object. Non-array values will cause exceptions to be thrown on being interpreted as data objects.

This behaviour can be changed by setting the $castUnsetObjects property to true: unset attributes with an object cast will then be cast as an empty instance of that object class.

Contributing

Please see CONTRIBUTING for details.

Credits

License

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


All versions of laravel-dataobject 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 czim/laravel-dataobject contains the following files

Loading the files please wait ....