ObjectService Class
Service provides basic methods for getting, updating, remove multiple objects on multiple tables.
Item Index
Methods
- __call
- autoDetectItem
- bindObject
- bindObjects
- call
- callByItem
- field
- gateway
- getCaller
- getStack
- hasDefaultField
- installItem
- installItems
- internalAdd
- internalGetAll
- internalGetByIndex
- internalGetTotalAll
- internalGetTotalByIndex
- internalRemoveByIndex
- internalUpdateByIndex
- parse
- privilege
- registerItem
- service
- template
- valueSet
- verify
- verifyField
Methods
__call
-
method
-
args
Override of the dynamic call method to call install* methods, for instance
if we're install an item name Object it would be $this->installObject()
Returns:
The instance of ObjectService for chaining
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 optionalAdditional arguments to call
Returns:
The result of the method call
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
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.
hasDefaultField
-
method
Get the default part of the property name
Parameters:
-
method
StringThe name of the default method (without "ByField")
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
service
-
alias
Get a service by alias
Parameters:
-
alias
StringThe alias
Returns:
The service matching the alias
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
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
profiler
Profiler
The instance of the profiler for debugging performance