Hello, this is simple attribute validation for PHP Models, based on the new features, presented in PHP 8

Overview

VMValidator

Hello, this is simple attribute validation for PHP Models, based on the new features, presented in PHP 8 It works as a standalone and can be use in custom projects or in libraries like Symfony and Laravel.

Use just three rows, alogside some attributes:

Example

test = $test; } } $test = new Test(40); try { MasterValidator::validate(new UpperTest($test), new OptionsModel(orderOfValidation: [ValidationOrderEnum::PROPERTIES, ValidationOrderEnum::METHODS, ValidationOrderEnum::CONSTANTS], excludedMethods: ['getFile'], excludedProperties: ['file'])); } catch(Exception $e) { var_dump($e); } ">
test = $test;
    }
}

$test = new Test(40);

try {
    MasterValidator::validate(new UpperTest($test), 
    new OptionsModel(orderOfValidation: [ValidationOrderEnum::PROPERTIES, 
                                         ValidationOrderEnum::METHODS,
                                         ValidationOrderEnum::CONSTANTS], 
                     excludedMethods: ['getFile'], 
                     excludedProperties: ['file']));
}
catch(Exception $e) {
    var_dump($e);
}

Installation

composer require ivangrigorov/vmvalidator

Options

In what order to validate the classes (methods or properties first), and what to exclude is directly configurable runtime here

Extras

  • Lots of validations
  • Supprots also nested object validation
  • Supprots also collection item types and collection item validations
  • Supprots also custom validations*
  • Nullable check
  • Repeatable validation attributes
  • Works with private properties and methods
  • Works with constructor promotion
  • Memory and time profiling
  • Custom error messages
  • Custom property and method names for the exceptions

*The custom validation should be declared as static in a validation class

class Validation {

    static function validate($valueToTest, $arg1) : bool {
        return $valueToTest == $arg1;
    }
}

The method should always return boolean: true for valid input and false for invalid.

In the declaration:

    #[CustomAttribute(staticClassName: Validation::class, staticMethodName: 'validate', args: [2])]

You can pass additional arguments to use in the validation function, but the first parameter is always the value to be tested.

Support

  • Request a new validation
  • Give a star
  • Just say hi !
You might also like...
Simple PHP framework that helps you quickly understand and write simple APIs.

Lightweight-PHP-Framework-For-APIs. Simple PHP framework that helps you quickly understand and write simple APIs. Installation Use the package manager

Simple PHP framework that helps you quickly understand and write simple APIs.

Lightweight PHP Framework For Web and APIs PHP framework that helps you write quickly simple but powerful web apps and APIs Installation Use the packa

๐Ÿš€ Coroutine-based concurrency library for PHP

English | ไธญๆ–‡ Swoole is an event-driven asynchronous & coroutine-based concurrency networking communication engine with high performance written in C++

High performance HTTP Service Framework for PHP based on Workerman.
High performance HTTP Service Framework for PHP based on Workerman.

webman High performance HTTP Service Framework for PHP based on Workerman. Manual https://www.workerman.net/doc/webman Benchmarks https://www.techempo

Symprowire is a PHP MVC Framework based and built on Symfony, using the ProcessWire CMS as DBAL and Service Provider.

Symprowire - PHP MVC Framework for ProcessWire 3.x Symprowire is a PHP MVC Framework based and built on Symfony using ProcessWire 3.x as DBAL and Serv

Bootcamp project based on PHP-MVC using MySQL database.
Bootcamp project based on PHP-MVC using MySQL database.

Up-Stream This is the implementation of a full website based on PHP MVC. Using MySql database to create a website. And Bootstrap4 for front-end. Start

The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)

gRPC - An RPC library and framework gRPC is a modern, open source, high-performance remote procedure call (RPC) framework that can run anywhere. gRPC

A server side alternative implementation of socket.io in PHP based on workerman.

phpsocket.io A server side alternative implementation of socket.io in PHP based on Workerman. Notice Only support socket.io v1.3.0 or greater. This pr

