PHPackages                             kheaactua/argument-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. kheaactua/argument-validator

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

kheaactua/argument-validator
============================

Simple class to validate and set inputs on functions in PHP. Useful when function takes large number of inputs

011PHP

Since Jul 8Pushed 11y ago1 watchersCompare

[ Source](https://github.com/kheaactua/argument-validator)[ Packagist](https://packagist.org/packages/kheaactua/argument-validator)[ RSS](/packages/kheaactua-argument-validator/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Argument Validator
======================

[](#php-argument-validator)

Simple class to compensate for the lack of keyworded arguments in PHP. This is useful for functions that take many arguments, where many are optional and have default values.

Install
=======

[](#install)

Create a `composer.json`:

```
{
    "require": {
        "kheaactua/argument-validator": "dev-master"
    }
}
```

and run

```
$ wget http://getcomposer.org/composer.phar
$ php composer.phar install
```

After the installation, you need to include the `vendor/autoload.php` to make the class in your script available.

```
require_once('vendor/autoload.php');
```

Example
=======

[](#example)

In this example, we have an Order class with a toArray method that takes in a configuration and serializes an Order object into an array that's then used to serialize it into HTML/Text/LaTeX, etc..

This method has a large number of configuration options. For example, show item action buttons on the HTML output of every item in the order, what headers to show, who is requestion the output, etc.

```
use ArgumentValidator\ArgumentValidator;

class Order extends BaseOrder {

	protected $toArrayConfig;

	public function __construct() {
		$this->toArrayConfig = new ArgumentValidator();
		$this->toArrayConfig->addOpt('auth', 'obj:\Mayofest\Auth', false, \Mayofest\Auth::getInstance());
		$this->toArrayConfig->addOpt('itemActions', 'bool', false, false); // Actions for items, delete, discount, refund
		$this->toArrayConfig->addOpt('adminView', 'bool', false, false); // Top toggle button, FB and Email icon
		$this->toArrayConfig->addOpt('adminOrderActions', 'bool', false, false); // Button buttons, recalc, del, cancel
		$this->toArrayConfig->addOpt('userOrderActions', 'bool', false, false); // User buttons, confirm, cancel
		$this->toArrayConfig->addOpt('activity', 'bool', false, true); // Show order acitivty
		$this->toArrayConfig->addOpt('itemTax', 'bool', false, false); // Show tax on individual items
		$this->toArrayConfig->addOpt('omit_discounts', 'bool', false, false); // Don't show discounts
		$this->toArrayConfig->addOpt('omit_donations', 'bool', false, false); // Don't show donations
		$this->toArrayConfig->addOpt('groupSimilar', 'bool', false, false); // Group by class & options, sum quantity and price
		$this->toArrayConfig->addOpt('labelDonations', 'bool', false, false); // Change "Donation" to "5$ donation"
		$this->toArrayConfig->addOpt('moneyFmt', 'text', false, MONEY_FMT);
		$this->toArrayConfig->addOpt('shortTitle', 'bool', false, false); // Change "Donation" to "5$ donation"
		$this->toArrayConfig->addOpt('statusInTitle', 'bool', false, false); // Put the status in the title
	}

	/**
	* Converts the order object into an array that is used by output serializers (HTML, LaTeX, Text, etc)
	* @param ArgumentValidator $config Config output (see the constructor for an up to date list if inputs)
	*
	* @returns string All the info to be rendered
	*/
	public function __toArray($config = array()) {
		// Let the exception rise
		$config = $this->toArrayConfig->validate($config, $str);

		// Our object (array)
		// Most options removed for example
		$obj = array('headers'=>array(),
			'orderId' => $oid, // Order title
			'userName' => $user->getName(),
			'userNameAndId' => $user->getNameAndId(),
			'userShortName' => sprintf('%s. %s', substr($user->getFirstName(), 0, 1), $user->getLastName()),
			'title' => NULL, // Order title
			'itemTax' => $config->getConf('itemTax'),
			'items' => array(), // button "objects"
			// ...
		);

		if ($config->getConf('adminView')) {
			$obj['user_fb_id'] = $this->getUserRelatedByUserId()->getFbId();
			$obj['user_email'] = $this->getUserRelatedByUserId()->getEmail();
			$obj['user_contact_html'] = $this->getUserRelatedByUserId()->getNameAndContact();
		}

		// Headers
		$obj['headers'] = array('item'=>'Item', 'details' => 'Details', 'quantity' => 'Quantity');
		if ($config->getConf('itemTax'))
			$obj['headers']['itemTax'] = 'Tax';
		if ($config->getConf('itemActions'))
			$obj['headers']['itemActions'] = 'Actions';

		// ...

		return $obj;
	}
}
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/73345fc23c3ca71540a2c07174d562d57b9ea7971a52e4c64128ae99cd93972c?d=identicon)[kheaactua](/maintainers/kheaactua)

---

Top Contributors

[![kheaactua](https://avatars.githubusercontent.com/u/2363406?v=4)](https://github.com/kheaactua "kheaactua (16 commits)")

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/kheaactua-argument-validator/health.svg)](https://phpackages.com/packages/kheaactua-argument-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)
