Download the PHP package asko/hird without Composer

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

Hird

Latest Stable Version

Hirds, also known as housecarls, was a gathering of hirdmen, who functioned as the king's personal guards during the viking age and the early middle ages.

Hird

Hird is an extensible validation library for your data with sane defaults.

Installation

You can install the package via composer:

Usage

Hird takes in an array of $fields and an array of $rules.

The key of each item in the $fields array must correspond to the the key of each item in the $rules array, so that Hird would know how to connect the two to each other.

The $rules must have a value that is a string where the rules are separated by a | character, and each rule must match the key of the implemented validator, such as len, email or one that you have implemented yourself. Additionally, each rule can take in a modifier, where the name of the rule and the modifier is separated by a : character.

For example, say we have a validator called len which takes a modifier that lets that validator validate the length of a string, in such a case we'd write that rule as len:8, which would indicate using a len validator and passing a modifier with the value 8 to it.

Example usage

An example usage of Hird looks like this:

From the above example, you can see that there are two Hird methods being used such as $hird->fails() and $hird->errors(). The $hird->fails() method will run the validation and return a boolean depending on whether the validation failed or not, true if it did. The $hird->errors() method will return an array of all the errors that occured, as defined by the validators.

You can also get the first error rather than all errors by using the method $hird->firstError().

If you wish to run the validation without needing to call $hird->fails(), you can instead call $hird->validate().

Overwrite field names in validation messages

You can use $hird->setFieldNames to overwrite the field names for use within the error messages, so that email could become E-mail when shown to the user. Simply provide an array where the keys are the actual field names you instantiated Hird with and the values the names you'd like used in validation messages, like so:

Manually add an error

In some cases you want to use the same validator provided error messages, but want to mix-match them with validations you do outside of Hird. Well, for that you can use the addError method, like so:

Which will prompt Hird validation to fail and show that error message.

Built-in validators

There are a number of built-in validators available for use by default. If you want to remove a built-in validator, you can remove one using the $hird->removeValidator('rule-name') method.

email

The email validator validates an e-mail address, and it is registered as the email rule.

len

The len validator validates the length of a string, and it is registered as the len rule. The len validator also accepts, and requires, a modifier. A modifier can be passed to a rule by appending a color character : to it, and passing the modifier after it, like len:8.

required

The required validator validates the presence of value, and it is registered as the required rule. It will pass validation if the value is set and the value is not an empty string.

date-format

The date-format validator validates the string format of a date, and is registered as the date-format rule. It will pass validation if the value is set and the value is in the format specified by the rule.

Creating validators

You can also create your own validators, or replace existing ones if you're not happy with them.

Note: To replace an existing one, first remove the built-in validator via $hird->removeValidator('rule-name') and then add your own via $hird->registerValidator('rule-name', ValidatorClass::class).

A validator is a class that implements the Validator interface. A full example of a correct validator would look something like this:

You can see that there are two methods, one for validating the $value and the other for composing an error message if the validation fails. Both functions take in a $modifier argument, which will only have value if the validator is using modifiers. For example, the len validator is using modifiers to determine how long of a string should be required, by passing the rule in as len:{number-of-characters}.

Once you've created the class for your validator, you can register it by calling $hird->registerValidator('rule-name', YourValidator::class).


All versions of hird with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
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 asko/hird contains the following files

Loading the files please wait ....