PHPackages                             baghayi/strategy-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. baghayi/strategy-validator

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

baghayi/strategy-validator
==========================

A zf2 validator implementing Strategy design pattern which is mainly created to be used in Apigility.

v0.1.0(11y ago)034MITPHPPHP &gt;=5.3.23

Since Dec 22Pushed 11y ago1 watchersCompare

[ Source](https://github.com/baghayi/StrategyValidator)[ Packagist](https://packagist.org/packages/baghayi/strategy-validator)[ Docs](http://github.com/baghayi/StrategyValidator)[ RSS](/packages/baghayi-strategy-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Strategy Validator
==================

[](#strategy-validator)

Introduction
------------

[](#introduction)

This is a zf2 module which is mainly created to be used by Apigility. In fact, apigility ships with a number of validators by default and one of them is Zend\\Validator\\Callable. StrategyValidator module is very similar to Callable validator in some ways but does things slightly differently.

In Callable, you will have to create an object in advance, which you may never use it. You may even have difficulty passing your domain logic's dependencies to it as well since it is not a Class and even if it is you would have to create an instance of it beforehand.

What I had in mind when creating this module was to solve these issues. Which was bugging me :)

By using this Validator you will only need to create your own class, resolve its dependencies in a very clean and less vague way then pass it to the StrategyValidator validator and you're good to go.

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

[](#installation)

First you need to download this module to either manually, using git or by composer. It is recommended to use composer, but the choice is yours.

If your are using composer, it will download the module to vendor/ directory by default. If you are downloading manually, or cloning it using git, then you need to place it under vendor/ directory as composer does.

Then you need to add 'StrategyValidator' to your config/application.config.php file under 'modules' key.

- For installing using composer you need to run this command in your project's root directory:

    > `composer require "baghayi/strategy-validator:dev-master"`
- If you want to directly clone it using git then you need to run this command under vendor/ (or wherever your modules will be loaded from) directory:

    > `git clone https://github.com/baghayi/StrategyValidator`
- You can also download module in a zip file by clicking on 'Download ZIP' button or use this URL, then place it under vendor/ directory:

    > `https://github.com/baghayi/StrategyValidator/archive/master.zip`

Now you are ready to go.

Usage
-----

[](#usage)

This validator has already been defined to be used in Apigility and doesn't require you to do anything other than downloading this module and enablding it.

In order to use it, first you will need to create a class which is implementing the following interface:

> StrategyValidator/Strategy/StrategyInterface.php

This interface has only one method that needs to be implemented:

> isValid($value)

It will get value that needs to be validated as its first argument. After been checked of whether or not it is valid you will need to return a `Boolean` value.

Then you need to register your class as a service in the `main service manager`.

It could be a `factory`, `invokable` or whatever else you want it to be. It only needs to be registered in the main service manager and not in the validator plugin manager or any other managers.

At last you need to pass the service name to the StrategyValidator validator as `strategy`.

StrategyValidator validstor `(StrategyValidator\Validator\Strategy)` has 2 main options. First one like others is `message` for specifiying a message to be shown whenever validation fails. The second one is `strategy` which is for specifying your strategy class. (The class you've aleady created in first step)

After registeting your class in the service manager, you need to pass it as `strategy` option to the StrategyValidator validator alongside with the `message` option.

Adding Strategy and message options in Apigility admin dashboard is pretty straightforward. As it is listed in the select box (in validations section of cource) and could be selected and specified that way.

In a nutshell:
--------------

[](#in-a-nutshell)

- Create a class.
- Implement StrategyValidator/Strategy/StrategyInterface.php interface.
- Register as a service in the main service manager.
- Pass service name as 'strategy' option to validator.
- Set 'message' option alongside 'strategy'.

That's pretty much it. Hope it could have any use.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

4155d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1186187977426c403860f7f27e73e5e5d35a6d6f622a8e925a405e5601766ebb?d=identicon)[baghayi](/maintainers/baghayi)

---

Top Contributors

[![baghayi](https://avatars.githubusercontent.com/u/937667?v=4)](https://github.com/baghayi "baghayi (24 commits)")

---

Tags

validatorzf2apigilityastrategy design pattern

### Embed Badge

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

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

###  Alternatives

[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M379](/packages/respect-validation)[seld/jsonlint

JSON Linter

1.3k217.8M206](/packages/seld-jsonlint)[composer/spdx-licenses

SPDX licenses list and validation library.

1.4k184.2M25](/packages/composer-spdx-licenses)[opis/json-schema

Json Schema Validator for PHP

64236.9M184](/packages/opis-json-schema)[laminas/laminas-validator

Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria

15544.9M188](/packages/laminas-laminas-validator)[ergebnis/json-schema-validator

Provides a JSON schema validator, building on top of justinrainbow/json-schema.

3626.9M7](/packages/ergebnis-json-schema-validator)

PHPackages © 2026

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