API Documentation for: 1.1.1
Show:

SimpleObjectService Class

Extends ObjectService
Namespace: Canteen\Services

This is like the ObjectService but provides some convience methods if only dealing with one object type. This include custom verify* methods for checking different field types (e.g. $this->verifyName($name)). Located in the namespace Canteen\Services.

Constructor

SimpleObjectService

(
  • className
  • table
  • field
  • [itemName]
  • [itemsName]
)

Parameters:

  • className String

    Class to bind database result to

  • table String

    The table that the objects are on

  • field Array

    The collection of ObjectServiceField objects

  • [itemName] String optional

    The optional item name to specify, defaults to unqalified class name (without the full namespace)

  • [itemsName] String optional

    The optional items name (plural) of itemName

Methods

__call

(
  • method
  • args
)

Inherited from ObjectService

Override of the dynamic call method to call verify* methods, for instance if we're validating Name it would be $this->verifyName($value)

Parameters:

  • method String

    The name of the method to call

  • args Array

    The collection of arguments

autoDetectItem

(
  • method
)
ObjectServiceItem private

Inherited from ObjectService:

Auto detect the item name based on the name of the method that called it

Parameters:

  • method String

    The name of the method

Returns:

ObjectServiceItem:

Returns the item or throw error

bindObject

(
  • data
  • dataClass
  • [prepends=null]
  • [useFirstRow=true]
)
Mixed protected

Inherited from Service:

Bind an associate array to a data object

Parameters:

  • data Array

    The data to bind

  • dataClass String

    The name of the data class (string to bind)

  • [prepends=null] Array optional

    The array of maps to prepend to the variables used for prepending a path or directory to a file/path/url

  • [useFirstRow=true] Boolean optional

    If to just return the row in a return, only getting one item from a mysql array call

Returns:

Mixed:

The typed data object

bindObjects

(
  • data
  • dataClass
  • [prepends=null]
)
Array protected

Inherited from Service:

Same as bindObject but done on a whole collection

Parameters:

  • data Array

    The data to bind

  • dataClass String

    The name of the data class (string to bind)

  • [prepends=null] Array optional

    The array of maps to prepend to the variables used for prepending a path or directory to a file/path/url

Returns:

Array:

The data object

call

(
  • [args*]
)
protected

Inherited from ObjectService

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 optional

    The collection of arguments

callByItem

(
  • item
  • method
  • args
)
Mixed protected

Inherited from ObjectService:

Generally called for calling the item methods

Parameters:

Returns:

Mixed:

The result of the method call

field

(
  • id
  • [type=null]
  • [name=null]
)
ObjectServiceField protected

Inherited from ObjectService:

Convenience function for creating a new field

Parameters:

  • id String

    The name of the field on the database

  • [type=null] RegExp | Array optional

    The validation type or set of values, default is no validation

  • [name=null] String optional

    The name of the php property

Returns:

ObjectServiceField:

The new custom field object

gateway

(
  • uri
  • method
  • [privilege=Privilege::ANONYMOUS]
)
Service

Inherited from Service:

Add for use on the Gateway, these methods can be called from javascript. For an example see the TimeService class.

Parameters:

  • uri String

    The URI path to call from the gateway

  • method String

    The name of the method

  • [privilege=Privilege::ANONYMOUS] Int optional

    The minimum privilege needed for the client to access this method.

Returns:

Service:

Return the instance of this for chaining

getCaller

(
  • [ignore=1]
)
String | Array protected

Inherited from Service:

Get the method/function name of the caller function

Parameters:

  • [ignore=1] Int optional

    The depth of the call, default is the immediate function before this one is called

Returns:

String | Array:

The name of the method

getStack

(
  • [limit=0]
  • [ignore=1]
)
String | Array protected

Inherited from Service:

Get the method/function name of the caller function