Jin microservices is a complete microservice demo based on PHP language + hyperf microservices framework
Jin microservices is a complete microservice demo based on PHP language + hyperf microservices framework

ไป‹็ป Jin-microservicesๆ˜ฏๅŸบไบŽ php ่ฏญ่จ€ + hyperf ๅพฎๆœๅŠก ๆก†ๆžถ็š„ๅฎŒๆ•ดๅพฎๆœๅŠกdemoใ€‚ github๏ผšhttps://github.com/Double-Jin/jin-microservices gitee๏ผšhttps://gitee.com/ljj96/jin-mic

Releases(2.4.2)
Owner
Ivan Grigorov
๐Ÿ‡ง๐Ÿ‡ฌ Software developer / Web / Mobile / Desktop
Ivan Grigorov
An enhanced FileInput widget for Bootstrap 4.x/3.x with file preview, multiple selection, and more features (sub repo split from yii2-widgets)

yii2-widget-fileinput The FileInput widget is a customized file input widget based on Krajee's Bootstrap FileInput JQuery Plugin. The widget enhances

Kartik Visweswaran 227 Nov 6, 2022
"Static" interface for various Slim features

SlimFacades SlimFacades is a collection of facades for Slim PHP microframework, providing simple "static" interface for various Slim features. For exa

its 74 May 12, 2022
๐Ÿ”ญ Proof of concept on adding observability features (tracing and metrics) to a Nano microservice (using existing Hyperf components).

?? Tracing Nano Proof of concept on adding observability features (tracing and metrics) to a Nano microservice (using existing Hyperf components ?? ).

Leo Cavalcante 4 Oct 24, 2022
:gem: Go! AOP PHP - modern aspect-oriented framework for the new level of software development

Go! Aspect-Oriented Framework for PHP Go! AOP is a modern aspect-oriented framework in plain PHP with rich features for the new level of software deve

Go! Aspect-Oriented Framework 1.6k Dec 29, 2022
Gracili is a PHP Application Template to quickly create a new Project

Gracili What is Gracili? Gracili is a PHP Application Template to quickly create a new Project. Using this template can save you a lot of time. With t

Bjรถrn Pfoster 1 May 12, 2021
Hamtaro - the new web framework for front-end / back-end development using Php and Javascript.

Hamtaro framework About Technologies Controllers Components Commands Front-end development Getting Started About Hamtaro is the new web framework for

Phil'dy Jocelyn Belcou 3 May 14, 2022
Silex Skeleton - a fully-functional Silex application that you can use as the skeleton for your new applications

Silex Skeleton - a fully-functional Silex application that you can use as the skeleton for your new applications

Silex 789 Dec 5, 2022
FuelPHP v1.x is a simple, flexible, community driven PHP 5.3+ framework, based on the best ideas of other frameworks, with a fresh start! FuelPHP is fully PHP 7 compatible.

FuelPHP Version: 1.8.2 Website Release Documentation Release API browser Development branch Documentation Development branch API browser Support Forum

Fuel 1.5k Dec 28, 2022
Framework X is a simple and fast micro framework based on PHP

Framework X is a simple and fast micro framework based on PHP. I've created a simple CRUD application to understand how it works. I used twig and I created a custom middleware to handle PUT, DELETE methods.

Mahmut Bayri 6 Oct 14, 2022
a framework for WebDevelop based on the mvc structure. The name of this project for Fun because everyone can use it. Completely simple and powerful structure for all your projects

A_A (-.-) โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ |-| โ–ˆโ–„โ”€โ–„โ–„โ”€โ–ˆโ–„โ”€โ–ˆโ–ˆโ”€โ–„โ–ˆโ”€โ–„โ–„โ–„โ–„โ–ˆโ”€โ–„โ–„โ–„โ–„โ–ˆโ–„โ”€โ–ˆโ”€โ–„โ–ˆโ”€โ–„โ–„โ–„โ”€โ–ˆโ–ˆโ–€โ–„โ”€โ–ˆโ–ˆโ”€โ–„

MasihGhaznavi 7 Jun 29, 2022