PHPackages                             mwayi/expression - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mwayi/expression

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mwayi/expression
================

A multi-purpose php condition parser.

0.1.0(9y ago)01.4kMITPHPPHP &gt;=5.3

Since Nov 8Pushed 9y ago1 watchersCompare

[ Source](https://github.com/mwayi/Expression)[ Packagist](https://packagist.org/packages/mwayi/expression)[ RSS](/packages/mwayi-expression/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Expression
==========

[](#expression)

[![status](https://camo.githubusercontent.com/0e410e2240a98793672bbd4e26574a08419e96a20cd6b65e81203501973b182f/68747470733a2f2f636f6465736869702e636f6d2f70726f6a656374732f66626361633265302d383666302d303133342d326538652d3336633263636637396131362f7374617475733f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/0e410e2240a98793672bbd4e26574a08419e96a20cd6b65e81203501973b182f/68747470733a2f2f636f6465736869702e636f6d2f70726f6a656374732f66626361633265302d383666302d303133342d326538652d3336633263636637396131362f7374617475733f6272616e63683d6d6173746572)

A multi-purpose expression parser.

The expression parser allows developers to pass in a plain text statement that can be resolved to one of the following:-

- An iterable conditions object
- A boolean (true or false) statement
- A MySql PDO object

Here is a sample use case:

```
$expression = new \Smrtr\Expression('a = b');
$conditions = $expression->execute()->toArray();
print_r($conditions);

```

Would resolve to:

```
Array
(
	[0] => Smrtr\Expression\Condition Object
		(
			[attributes:protected] => Array
				(
					[key] => a
					[value] => b
					[original_value] => b
					[operator] => =
				)

		)

)

```

You can now iterate the object recurrsively using a callback

```
$result = $expression->solve(function($condition) {

	return $this->myCustomAssertionEngine(
		$condition->key,
		$condition->operator,
		$condition->value
	);

});

```

Where `$this->myCustomAssertionEngine` would be built to recognise keys and operators. The handlers would contain logic that would be able to return falsey and truthy results based upon the value supplied.

```
protected function myCustomAssertionEngine($key, $operator, $value)
{
	$handler = 'handle' . ucfirst($key) . 'Key';

	if(method_exists($handler, $this)) {
		return $this->{$handler}($operator, $value);
	}

	return false;
}

```

The result would be a boolean value.

```
var_dump($result); // bool(true) or bool(false)

```

Definitions
===========

[](#definitions)

### Condition Elements

[](#condition-elements)

A condition consists of a key and value that are connected by an operator such as `=` that return true or false.

```
[key] [operator] [value]
  a        =        b

```

### Compound conditions

[](#compound-conditions)

A compound condition combines two or more conditions that are connected by logical operators (for example, AND) that return true or false.

```
a = b AND c = d

```

### Nested conditions

[](#nested-conditions)

A nested condition uses parentheses to group conditions that are contained in another condition and are connected using AND and OR.

```
a = b AND (c = d OR e = f)

```

### Logical operators

[](#logical-operators)

Logical operators combines two conditions together to return a set of results

```
AND
OR

```

Todo
====

[](#todo)

- Allow condition elements `value` and `key` to be extended.
- Pass responsiblity of creating an expression object to an expression interface.

Tests
=====

[](#tests)

```
php vendor/bin/phpunit

```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

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

3568d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/50300a254a75cdf9fed420761e2bcf90fdd415dc978a20654e1c9f189ce1a737?d=identicon)[mwayi](/maintainers/mwayi)

---

Top Contributors

[![mwayi](https://avatars.githubusercontent.com/u/1902732?v=4)](https://github.com/mwayi "mwayi (15 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mwayi-expression/health.svg)

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

###  Alternatives

[typisttech/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins.

111303.6k1](/packages/typisttech-imposter)

PHPackages © 2026

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