Download the PHP package rsmike/label without Composer
On this page you can find all versions of the php package rsmike/label. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package label
Short Description A simple way to organise constant collections and constant=>string dictionaries.
License MIT
Informations about the package label
PHP Labels
A simple way to organise constant collections and constant=>string dictionaries.
Example label class:
Notes:
- make sure to declare '@method static' PHPDoc for autocomplete to work
- classes should be declared abstract to avoid instantiation
Usage:
TestLabels::status(TestLabels::ACTIVE); Returns: 'Active'
TestLabels::abbr(0); Returns: 'I'
TestLabels::status(2); Returns: 2 (pass-through)
TestLabels::status(3); Returns: 'Other'
TestLabels::status(null); Returns: null (pass-through)
TestLabels::status(); Returns: [1=>'Active', 0=>'Inactive'] (complete set of options. Useful for dropdowns etc. )
TestLabels::status([]); Returns: [1=>'Active', 0=>'Inactive'] (same as above)
TestLabels::status([0]); Returns: [1, 0] (all available keys)
TestLabels::status([[0, 3]]); Returns: [0=>'Inactive', 3=>'Other'] (subset)
Default value:
An additional parameter may be passed as a default value instead of pass-through:
TestLabels::status(2, 'N/A'); Returns: 'N/A' (key not found)
TestLabels::status(null, 'N/A'); Returns: 'N/A' (always returns default value on null)
Yes/No:
YN method is a built-in example and may be used in any sub-class
TestLabels::YN(1) Returns: 'Yes'
$YN is protected and may be overridden in a subclass.
Installation
Either run
or add
to the require section of your composer.json file.
Changelog
v1.1
- Subset functionality
v1.0
- YN is now builtin
- label() method removed
- Fallback value functionality
v0.3.4
- changed default shortcuts to
[]and[0]v0.3.4
- array keys shortcut
v0.3
- dev version
TODO
- tests