ConfigService Class
Interacts with the config data table from the database. Located in the namespace Canteen\Services.
Item Index
Methods
- __call
- addConfig
- autoDetectItem
- bindObject
- bindObjects
- call
- callByItem
- field
- gateway
- getCaller
- getConfig
- getConfigs
- getStack
- getValidationByType
- getValueByName
- getValueTypes
- hasDefaultField
- install
- installItem
- installItems
- internalAdd
- internalGetAll
- internalGetByIndex
- internalGetTotalAll
- internalGetTotalByIndex
- internalRemoveByIndex
- internalUpdateByIndex
- parse
- privilege
- registerItem
- registerSettings
- removeConfig
- service
- setPrepends
- setProperties
- setup
- setWhere
- template
- updateConfig
- valueSet
- verify
- verifyField
Methods
__call
-
method
-
args
Override of the dynamic call method to call verify* methods, for instance if we're validating Name it would be $this->verifyName($value)
addConfig
-
propertiesOrName
-
[value='']
-
[type='string']
-
[access=0]
Add a key to the config
Parameters:
Returns:
The new ID if successful, false if not
autoDetectItem
-
method
Auto detect the item name based on the name of the method that called it
Parameters:
-
method
StringThe name of the method
Returns:
Returns the item or throw error
bindObject
-
data
-
dataClass
-
[prepends=null]
-
[useFirstRow=true]
Bind an associate array to a data object
Parameters:
-
data
ArrayThe data to bind
-
dataClass
StringThe name of the data class (string to bind)
-
[prepends=null]
Array optionalThe array of maps to prepend to the variables used for prepending a path or directory to a file/path/url
-
[useFirstRow=true]
Boolean optionalIf to just return the row in a return, only getting one item from a mysql array call
Returns:
The typed data object
bindObjects
-
data
-
dataClass
-
[prepends=null]
Same as bindObject but done on a whole collection
Parameters:
Returns:
The data object
call
-
[args*]
This allows for the internal dynamic calling of methods, the methods supported include getItems, getItem, updateItem, removeItem, getTotalItems, getTotalItem, getItemBy[IndexName], getTotalItemBy[IndexName], removeItemBy[IndexName], updateItemBy[IndexName].
Parameters:
-
[args*]
Mixed optionalThe collection of arguments
callByItem
-
item
-
method
-
args
Generally called for calling the item methods
Parameters:
-
item
ObjectServiceItemThe item to call for
-
method
StringThe method name to call
-
args
ArrayThe collection of additional arguments
Returns:
The result of the method call
field
-
id
-
[type=null]
-
[name=null]
Convenience function for creating a new field
Parameters:
Returns:
The new custom field object
gateway
-
uri
-
method
-
[privilege=Privilege::ANONYMOUS]
Add for use on the Gateway, these methods can be
called from javascript. For an example see the
TimeService
class.
Parameters:
Returns:
Return the instance of this for chaining
getCaller
-
[ignore=1]
Get the method/function name of the caller function
Parameters:
-
[ignore=1]
Int optionalThe depth of the call, default is the immediate function before this one is called
getConfig
-
id
Get a config variable by id
Parameters:
-
id
IntThe ID of the config Option
Returns:
The config object
getConfigs
()
Array
Get all the the config for the site
Returns:
The collection of Config objects
getStack
-
[limit=0]
-
[ignore=1]
Get the method/function name of the caller function
Parameters:
-
[limit=0]
Int optionalThe number of stack items to return, default is all
-
[ignore=1]
Int optionalThe number of stack levesl to ignore, default is the immediate function before this one is called.
getValidationByType
-
type
Get the validator by the current type
Parameters:
-
type
StringThe type of config (path, page, boolean, integer, string)
Returns:
The regular expression for validating
getValueByName
-
name
Get a config variable by name
Parameters:
-
name
StringThe name of the config property
Returns:
The value of the config property
getValueTypes
()
Array
Get the collection of values types
Returns:
A collection of value type strings
hasDefaultField
-
method
Get the default part of the property name
Parameters:
-
method
StringThe name of the default method (without "ByField")
install
()
Boolean
protected
Use the install method that comes built-in, this is experimental and may not set the best default data type on the table. It's encouraged that manual adjustments are made afterwards.
Returns:
If the install was successful
installItem
-
item
Auto install the service item
Parameters:
-
item
ObjectServiceItemRegistered item
Returns:
If item was installed successfully
installItems
-
items
Auto install multiple service items
Parameters:
-
items
Array | ObjectServiceItemRegistered items as different arguments or as a collection of ObjectServiceItems
Returns:
If item was installed successfully
internalAdd
-
item
-
properties
Conviencence method to inserting a new row into a table, this does all the field validation and insert.
Parameters:
-
item
ObjectServiceItemThe item to use
-
properties
Dictionary | ObjectThe collection map of field names to values
Returns:
The result
internalGetAll
-
item
-
[lengthOrIndex=null]
-
[duration=null]
Internal getting a collection of items
Parameters:
-
item
ObjectServiceItemThe item definition
-
[lengthOrIndex=null]
Int optionalThe starting index or elements to return
-
[duration=null]
Int optionalThe duration of the items
Returns:
The collection of objects
internalGetByIndex
-
item
-
index
-
isSingle
-
search
-
[lengthOrIndex=null]
-
[duration=null]
Internal method for getting result by an index
Parameters:
-
item
ObjectServiceItemThe item definition
-
index
ObjectServiceFieldThe index field to search on
-
isSingle
BooleanIf the index search is a single
-
search
Array | MixedThe value to search on
-
[lengthOrIndex=null]
Int optionalThe starting index or elements to return
-
[duration=null]
Int optionalThe duration of the items
internalGetTotalAll
-
item
Internal getting a total number of items
Parameters:
-
item
ObjectServiceItemThe item definition
Returns:
The number of items in selection
internalGetTotalByIndex
-
item
-
index
-
isSingle
-
search
Internal method for getting result by an index
Parameters:
-
item
ObjectServiceItemThe item definition
-
index
ObjectServiceFieldThe index field to search on
-
isSingle
BooleanIf the index search is a single
-
search
Array | MixedThe value to search on
internalRemoveByIndex
-
item
-
index
-
search
The internal remove of items by index
Parameters:
-
item
ObjectServiceItemThe item definition
-
index
ObjectServiceFieldThe index field to search on
-
search
Array | MixedThe value to search on
Returns:
If the remove was successful
internalUpdateByIndex
-
item
-
index
-
search
-
prop
-
[value=null]
The internal remove of items by index
Parameters:
-
item
ObjectServiceItemThe item definition
-
index
ObjectServiceFieldThe index field to search on
-
search
MixedThe value to search on
-
prop
Dictionary | StringThe property name or map of properties to update
-
[value=null]
Mixed optionalIf updating a single property, the property name
Returns:
If the remove was successful
parse
-
content
-
substitutions
Convenience method for parsing content
Parameters:
-
content
StringThe string to parse
-
substitutions
DictionaryThe dictionary of tags to replace
Returns:
The parsed string
privilege
-
[required=Privilege::GUEST]
You can run to make sure a process requires a particular privilege
Parameters:
-
[required=Privilege::GUEST]
Int optionalThe privilege level required, default is anonymous
registerItem
-
className
-
table
-
field
-
itemName
-
itemsName
Add a new Item definition to the service. This is required before using any of the methods for updating, getting, removing. Located in the namespace Canteen\Services.
Parameters:
Returns:
The new service definition created
registerSettings
()
Dictionary
Get all the the config for the site and add them to the settings
Returns:
The collection of all config items
removeConfig
-
id
Delete a config key
Parameters:
-
id
Id | ArrayThe config ID or collection of IDs to delete
Returns:
If delete was successful
service
-
alias
Get a service by alias
Parameters:
-
alias
StringThe alias
Returns:
The service matching the alias
setPrepends
-
maps
-
[value=null]
Set the collection or single prepend the field value
Parameters:
Returns:
The instance of this class, for chaining
setProperties
-
[props=null]
Set additional selection properties not part of the field set
Parameters:
Returns:
The instance of this class, for chaining
setup
-
siteTitle
-
contentPath
-
templatePath
Install the config table
Parameters:
Returns:
If the table was installed
setWhere
-
args
Register additional where clauses for the SQL select on get methods
Parameters:
Returns:
The instance of this class, for chaining
template
-
name
-
[substitutions=[]
Convenience method for parsing content
Parameters:
-
name
StringThe name of the template to parse
-
[substitutions=[]
Dictionary optionalThe dictionary of tags to replace
Returns:
The parsed string
updateConfig
-
id
-
prop
-
[value=null]
Update a config's property or properties
Parameters:
-
id
IntThe config id
-
prop
String | DictionaryThe property name or an array of property => value
-
[value=null]
Mixed optionalThe value to update to if we're updating a single item
Returns:
If successfully updated
valueSet
-
A
-
[validationType=null]
Get a set of ids
Parameters:
Returns:
The MySQL formatted set of IDs
verify
-
data
-
[type=null]
-
[suppressErrors=false]
Sanitize input data using the validation types above
Parameters:
Returns:
If we don't verify and suppress errors, returns false, else returns the data
verifyField
-
item
-
name
-
[value=null]
The more manual method for verifying a field value.
Parameters:
-
item
ObjectServiceItemRegistered item
-
name
Dictionary | StringThe name of the field or a map of name=>values
-
[value=null]
Mixed optionalThe value to check against
Returns:
The instance of this object for chaining
Properties
db
Database
Convenience getter for the database connection
items
Dictionary
The dictionary of item names to ObjectServiceItem objects
parser
Parser
The parser is responsible for rendering templates
prepends
Dictionary
The list of prepend map
profiler
Profiler
The instance of the profiler for debugging performance