Class LabelMaker
Label Maker.
Makes so-called label beans.
A label is a bean with only an id, type and name property.
Labels can be used to create simple entities like categories, tags or enums.
This service class provides convenience methods to deal with this kind of
beans.
Namespace: RedBeanPHP
Copyright:
copyright (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community
This source file is subject to the BSD/GPLv2 License that is bundled
with this source code in the file license.txt.
License:
BSD/GPLv2
Author:
Gabor de Mooij and the RedBeanPHP Community
File:
RedBeanPHP/LabelMaker.php
Located at LabelMaker.php
Methods summary
public
|
|
public
array
|
#
dispenseLabels( string $type, array $labels )
A label is a bean with only an id, type and name property.
This function will dispense beans for all entries in the array. The
values of the array will be assigned to the name property of each
individual bean.
A label is a bean with only an id, type and name property.
This function will dispense beans for all entries in the array. The
values of the array will be assigned to the name property of each
individual bean.
$people = R::dispenseLabels( 'person', [ 'Santa', 'Claus' ] );
Parameters
- $type
- type of beans you would like to have
- $labels
- list of labels, names for each bean
Returns
array
|
public
array
|
#
gatherLabels( array $beans )
Gathers labels from beans. This function loops through the beans,
collects the value of the name property for each individual bean
and stores the names in a new array. The array then gets sorted using the
default sort function of PHP (sort).
Gathers labels from beans. This function loops through the beans,
collects the value of the name property for each individual bean
and stores the names in a new array. The array then gets sorted using the
default sort function of PHP (sort).
Usage:
$o1->name = 'hamburger';
$o2->name = 'pizza';
implode( ',', R::gatherLabels( [ $o1, $o2 ] ) );
Note that the return value is an array of strings, not beans.
Parameters
- $beans
- list of beans to loop through
Returns
array
|
public
array|RedBeanPHP\OODBBean
|
#
enum( string $enum )
Fetches an ENUM from the database and creates it if necessary.
An ENUM has the following format:
Fetches an ENUM from the database and creates it if necessary.
An ENUM has the following format:
ENUM:VALUE
If you pass 'ENUM' only, this method will return an array of its
values:
implode( ',', R::gatherLabels( R::enum( 'flavour' ) ) )
If you pass 'ENUM:VALUE' this method will return the specified enum bean
and create it in the database if it does not exist yet:
$bananaFlavour = R::enum( 'flavour:banana' );
$bananaFlavour->name;
So you can use this method to set an ENUM value in a bean:
$shake->flavour = R::enum( 'flavour:banana' );
the property flavour now contains the enum bean, a parent bean.
In the database, flavour_id will point to the flavour record with name 'banana'.
Parameters
- $enum
- ENUM specification for label
Returns
|