API Documentation for: 1.1.1
Show:

Service Class

Extends CanteenBase
Namespace: Canteen\Services

All services should extends this base service class. Located in the namespace Canteen\Services.

Constructor

Service

(
  • alias
)

Parameters:

  • alias String

    The alias to register service as

Methods

bindObject

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

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

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

dataMap

(
  • results
  • [key='id']
)
Dictionary static

Turn a collection of objects into a dictionary by a property name.

Parameters:

  • results Array

    The objects collection

  • [key='id'] String optional

    The name of the key to create the map on

Returns:

Dictionary:

The objects mapped by property

gateway

(
  • uri
  • method
  • [privilege=Privilege::ANONYMOUS]
)
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

get

(
  • alias
)
Service static

Get a particular service by alias

Parameters:

  • alias String

    The _registered alias or class name

Returns:

Service:

The instance of the service

getAll

() Array static

Get all the service aliases

Returns:

Array:

The collection of string aliases

getCaller

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

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

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

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

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

register

(
  • alias
  • service
)
static

Add a single service alias

Parameters:

  • alias String

    The service alias

  • service Service

    The Service object

service

(
  • alias
)
Service protected

Inherited from CanteenBase:

Get a service by alias

Parameters:

Returns:

Service:

The service matching the alias

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

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

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

Properties

alias

String

The name of the service alias

cache

ServerCache

Inherited from CanteenBase:

Get the instance of the site cache

db

Database

Convenience getter for the database connection

mappings

Array private

The mappings used to prepend the data object paths

parser

Parser

Inherited from CanteenBase:

The parser is responsible for rendering templates

profiler

Profiler

Inherited from CanteenBase:

The instance of the profiler for debugging performance

registerd

Dictionary private static

The registered list of services by alias

settings

SettingsManager

Inherited from CanteenBase:

Get the instance of the settings manager

site

Site

Inherited from CanteenBase:

Convenience getter for the site

user

Authorization

Inherited from CanteenBase:

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