Parameters:

  • [limit=0] Int optional

    The number of stack items to return, default is all

  • [ignore=1] Int optional

    The number of stack levesl to ignore, default is the immediate function before this one is called.

Returns:

String | Array:

The name of the method or full trace

hasDefaultField

(
  • method
)
private

Inherited from ObjectService:

Get the default part of the property name

Parameters:

  • method String

    The 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:

Boolean:

If the install was successful

installItem

(
  • item
)
Boolean protected

Inherited from ObjectService:

Auto install the service item

Parameters:

Returns:

Boolean:

If item was installed successfully

installItems

(
  • items
)
Boolean protected

Inherited from ObjectService:

Auto install multiple service items

Parameters:

  • items Array | ObjectServiceItem

    Registered items as different arguments or as a collection of ObjectServiceItems

Returns:

Boolean:

If item was installed successfully

internalAdd

(
  • item
  • properties
)
Int protected

Inherited from ObjectService:

Conviencence method to inserting a new row into a table, this does all the field validation and insert.

Parameters:

  • item ObjectServiceItem

    The item to use

  • properties Dictionary | Object

    The collection map of field names to values

Returns:

Int:

The result

internalGetAll

(
  • item
  • [lengthOrIndex=null]
  • [duration=null]
)
Array private

Inherited from ObjectService:

Internal getting a collection of items

Parameters:

  • item ObjectServiceItem

    The item definition

  • [lengthOrIndex=null] Int optional

    The starting index or elements to return

  • [duration=null] Int optional

    The duration of the items

Returns:

Array:

The collection of objects

internalGetByIndex

(
  • item
  • index
  • isSingle
  • search
  • [lengthOrIndex=null]
  • [duration=null]
)
Array | Object private

Inherited from ObjectService:

Internal method for getting result by an index

Parameters:

  • item ObjectServiceItem

    The item definition

  • index ObjectServiceField

    The index field to search on

  • isSingle Boolean

    If the index search is a single

  • search Array | Mixed

    The value to search on

  • [lengthOrIndex=null] Int optional

    The starting index or elements to return

  • [duration=null] Int optional

    The duration of the items

Returns:

Array | Object:

The collection of objects or a single object matching the className from the constuction

internalGetTotalAll

(
  • item
)
Int private

Inherited from ObjectService:

Internal getting a total number of items

Parameters:

Returns:

Int:

The number of items in selection

internalGetTotalByIndex

(
  • item
  • index
  • isSingle
  • search
)
Array | Object private

Inherited from ObjectService:

Internal method for getting result by an index

Parameters:

Returns:

Array | Object:

The collection of objects or a single object matching the className from the constuction

internalRemoveByIndex

(
  • item
  • index
  • search
)
Boolean private

Inherited from ObjectService:

The internal remove of items by index

Parameters:

Returns:

Boolean:

If the remove was successful

internalUpdateByIndex

(
  • item
  • index
  • search
  • prop
  • [value=null]
)
Boolean private

Inherited from ObjectService:

The internal remove of items by index

Parameters:

  • item ObjectServiceItem

    The item definition

  • index ObjectServiceField

    The index field to search on

  • search Mixed

    The value to search on

  • prop Dictionary | String

    The property name or map of properties to update

  • [value=null] Mixed optional

    If updating a single property, the property name

Returns:

Boolean:

If the remove was successful

parse

(
  • content
  • substitutions
)
String protected

Inherited from CanteenBase

Convenience method for parsing content

Parameters:

  • content String

    The string to parse

  • substitutions Dictionary

    The dictionary of tags to replace

Returns:

String:

The parsed string

privilege

(
  • [required=Privilege::GUEST]
)
protected

Inherited from Service:

You can run to make sure a process requires a particular privilege

Parameters:

  • [required=Privilege::GUEST] Int optional

    The privilege level required, default is anonymous

registerItem

(
  • className
  • table
  • field
  • itemName
  • itemsName
)
ObjectServiceItem protected

