Download the PHP package gamernetwork/yolk-support without Composer
On this page you can find all versions of the php package gamernetwork/yolk-support. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gamernetwork/yolk-support
More information about gamernetwork/yolk-support
Files in gamernetwork/yolk-support
Package yolk-support
Short Description Gamer Network's PHP framework core
License MIT
Informations about the package yolk-support
Want to work for Gamer Network? We are hiring!
Yolk Support
Provides various supporting elements to the Yolk framework, such as:
- Collections
- Configuration
- Fieldsets and Fields
- Twig Extension
- Validation
Requirements
This library requires only PHP 5.4 or later and the Yolk Contracts package (gamernetwork/yolk-contracts
).
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
Yolk Support is open-sourced software licensed under the MIT license.
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.
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.
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
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
.
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 valuemax
- [integer|string
] maximum acceptable valuemin-length
- [integer
] minimum length of valuemax-length
- [integer
] maximum length of valueregex
- [string
] a regular expression that acceptable values must matchvalues
- [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 typevalidate()
- validate a specified value against the Field's rules and return a 'cleaned' value and any validation error encountered. Supported errors are defined inyolk\contracts\support\Error
.
Fieldsets
Fields are added via the add()
method:
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.
Twig Extension
The Twig extension provides additional utility functionality to Twig environments.
Tests (is):
numeric
- determines if a variable contains a numeric valueinteger
- determines if a variable contains an integer valuestring
- determines if a variable is a stringarray
- determines if a variable is an arrayobject
- determines if a variable is an object
Filters
md5
- generate the md5 hash of a valuesha1
- generate the sha1 hash of a valuetruncate
- truncate a value to a specified lengthsum
- generate the sum of an array, viaarray_sum()
shuffle
- shuffle an array, viashuffle()
Functions
ceil
- round a value up to next highest integer, viaceil()
floor
- round a value down to next lowest integer, viafloor()
If the yolk-core
package is detected, most Helper methods are included as
filters or functions where there is no corresponding native functionality.
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)