PHPackages                             dashifen/validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. dashifen/validator

ActiveProject[Validation &amp; Sanitization](/categories/validation)

dashifen/validator
==================

An interface and abstract class useful for the production of objects which validate data.

3.0.0(4y ago)04.9kMITPHPPHP &gt;=7.3

Since Sep 14Pushed 4y ago1 watchersCompare

[ Source](https://github.com/dashifen/validator)[ Packagist](https://packagist.org/packages/dashifen/validator)[ RSS](/packages/dashifen-validator/feed)WikiDiscussions main Synced 4d ago

READMEChangelogDependencies (2)Versions (20)Used By (0)

Validators
==========

[](#validators)

Here we define an interface for Validators as well as an Abstract class from which concrete objects that validate data based on field names can be built. The goal: to standardize the way that Dash creates validators in their work.

Installation
------------

[](#installation)

`composer require dashifen/validator`

Usage
-----

[](#usage)

You can either extend the `AbstractValidator` object or simply implement the `AbstractInterface` on your own. The interface defines two methods:

1. `canValidate` - returns a Boolean value to tell the calling scope if data can be validated based on a `$field` parameter.
2. `isValid` - returns a Boolean regarding the validity of a `$value` based on its `$field` label.

The `AbstractValidator` implements both of these for you while requiring that you define a third method: a protected `getValidationMethod` method. It returns the name of another method that is assumed to be of the same object that can validate data labeled by `$field`.

Example
-------

[](#example)

In this example, we're assuming that the naming convention for the application's fields is to use kebab-case.

```
class Validator extends AbstractValidator {
    protected function getValidationMethod(string $field): string {

        // to convert a kebab-case $field to a function name, we want to
        // convert it to StudlyCaps.  so, first, we convert from kebab-case to
        // camelCase and then we ucfirst() the camelCase string to make it
        // studly.  finally, we add the word "validate."  Thus, a start-date
        // field becomes startDate, then StartDate, and finally we return
        // transformStartDate.

        $camelCase = preg_replace_callback("/-([a-z])/", function (array $matches): string {
            return strtoupper($matches[1]);
        }, $field);

        return "validate" . ucfirst($camelCase);
    }

    private function validateStartDate(string $date): bool {

        // what we want to do is make sure that our date appears valid.
        // we're less concerned with format (a transform can standardize
        // that).  here, we just want to know that what we have might be
        // a date which is a good job for strtotime()!

        return strtotime($date) !== false;
    }
}
```

The above little class represents a simple, concrete object based on the functionality of the `AbstractValidator` found within this repo. The abstract object's implementation of the `canValidate` and `isValid` methods of our interface make sure that we use the `getValidationMethod` to identify the name of a method that can transform data labeled by `$field` and then will call that method when we need it returning its result.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 87.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~47 days

Total

16

Last Release

1723d ago

Major Versions

1.2.4 → 2.0.02020-06-11

2.3.0 → 3.0.02021-08-26

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8269?v=4)[David Dashifen Kees](/maintainers/dashifen)[@dashifen](https://github.com/dashifen)

---

Top Contributors

[![dashifen](https://avatars.githubusercontent.com/u/8269?v=4)](https://github.com/dashifen "dashifen (21 commits)")[![dashifen-gu](https://avatars.githubusercontent.com/u/50078554?v=4)](https://github.com/dashifen-gu "dashifen-gu (3 commits)")

### Embed Badge

![Health badge](/badges/dashifen-validator/health.svg)

```
[![Health](https://phpackages.com/badges/dashifen-validator/health.svg)](https://phpackages.com/packages/dashifen-validator)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