Inherited from ObjectService:

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:

  • className String

    Class to bind database result to

  • table String

    The name of the database table

  • field Array

    The collection of ObjectServiceField objects

  • itemName String

    The name of the item

  • itemsName String

    The name of the plural items

Returns:

ObjectServiceItem:

The new service definition created

service

(
  • alias
)
Service protected

Inherited from CanteenBase:

Get a service by alias

Parameters:

Returns:

Service:

The service matching the alias

setPrepends

(
  • maps
  • [value=null]
)
ObjectService protected

Set the collection or single prepend the field value

Parameters:

  • maps Dictionary | String

    If null, returns prepends Dictionary

  • [value=null] String optional

    The value if setting a single map

Returns:

ObjectService:

The instance of this class, for chaining

setProperties

(
  • [props=null]
)
ObjectService protected

Set additional selection properties not part of the field set

Parameters:

  • [props=null] Array | String* optional

    N-number of strings to set as additional properties, or a collection of strings to add to the existing properties.

Returns:

ObjectService:

The instance of this class, for chaining

setWhere

(
  • args
)
ObjectService protected

Register additional where clauses for the SQL select on get methods

Parameters:

  • args Array | String*

    The collection of extra SQL select where parameters to add to all get selections

Returns:

ObjectService:

The instance of this class, for chaining

template

(
  • name
  • [substitutions=[]
)
String protected

Inherited from CanteenBase:

Convenience method for parsing content

Parameters:

  • name String

    The name of the template to parse

  • [substitutions=[] Dictionary optional

    The dictionary of tags to replace

Returns:

String:

The parsed string

valueSet

(
  • A
  • [validationType=null]
)
String protected

Inherited from Service:

Get a set of ids

Parameters:

  • A Array | String

    single id or a collection of IDs

  • [validationType=null] RegExp optional

    See Validation class for more information on types

Returns:

String:

The MySQL formatted set of IDs

verify

(
  • data
  • [type=null]
  • [suppressErrors=false]
)
Mixed protected

Inherited from Service:

Sanitize input data using the validation types above

Parameters:

  • data String

    The data to be validated, can be an array of items

  • [type=null] RegExp optional

    The type of validation, defaults to Numeric. Can also be an array set of items

  • [suppressErrors=false] Boolean optional

    If we should suppress throwing errors

Returns:

Mixed:

If we don't verify and suppress errors, returns false, else returns the data

verifyField

(
  • item
  • name
  • [value=null]
)
ObjectService protected

Inherited from ObjectService:

The more manual method for verifying a field value.

Parameters:

  • item ObjectServiceItem

    Registered item

  • name Dictionary | String

    The name of the field or a map of name=>values

  • [value=null] Mixed optional

    The value to check against

Returns:

ObjectService:

The instance of this object for chaining

Properties

alias

String

Inherited from Service:

The name of the service alias

cache

ServerCache

Inherited from CanteenBase:

Get the instance of the site cache

className

String

The name of the class to bind with

db

Database

Inherited from Service:

Convenience getter for the database connection

item

ObjectServiceItem protected

The item definition

item

ObjectServiceItem

The reference to the object

items

Dictionary

Inherited from ObjectService:

The dictionary of item names to ObjectServiceItem objects

mappings

Array private

Inherited from Service:

The mappings used to prepend the data object paths

parser

Parser

Inherited from CanteenBase:

The parser is responsible for rendering templates

prepends

Dictionary

The list of prepend map

profiler

Profiler

Inherited from CanteenBase:

The instance of the profiler for debugging performance

properties

Array

The list of select properties

settings

SettingsManager

Inherited from CanteenBase:

Get the instance of the settings manager

site

Site

Inherited from CanteenBase:

Convenience getter for the site

table

String

The name of the table of the custom type

user

Authorization

Inherited from CanteenBase:

Get the Authorization class to handle things like login, password change