Download the PHP package samleybrize/valoa without Composer

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

Valoa - Easy value objects and entities

Installation

For a quick install with Composer use :

$ composer require samleybrize/valoa

Requirements

Usage

Traditionnaly, when you build value objects (or entities), you define properties as private and then you create a getter (and maybe a setter) for each of them. Valoa handles get and set operations without the need to create any method. All you need is to use the Samleybrize\Valoa\ValueObject\ValueObjectTrait trait.

Additionally, you can define constraints to your properties. On the example above, $var1 only accepts integer values, as specified by the @var tag.

Validation strictness

By default, validation is non-strict. For some validators, non-strict validation allows you to give a value of a different type that will be converted. For an integer property, you can set a string 123azerty that will be converted to the integer 123. Strict validation is enabled with the @strict tag. If strict validation is enabled on an integer property, only integers will be accepted.

Define the validator used

By default, the @var tag define which validator will be used. If for somme reason you need to put some funky value into that tag, you have to specify the validator with the @validator tag. If there is a @validator tag, the @var tag is always ignored.

If you don't want any validation on a property, use the any validator.

Immutable property

A property can be made immutable with the @immutable tag. Immutable properties can't be setted from outside.

You can make all properties immutable at once by setting the @immutable tag on the class.

Nullable property

A property can accept a null value with the @nullable tag.

Array types

Array types can be specified in several ways. The simplest method is to add [] to the tag. This way you can also validate multidimensional arrays, by adding as many [] as you want.

The other way of specifying array types is @var array and @validator setted to the underlying type. If there is no @validator tag, the validator any is used by default. This method does not allow to validate multidimensional arrays.

Enum validator

The enum validator allows you to define a list of accepted values with the @enum tag. Each allowed value should be scalar.

Class constants validator

The class constants validator define a set of class constants as allowed values. The @classname tag specify the full class name that contains allowed class constants. By default, all class constants in that class are allowed. You can restrict allowed values with the followin options :

Validator list

Validator Options Description Non strict
Any Allow any value
Boolean Allow boolean values Any scalar value
ClassConstants Allow constants values of a given class Any scalar value
beginWith Filter constant names
endWith Filter constant names
contain Filter constant names
Email Allow email adresses
Enum Allow a predefined list of values Any scalar value
Float Allow decimal values Any scalar value
min Min valid value
max Max valid value
Integer Allow integer values Any scalar value
min Min valid value
max Max valid value
Ip Allow IP addresses
String Allow strings Any scalar value
minLength Min valid string length
maxLength Max valid string length
regex Validation regex (ex: ^[0-9]+$)

Write your own validator

Custom validators can be created by implementing the Samleybrize\Valoa\ValueObject\Validator\ValidatorInterface interface.

To use it, you have to specify the full class name on the @validator tag.

Lazy loaders

Sometimes you want to retrieve some data on demand. All properties accept an instance of the Samleybrize\Valoa\ValueObject\ValueObjectLazyLoaderInterface interface regardless of its associated validator. When you first try to get its value, the lazy loader is used to retrieve the effective value and validates it using the validator. Next times, the lazy loader is no longer used.

Known limitations

Array types can't be directly modified from outside. Instead, you have two workarounds :

Author

This project is authored and maintained by Stephen Berquet.

License

Valoa is licensed under the MIT License - see the LICENSE file for details.


All versions of valoa with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
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 samleybrize/valoa contains the following files

Loading the files please wait ....