Download the PHP package broeser/wellid without Composer

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

wellid

wellid is a set of PHP validators and a few loosely coupled components for validation.

Build Status codecov.io License SemVer 2.0.0

Latest stable version: 0.4.0

Goals

Installation

wellid works with PHP 5.6 and 7.0.

The package can be installed via composer:

composer require broeser/wellid

Before you start

Using wellid

Simple use case with validateBool()

The simplest usage case is creating a new validator and using the validateBool()-method. It takes the value that shall be validated as parameter and returns true on success and false on failure.

These are the validators supplied with wellid by default:

Error handling with validate() and ValidationResult

Sometimes it is important to know, why validation failed. If you need more than boolean true/false, you can use the validate()-method of a validator of your choice to get a ValidationResult-object. A ValidationResult includes an error message and error code if validation fails, you can use getCode() and getMessage() to retrieve them:

ValidationResultSets – A collection of ValidationResults

If you validate a value with several different validators, or if you validate a lot of different values you might need a better way of handling the results:

You can combine several ValidationResults to form a ValidationResultSet. You can add() a single ValidationResult to a ValidationResultSet or you can combine two ValidationResultSets with addSet()

ValidationResultSets can be count()-ed and iterated over with foreach().

hasErrors() is useful to check if there are any errors in the ValidationResultSet, its counterpart is called hasPassed(). You can retrieve the firstError()-ValidationResult (if there is any), if everything has passed the method will return null.

Validating objects with ValidatableTrait and ValidatableInterface

If you want to create classes (as opposed to primitive data types) whose instances are validateable by wellid, just implement the ValidatableInterface in your class and use the ValidatableTrait. If you prefer abstract classes instead, (e.g. if you want to override functionality from ValidatableTrait), extending AbstractValidatable is the way to go. In either case, Make sure to implement a getValue() method to supply the validators with a primitive typed version of your object's value. For a Money-class, for example, that might be a float.

You'll now be able to addValidators() to your object. You can validate your object with the validate() and validateBool() methods.

Note that validate() returns a ValidationResultSet and not a ValidationResult (see above).

The following example code uses three validators: The value shall be a floating point number. It shall be between 0 (zero) and 830.

Caching ValidationResultSets with CacheableValidatableTrait and CacheableValidatableInterface

If a lot of Validators are used in validating an object, caching might improve performance. In the last chapter each call to validate() or validateBool() starts validation anew. To add caching functionality use CacheableValidatableInterface instead of ValidatableInterface and CacheableValidatableTrait instead of ValidatableTrait. If you prefer an abstract class over traits and interfaces, extend AbstractCacheableValidatable. All cache-related functionality can be found in the \Wellid\Cache-namespace.

Like the cacheless variant, CacheableValidatable has to implement the getValue()-method.

Caching will be performed automatically.

If you want to disable caching for a particular instance of CacheableValidatableInterface, you can call disableValidationCache(). This will also remove a potentially existing ValidationResultSet from the cache of that instance.

While rarely useful, you can also force revalidation without disabling the cache. Clear the current ValidationResultSet with clearValidationResult(), then use validate() or validateBool() to get a new ValidationResultSet.

A collection of Validators – The ValidatorHolder

The way wellid is designed, you can always add validators directly to your data objects. However it might become handy to store a collection of validators separate from the data objects or even without having data objects.

You can use the ValidatorHolder-class directly, extend it by your own class, or you can create a class that implements ValidatorHolderInterface and may use the ValidatorHolderTrait to get some basic functionality.

Adding validators works the same as on data objects: You can use addValidators() or addValidator() (for a single validator). Use getValidators() to retrieve an array of all assigned validators.

To validate a value with the ValidatorHolder, use the validateValue()-method.

The AccountBalance-example from above becomes much cleaner and easier to understand.

Example:

Of course you don't have to setup the validators in the constructor in your own project, but you can just call addValidator or addValidators from anywhere.

Please note, that there is currently no validateBoolValue()-method for ValidatorHolders. If you need the boolean value you can use the syntax $validationResultAsBool = $accountBalanceValidators->validateValue($value)->hasPassed();

Another example shows, how to use ValidatorHolders with data objects. (Both used classes are the same as in the examples above):

Using wellid with Sanitor with SanitorBridgeTrait and SanitorBridgeInterface

Sanitor is a thin wrapper around PHP's sanitization functions (filter_var(), filter_input(), etc.). If you want to use Sanitor to sanitize input or arbitrary values before validating them with wellid, there is a handy piece of code called the SanitorBridgeTrait just for that.

Refer to Sanitor's README.md for more information. These are the four basic steps necessary to integrate Sanitor and wellid

  1. Install the Sanitor package (composer require broeser/sanitor)
  2. Substitute the ValidatableTrait and CacheableValidatableTraits with the SanitorBridgeTrait in all places.
  3. Make sure that those classes implement SanitorBridgeInterface
  4. Make sure that those classes call $this->setSanitizer(...) somewhere before validation (e. g. in the constructor) and set a fitting sanitization filter (you can try FILTER_DEFAULT)

SanitorBridge automatically uses caching. You don't have to clear the cache when setting a new rawValue, this will be done automatically.

Imagine you are expecting an integer as value, but the user enters 65{ instead. Depending on your business logic, two different cases are possible:

  1. Ignore the { and assume 65, continue working with 65. Optionally notify the user of this – this makes sense if there is an undo anyway and you don't want to annoy your users with error messages.
  2. Return an error message and ask for the value again – this makes sense if the user is not expected to notice/fix the mistake, or if valid data is more important than user experience

The first case is the default setting.

For the second case, just add a SanitorMatch-Validator to your object before starting validation. The SanitorMatch-Validator expects the validatable object itself as parameter on construction. The Validator uses "The given value contains illegal characters" as error message, if validation fails.

Luckily there is a shorter way to accomplish the same with the method addSanitorMatchValidator():

Exceptions

Feel free to use the Exception-classes supplied with wellid in any validation context you want to.

Contributing?

Yes, please!

See CONTRIBUTING.md for details and/or open an issue with your questions.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

wellid?

Yes, it is a pun on well and valid.


All versions of wellid with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.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 broeser/wellid contains the following files

Loading the files please wait ....