Download the PHP package friendsofhyperf/validated-dto without Composer

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

Validated DTO

Latest Stable Version Total Downloads License

The Data Transfer Objects with validation for Hyperf applications. Forked from laravel-validated-dto

Documentation

https://wendell-adriel.gitbook.io/laravel-validated-dto

Installation

Generating DTO

You can create DTO using the gen:dto command:

The DTO are going to be created inside app/DTO.

Defining Validation Rules

You can validate data in the same way you validate Request data:

Creating DTO instances

You can create a DTO instance on many ways:

From arrays

From JSON strings

From Request objects

From Model

Beware that the fields in the $hidden property of the Model won't be used for the DTO.

From Artisan Commands

You have three ways of creating a DTO instance from an Artisan Command:

From the Command Arguments

From the Command Options

From the Command Arguments and Options

Accessing DTO data

After you create your DTO instance, you can access any properties like an object:

If you pass properties that are not listed in the rules method of your DTO, this data will be ignored and won't be available in your DTO:

Defining Default Values

Sometimes we can have properties that are optional and that can have default values. You can define the default values for your DTO properties in the defaults function:

With the DTO definition above you could run:

Converting DTO data

You can convert your DTO to some formats:

To array

To JSON string

To Eloquent Model

Customizing Error Messages, Attributes and Exceptions

You can define custom messages and attributes implementing the messages and attributes methods in your DTO class:

Type Casting

You can easily cast your DTO properties by defining a casts method in your DTO:

Available Types

Array

For JSON strings, it will convert into an array, for other types, it will wrap them in an array.

Boolean

For string values, this uses the filter_var function with the FILTER_VALIDATE_BOOLEAN flag.

Carbon

This accepts any value accepted by the Carbon constructor. If an invalid value is found it will throw a \FriendsOfHyperf\ValidatedDTO\Exception\CastException exception.

You can also pass a timezone when defining the cast if you need that will be used when casting the value.

You can also pass a format when defining the cast to be used to cast the value. If the property has a different format than the specified it will throw a \FriendsOfHyperf\ValidatedDTO\Exception\CastException exception.

CarbonImmutable

This accepts any value accepted by the CarbonImmutable constructor. If an invalid value is found it will throw a \FriendsOfHyperf\ValidatedDTO\Exception\CastException exception.

You can also pass a timezone when defining the cast if you need that will be used when casting the value.

You can also pass a format when defining the cast to be used to cast the value. If the property has a different format than the specified it will throw a \FriendsOfHyperf\ValidatedDTO\Exception\CastException exception.

Collection

For JSON strings, it will convert into an array first, before wrapping it into a Collection object.

If you want to cast all the elements inside the Collection, you can pass a Castable to the CollectionCast constructor. Let's say that you want to convert all the items inside the Collection into integers:

This works with all Castable, including DTOCast and ModelCast for nested data.

DTO

This works with arrays and JSON strings. This will validate the data and also cast the data for the given DTO.

This will throw a Hyperf\Validation\ValidationException exception if the data is not valid for the DTO.

This will throw a FriendsOfHyperf\ValidatedDTO\Exception\CastException exception if the property is not a valid array or valid JSON string.

This will throw a FriendsOfHyperf\ValidatedDTO\Exception\CastTargetException exception if the class passed to the DTOCast constructor is not a ValidatedDTO instance.

Float

If a not numeric value is found, it will throw a FriendsOfHyperf\ValidatedDTO\Exception\CastException exception.

Integer

If a not numeric value is found, it will throw a FriendsOfHyperf\ValidatedDTO\Exception\CastException exception.

Model

This works with arrays and JSON strings.

This will throw a FriendsOfHyperf\ValidatedDTO\Exception\CastException exception if the property is not a valid array or valid JSON string.

This will throw a FriendsOfHyperf\ValidatedDTO\Exception\CastTargetException exception if the class passed to the ModelCast constructor is not a Model instance.

Object

This works with arrays and JSON strings.

This will throw a FriendsOfHyperf\ValidatedDTO\Exception\CastException exception if the property is not a valid array or valid JSON string.

String

If the data can't be converted into a string, this will throw a FriendsOfHyperf\ValidatedDTO\Exception\CastException exception.

Create Your Own Type Cast

You can easily create new Castable types for your project by implementing the FriendsOfHyperf\ValidatedDTO\Casting\Castable interface. This interface has a single method that must be implemented:

Let's say that you have a URLWrapper class in your project, and you want that when passing a URL into your DTO it will always return a URLWrapper instance instead of a simple string:

Then you could apply this to your DTO:

Contact

License

MIT


All versions of validated-dto with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
hyperf/code-parser Version ~3.1.0
hyperf/collection Version ~3.1.0
hyperf/context Version ~3.1.0
hyperf/stringable Version ~3.1.0
hyperf/validation Version ~3.1.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 friendsofhyperf/validated-dto contains the following files

Loading the files please wait ....