Download the PHP package ovargas/fluentrules without Composer

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

Yii2 Fluent Rules

Latest Stable Version PHP Version PHPStan

A lightweight, expressive, and type-safe fluent validation interface for the Yii2 Framework.

Tired of maintaining massive, multi-dimensional array trees in your ActiveRecord models? This package replaces arbitrary array configurations with an elegant, IDE-discoverable object chain, dramatically improving code readability, refactoring safety, and static analysis precision.


Key Features


Installation

Install the package via Composer:


Why Use Yii2 Fluent Rules?

The Traditional Yii2 Approach

Standard validation rules in Yii2 depend heavily on raw nested arrays. They lack autocomplete support, are prone to typo errors, and quickly become hard to read:

The Fluent Rules Approach

With this library, your logic remains clear, readable, and perfectly discoverable by any modern IDE:


From Migration to Model in Seconds (Productivity Trick)

Because the fluent interface mirrors the fluid syntax used by Yii2's Schema Builder during database migrations, writing your model constraints becomes incredibly fast. You can literally copy your column definitions from a migration file, paste them into your model's rules() method, and apply a few multi-cursor edits in your IDE:

1. Your Migration File

2. Your Model Rules (After quick multi-cursor refactoring)


Advanced Usage: Hybrid Mode

One of the greatest design strengths of this package is its progressive migration support. If you have an established project with numerous core array rules, or you need to integrate specialized third-party inline validators, you can mix arrays and fluent configurations smoothly inside the same root array block:


Complete Exhaustive Reference Table

Every fluent method maps cleanly to an underlying specialized RuleBuilder class and compiles directly into its native Yii2 core counterpart:

Fluent Method Concrete Underlying Class Target Yii2 Validator Description / Sample Default Behavior
->boolean() BooleanRuleBuilder boolean Checks for standard boolean flags (0, 1, true, false).
->captcha() CaptchaRuleBuilder captcha Validates matching verification codes from a Captcha widget.
->compareAttr(string $otherAttr, ?string $op = null) CompareAttributeRuleBuilder compare Validates that the attribute matches another model field (e.g. password_repeat).
->compareValue(mixed $value, ?string $op = null) CompareValueRuleBuilder compare Compares value statically against a scalar using operators (==, >=, etc).
->custom(callable\|string $methodName) CustomRuleBuilder custom Executes inline closures or custom local validation methods.
->date(?string $format = null) DateRuleBuilder date Validates calendar dates.
->dateTime(?string $format = null) DateTimeRuleBuilder date Validates full ISO/custom timestamp dates.
->defaultValue(mixed $value = null) DefaultValueRuleBuilder default Assigns an explicit fallback value if input is empty.
->email() EmailRuleBuilder email Validates standard RFC email addressing.
->exist(string $class, string\|array\|null $attr) ExistRuleBuilder exist Assures record exists in database table (Defaults to skipOnError => true).
->file() FileRuleBuilder file Evaluates file upload properties (size, extension, mime types).
->filter(callable\|string\|null $filter = null) FilterRuleBuilder filter Processes input through a PHP callback (Defaults to skipOnEmpty => false).
->image() ImageRuleBuilder image Specialized file validator checking dimensions, width, and height.
->in(\Closure\|null\|iterable $range = null) RangeRuleBuilder in Ensures values exist inside a predefined iterable array.
->integer() IntegerRuleBuilder integer Ensures data represents a pure integer format.
->ip() IpRuleBuilder ip Validates IPv4 or IPv6 network addresses.
->match(string $pattern) RegularExpressionRuleBuilder match Checks input compliance against a custom Regex pattern.
->notNull() RequiredRuleBuilder required Shorthand alias. Validates that the attribute value is provided.
->number() NumberRuleBuilder number Validates that the input is a valid decimal/float number.
->range(\Closure\|null\|iterable $range = null) RangeRuleBuilder in Core Yii2 name endpoint. Ensures values exist inside an iterable collection.
->required() RequiredRuleBuilder required Core Yii2 name endpoint. Validates that the attribute value is provided.
->safe() SafeRuleBuilder safe Explicitly flags attributes as safe for massive assignments.
->string(?int $length = null) StringRuleBuilder string Core Yii2 name endpoint. Sets max length boundaries for string inputs.
->strim() TrimmedStringRuleBuilder trimmedString Custom combined builder to trim and evaluate strings sequentially.
->text(?int $length = null) StringRuleBuilder string Shorthand alias. Sets max length boundaries for string inputs.
->time(?string $format = null) TimeRuleBuilder date Validates custom temporal configurations (Forces internal type => time).
->timestamp() IntegerRuleBuilder integer Shorthand alias. Ensures data represents a pure integer format.
->trim() TrimRuleBuilder trim Strip whitespace from the beginning and end.
->unique(?string $targetClass = null) UniqueRuleBuilder unique Validates database unique indices to prevent duplicate entries.
->url() UrlRuleBuilder url Verifies well-formed URL syntax.

Global Parameters: All specialized builders inherit directly from RuleBuilder. This means structural parameters like ->on(), ->except(), ->message(), ->skipOnError(), ->skipOnEmpty(), ->enableClientValidation(), and execution callbacks like ->isEmpty(), ->when(), and ->whenClient() are universally available across all methods listed above.


Running Tests & Quality Control

The library features strict internal routing validation, ensuring compiled structures completely match the definitions expected by the Yii2 framework engine.

Run the test runner using PHPUnit:

Run static analysis using PHPStan:


Gii Integration (Automated Code Generation)

The package includes a built-in Gii Template and an automatic parsing utility (GiiHelper) that intercepts the native multi-dimensional array layouts generated by Yii2's Gii engine and seamlessly compiles them into clean, fluent architecture.

1. Enable the Template in your Application

Register the custom model template within your application configuration file (usually config/main-local.php or config/web.php under the development environment check):

2. Generate Your Fluent Models

2.1. Open Gii in your browser (/index.php?r=gii).

2.2. Go to the Model Generator.

2.3. Fill in your table details as usual.

2.4. Under the Code Template dropdown selection, choose "Fluent Rules".

2.5. Click Preview and then Generate.

3. Creating Custom Extensions (For Library Extenders)

If you or a third-party developer need to build a highly customized Gii template based on this package, you don't need to duplicate complex string-parsing algorithms. The GiiHelper::parseGiiRules() static method is globally available out of the box to process the core array definitions into clean fluent chains:

Gii Generation Notice & Feedback

Note: Since Gii code generation relies on strict string parsing of native array structures, highly complex rule definitions or uncommon core validators might occasionally render unexpected results.

If you encounter any bugs, edge cases, or incorrectly formatted fluent outputs, please do not hesitate to open an issue on our GitHub repository. Your feedback helps improve the parsing engine for the entire community!

License

This package is licensed under a Proprietary Hybrid License by Omar Vargas.

For commercial licensing inquiries, please contact the author directly.


All versions of fluentrules with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2.0
yiisoft/yii2 Version ~2.0.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 ovargas/fluentrules contains the following files

Loading the files please wait ...