PHPackages                             gamernetwork/yolk-support - 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. [Framework](/categories/framework)
4. /
5. gamernetwork/yolk-support

AbandonedArchivedLibrary[Framework](/categories/framework)

gamernetwork/yolk-support
=========================

Gamer Network's PHP framework core

v1.0(10y ago)07.0k21MITPHPPHP &gt;=5.4.0

Since Jul 24Pushed 10y ago9 watchersCompare

[ Source](https://github.com/gamernetwork/yolk-support)[ Packagist](https://packagist.org/packages/gamernetwork/yolk-support)[ RSS](/packages/gamernetwork-yolk-support/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (1)

Want to work for Gamer Network? [We are hiring!](http://www.gamesindustry.biz/jobs/gamer-network)

Yolk Support
============

[](#yolk-support)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/e3e2810a06f944f9ab815e0d2d3e07f7753e60133d027031b424aa9f15c95425/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f67616d65726e6574776f726b2f796f6c6b2d737570706f72742f6261646765732f7175616c6974792d73636f72652e706e673f623d646576656c6f70)](https://scrutinizer-ci.com/g/gamernetwork/yolk-support/?branch=develop)

Provides various supporting elements to the Yolk framework, such as:

- Collections
- Configuration
- Fieldsets and Fields
- Twig Extension
- Validation

Requirements
------------

[](#requirements)

This library requires only PHP 5.4 or later and the Yolk Contracts package (`gamernetwork/yolk-contracts`).

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

[](#installation)

It is installable and autoloadable via Composer as `gamernetwork/yolk-support`.

Alternatively, download a release or clone this repository, and add the `\yolk\support` namespace to an autoloader.

License
-------

[](#license)

Yolk Support is open-sourced software licensed under the MIT license.

Collections
-----------

[](#collections)

This package provides basic implementation of the `Collection`, `Dictionary` and `Set` interfaces defined in the `yolk-contracts` package.

`BaseCollection` accepts an array of items in its constructor and provides basic collection operations such as iteration, counting, emptying and testing for existence. There is no support for adding or removing individual items, this being provided by specific subclasses.

`BaseDictionary` extends `BaseCollection` to add support for adding and removing key/value pairs - each key being unique.

`BaseSet` extends `BaseCollection` to add support for adding and removing unique items.

```
use yolk\support\collections\BaseCollection;
use yolk\support\collections\BaseDictionary;
use yolk\support\collections\BaseSet;

$c = new Collection([123, 456, 789]);

$c->count();		// returns 3
$c->contains(456);	// returns true
$c->contains(234);	// returns false
$c->isEmpty();		// returns false
$c->clear();		// remove all items
$c->isEmpty();		// returns true

$d = new BaseDictionary();

$d->add('foo', 123);
$d->add('bar', 456);
$d->has('foo');	// returns true
$d->has('baz');	// returns false
$d->get('foo');	// returns 123
$d->keys();		// returns ['foo', 'bar']
$d->remove('bar');

$d = new BaseSet();

$d->add('foo');
$d->add('bar');
$d->contains('foo');	// returns true
$d->remove('bar');
$d->contains('bar');	// returns false
```

Configuration
-------------

[](#configuration)

`BaseConfig` provides a basic configuration object, the underlying implementation being an array. The array can be populated from an external file via `load()`, or from an existing array via `merge()`. Methods are also provided to allow easy access to nested elements.

```
use yolk\support\BaseConfig;

$c = new BaseConfig([
	'foo' => [
		'bar' => 123,
		'baz' => 456,
	],
]);

$c->get('foo.bar');	// returns 123

$c->set('foo.baz', 789);	// changes the value of ['foo']['bar']

// overwrite the 'foo' branch and add an additional value for 'bar'
$c->merge([
	'foo' => 'abc',
	'bar' => 'def',
]);

$c->get('foo.bar');	// returns null (key doesn't exist)

$c->get('bar');	// returns 'def'

$c->load(__DIR__. 'config.php');	// 'config.php' should create an array called $config
```

Fieldsets and Fields
--------------------

[](#fieldsets-and-fields)

A field represents an object property, database column or similar construct.

Fieldsets are collections of Fields and can be used as database table/model definitions, html form definitions, etc.

### Fields

[](#fields)

A Field must have a name and a type and may optionally have additional rules defining rules for values that are considered valid.

Supported field types are listed in `yolk\contracts\support\Type`.

```
use yolk\support\Field;

$f = new Field('id', Type::INTEGER);
$f = new Field('email', Type::EMAIL, ['required' => true, 'unique' => true]);
$f = new Field(
	'status',
	Type::ENUM,
	[
		'required' => true,
		'values' => ['EMPLOYEE', 'PARTNER', 'OTHER']
	]
);
```

Available Rules:

- `required` - \[`boolean`\] if true, must have a non-empty value (default: false)
- `nullable` - \[`boolean`\] determines if null is an acceptable value (default: false)
- `default` - \[`mixed`\] default value to use if none specified (default: empty based on type)
- `label` - \[`string`\] user-friendly label, (default: title-cased name)
- `unique` - \[`boolean`\] determines if values should be unique (default: false)
- `min` - \[`integer|string`\] minimum acceptable value
- `max` - \[`integer|string`\] maximum acceptable value
- `min-length` - \[`integer`\] minimum length of value
- `max-length` - \[`integer`\] maximum length of value
- `regex` - \[`string`\] a regular expression that acceptable values must match
- `values` - \[`array`\] an array containing all acceptable values

Specified rules are available as properties on a Field object; e.g. `$f->required`. Fields are immutable once instantiated.

There are two methods provided for validation:

- `cast()` - cast a specified value to the Field's type
- `validate()` - validate a specified value against the Field's rules and return a 'cleaned' value and any validation error encountered. Supported errors are defined in `yolk\contracts\support\Error`.

```
use yolk\contracts\support\Error;
use yolk\support\Field;

$f = new Field('id', Type::INTEGER, ['required' => true, 'min' => 0]);

$f->cast(false);		// returns 0
$f->cast('123fgh');		// returns 123
$f->cast('fghsdfs');	// returns 0

$f->validate(0);			// returns [0, Error::REQUIRED]
$f->validate(false);		// returns [false, Error::REQUIRED]
$f->validate('123fgh');		// returns [123, Error::NONE]
$f->validate('fghsdfs');	// returns ['fghsdfs', Error::TYPE]
$f->validate(-123);			// returns [-123, Error::MIN]
```

### Fieldsets

[](#fieldsets)

Fields are added via the `add()` method:

```
use yolk\support\Fieldset;

$f = new Fieldset();
$f->add($name, $type = Type::TEXT, $rules = []);
```

All Fields in the Fieldset can be validated at once by calling the `validate()` method and passing an array of field names and values. The return value is an array containing two elements, the first is an array of 'cleaned' values, indexed by Field name; the second is an array of validation errors, indexed by Field name.

```
use yolk\contracts\support\Error;
use yolk\support\Fieldset;

$f = new Fieldset();

$f->add('id', Type::INTEGER);
$f->add('email', Type::EMAIL, ['required' => true, 'unique' => true]);

$f->validate([
	'id'    => '123',
	'email' => 'bar',
]);
/*
returns:
[
	[
		'id'    => 123,
		'email' => 'bar',
],
	[
		'id'    => Error::NONE,
		'email' => Error::EMAIL,
	],
]
```

Twig Extension
--------------

[](#twig-extension)

The Twig extension provides additional utility functionality to Twig environments.

### Tests (is):

[](#tests-is)

- `numeric` - determines if a variable contains a numeric value
- `integer` - determines if a variable contains an integer value
- `string` - determines if a variable is a string
- `array` - determines if a variable is an array
- `object` - determines if a variable is an object

### Filters

[](#filters)

- `md5` - generate the md5 hash of a value
- `sha1` - generate the sha1 hash of a value
- `truncate` - truncate a value to a specified length
- `sum` - generate the sum of an array, via `array_sum()`
- `shuffle` - shuffle an array, via `shuffle()`

### Functions

[](#functions)

- `ceil` - round a value up to next highest integer, via `ceil()`
- `floor` - round a value down to next lowest integer, via `floor()`

If the `yolk-core` package is detected, most Helper methods are included as filters or functions where there is no corresponding native functionality.

Validation
----------

[](#validation)

The `yolk\support\Validator` class contains static methods for validating values. Where possible validation is performed using PHP's built-in `filter_var()` function with appropriate flags. Validation function will return a valid value of the correct type, or an empty value of the correct type.

- `isEmpty($v, $type = Type::TEXT)`
- `validateText($v)`
- `validateInteger($V)`
- `validateFloat($v)`
- `validateBoolean($v)`
- `validateTimestamp($v)`
- `validateDateTime($v, $format = 'Y-m-d H:i:s')`
- `validateDate($v)`
- `validateTime($v)`
- `validateYear($v, $min = 1900, $max = 2155)`
- `validateEmail($v)`
- `validateIP($v)`
- `validateURL($v)`
- `validateJSON($v)`
- `validateObject($v, $class, $nullable = false)`

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity59

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

3951d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2658e540902cbc1f59ec171e1b74515fb9e7c3a1e194e37e9c37f27ae400e4b4?d=identicon)[gamer-network](/maintainers/gamer-network)

---

Top Contributors

[![simon-downes](https://avatars.githubusercontent.com/u/1052903?v=4)](https://github.com/simon-downes "simon-downes (5 commits)")

---

Tags

frameworkeurogamergamer network

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gamernetwork-yolk-support/health.svg)

```
[![Health](https://phpackages.com/badges/gamernetwork-yolk-support/health.svg)](https://phpackages.com/packages/gamernetwork-yolk-support)
```

###  Alternatives

[hemp/presenter

Easy Model Presenters in Laravel

247592.6k1](/packages/hemp-presenter)[pestphp/pest-plugin-stressless

Stressless plugin for Pest

67792.6k16](/packages/pestphp-pest-plugin-stressless)[wpstarter/framework

The WpStarter Framework - Laravel Framework for WordPress

1810.1k4](/packages/wpstarter-framework)

PHPackages © 2026

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