Download the PHP package piggly/php-value-types without Composer

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

Values objects with based in data types

Versão Atual Latest Version on Packagist Packagist Downloads Packagist Stars PHP

This library was developed mainly to API systems. But, it may be applied to any systems.

What is Value Object?

A value object is a small object that represents a simple entity whose equality is not based on identity: i.e. two value objects are equal when they have the same value, not necessarily being the same object. Examples of value objects are objects representing an amount of money or a date range. See more.

Installation

Composer

  1. At you console, in your project folder, type composer require piggly/php-value-types;
  2. Don't forget to add Composer's autoload file at your code base require_once('vendor/autoload.php);.

Manual install

  1. Download or clone with repository with git clone https://github.com/piggly-dev/php-value-types.git;
  2. After, goes to cd /path/to/piggly/php-value-types;
  3. Install all Composer's dependencies with composer install;
  4. Add project's autoload file at your code base require_once('/path/to/piggly/php-value-types/vendor/autoload.php);.

Dependencies

The library has the following external dependencies:

How can it help?

Imagine an application which handle e-mails. E-mails, even with different values, have the same behavior. They have a pattern and must always be an e-mail. Across your application services, they are many entities with e-mails, such as: users, orders, companies and so on.

Without value objects you may need, in any entity which e-mails are available, checking the e-mail pattern. But, with a value object you may set this behavior and instead usign a primite type as string, you will use the EmailType object.

Any point of your application, it will know by all that EmailType handle an e-mail and always return a valid e-mail. Your business logic does not need to care about how to handle e-mails, because you EmailType object does.

How this library work?

Into the API enviroment, they are lot of data we can handle. But not just the pure data, but sometimes we must check if data is filled when required or if data meets the requirements of limit, length and so on.

This library standartize different values types as objects. And any value object may have one or more assertions to be a valid data as expected by your type. This make the process of validation fast and consisious, where you API must not care about how to handle data, because values objects do.

Any value object must extends AbstractValueType which consist of an immutable $value that once is set, will never change and must be the expected value type.

The AbstractValueType take care of object assertions, setting a default value or convert any child class to a string with __toString() method.

How do assertions work?

Assertions are runned by three methods:

You can add assertions to a value type object by using the apply( $rule ) method. The $rule method, must be an object which implements Piggly\ValueTypes\Interfaces\Validatable or Respect\Validation\Validatable inteface.

By default, objects may implement assertions at constructor method.

The required behavior

The only assertion implemented to any AbstractValueType is the required behavior. When constructing a value type object you may set the $required argument as true. If this happen, then AbstractValueType will evaluate if $value is null and required to throw InvalidValueTypeOfException before any assertions, or when $value is null but not required will assert value stopping any other assertions.

Assertion caching

Since a value object is immutable, the assertion must run only once. So, after run the fisrt time they are cached, and even you call any assertion method it will always return the same result.

But, there is an exception. If you apply a new assertion to the value object, it will lose cache and run only once again.

Common Objects

Basically, the common objects take care about parsing. They will always parse any $value you set at constructor to expected data type. There are six common objects, they extends and replaces the primitive data types. See:

The ArrayType and JsonType are the only value types that will throw an InvalidValueTypeOfException at constructor if they can't parse value to the expected type.

Advanced Objects

They are self explainer, different than Common Objects they handle more specific behaviors and patterns. See:

Masking Behavior

Some Advanced Objects has the capability to mask its data: i.e. the [email protected] can be masked to e******@g****.com or e*@g*.com. Masked objects extends AbstractMaskedType and have two methods:

Mask a value will never mutate the value object. It means if you have new EmailType('[email protected]) and want to persist the masked value or make only the masked value available you must: new EmailType( $emailType->masked() );.

Password enhanced behavior

Encryptation

The PasswordType object has and enhanced behavior.

When constructing it, the constructor will evaluate if password is encrypted with password_hash() native function or not. When not, it will encrypt following the options set with PasswordType::hash() static method. By default, encryptation will use the \PASSWORD_BCRYPT algorithm with default options.

After hashing, you will never ever get back the raw password. But, you can always verify hash with the check( $raw ) method.

Strength

Otherside, still in constructor, it will evaluate the password strengthness with the PasswordStrengthLib objects and throw an InvalidValueTypeOfException if password does not meet the minimum strength required.

PasswordStrengthLib is an interface which implements:

By default, there are three libs available in this library:

The PasswordBasicLib is applied by default to PasswordType object. Implementing all libs available increases the password strength checker accuracy.

Custom Objects

You can create anytime custom objects always extending the AbstractValueType and preparing its own assertions.

Samples

You can see very lightweight samples at /samples folder.

Changelog

See the CHANGELOG file for information about all code changes.

Testing the code

This library uses the PHPUnit. We carry out tests of all the main classes of this application.

You must always run tests with PHP 7.2 and greater.

Contributions

See the CONTRIBUTING file for information before submitting your contribution.

Credits

Support the project

Piggly Studio is an agency located in Rio de Janeiro, Brazil. If you like this library and want to support this job, be free to donate any value to BTC wallet 3DNssbspq7dURaVQH6yBoYwW3PhsNs8dnK ❤.

License

MIT License (MIT). See LICENSE.


All versions of php-value-types with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2 || ^8.0
bjeavons/zxcvbn-php Version ^1.2
respect/validation Version ^2.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 piggly/php-value-types contains the following files

Loading the files please wait ....