PHP Class Drest\Service

Is also injected into custom service actions
Datei anzeigen Open project: leedavis81/drest Class Usage Examples

Protected Properties

Property Type Description
$dm drest\Manager Drest Manager
$error_handler DrestCommon\Error\Handler\AbstractHandler The error handler instance
$matched_route Drest\Mapping\RouteMetaData When a route object is matched, it's injected into the service class
$representation DrestCommon\Representation\AbstractRepresentation A representation instance determined either from configuration or client media accept type - can be null if none matched Note this will be present on both a fetch (GET) request and on a push (POST / PUT) request if using the drest client
$service_action_registry Drest\Service\Action\Registry Service Action Registry

Public Methods

Method Description
__construct ( drest\Manager $dm, Drest\Service\Action\Registry $service_action_registry ) Initialise a new instance of a Drest service
getDrestManager ( ) : drest\Manager Get the Drest Manager
getEntityManager ( ) : EntityManager Get the entity manager This will return the default manager, to choose a specific one use getEntityManagerRegistry()
getEntityManagerRegistry ( ) : drest\EntityManagerRegistry Get the entity manager registry
getMatchedRoute ( ) : RouteMetaData Get the route object that was matched
getRepresentation ( ) : DrestCommon\Representation\AbstractRepresentation Get the predetermined representation
getRequest ( ) : DrestCommon\Request\Request Get the request object
getResponse ( ) : DrestCommon\Response\Response Get the response object
getServiceActionRegistry ( ) : Drest\Service\Action\Registry Get the service action registry
handleError ( Exception $e, integer $defaultResponseCode = 500, DrestCommon\Error\Response\ResponseInterface $errorDocument = null ) : DrestCommon\ResultSet Handle an error - set the resulting error document to the response object
renderDeterminedRepresentation ( DrestCommon\ResultSet $resultSet ) Write out as result set on the representation object that was determined - if no representation has been determined - defaults to text
runCallMethod ( ) Run the call method required on this service object
setErrorHandler ( DrestCommon\Error\Handler\AbstractHandler $error_handler ) Set the error handler object
setMatchedRoute ( RouteMetaData $matched_route ) Set the matched route object
setRepresentation ( DrestCommon\Representation\AbstractRepresentation $representation ) Set any predetermined representation instance
setUpAndRunRequest ( ) Set up and run the required call method

Protected Methods

Method Description
getActionInstance ( ) : Drest\Service\Action\AbstractAction Get an instance of the action class to be used
getDefaultAction ( ) : Drest\Service\Action\AbstractAction Gets an instance of the "default" action based of request information
setupRequest ( ) : boolean Called on successful routing of a service call Prepares the service to a request to be rendered

Method Details

__construct() public method

Initialise a new instance of a Drest service
public __construct ( drest\Manager $dm, Drest\Service\Action\Registry $service_action_registry )
$dm drest\Manager - The Drest Manager object
$service_action_registry Drest\Service\Action\Registry - registry use to look up service actions

getActionInstance() protected method

Get an instance of the action class to be used
protected getActionInstance ( ) : Drest\Service\Action\AbstractAction
return Drest\Service\Action\AbstractAction $action

getDefaultAction() protected method

Gets an instance of the "default" action based of request information
protected getDefaultAction ( ) : Drest\Service\Action\AbstractAction
return Drest\Service\Action\AbstractAction $action

getDrestManager() public method

Get the Drest Manager
public getDrestManager ( ) : drest\Manager
return drest\Manager $dm

getEntityManager() public method

Get the entity manager This will return the default manager, to choose a specific one use getEntityManagerRegistry()
public getEntityManager ( ) : EntityManager
return Doctrine\ORM\EntityManager $em

getEntityManagerRegistry() public method

Get the entity manager registry
public getEntityManagerRegistry ( ) : drest\EntityManagerRegistry
return drest\EntityManagerRegistry

getMatchedRoute() public method

Get the route object that was matched
public getMatchedRoute ( ) : RouteMetaData
return Drest\Mapping\RouteMetaData $matched_route

getRepresentation() public method

Get the predetermined representation
public getRepresentation ( ) : DrestCommon\Representation\AbstractRepresentation
return DrestCommon\Representation\AbstractRepresentation

getRequest() public method

Get the request object
public getRequest ( ) : DrestCommon\Request\Request
return DrestCommon\Request\Request $request

getResponse() public method

Get the response object
public getResponse ( ) : DrestCommon\Response\Response
return DrestCommon\Response\Response $response

getServiceActionRegistry() public method

Get the service action registry
public getServiceActionRegistry ( ) : Drest\Service\Action\Registry
return Drest\Service\Action\Registry $service_action_registry

handleError() public method

Handle an error - set the resulting error document to the response object
public handleError ( Exception $e, integer $defaultResponseCode = 500, DrestCommon\Error\Response\ResponseInterface $errorDocument = null ) : DrestCommon\ResultSet
$e Exception
$defaultResponseCode integer the default response code to use if no match on exception type occurs
$errorDocument DrestCommon\Error\Response\ResponseInterface
return DrestCommon\ResultSet the error result set

renderDeterminedRepresentation() public method

Write out as result set on the representation object that was determined - if no representation has been determined - defaults to text
public renderDeterminedRepresentation ( DrestCommon\ResultSet $resultSet )
$resultSet DrestCommon\ResultSet

runCallMethod() final public method

Run the call method required on this service object
final public runCallMethod ( )

setErrorHandler() public method

Set the error handler object
public setErrorHandler ( DrestCommon\Error\Handler\AbstractHandler $error_handler )
$error_handler DrestCommon\Error\Handler\AbstractHandler

setMatchedRoute() public method

Set the matched route object
public setMatchedRoute ( RouteMetaData $matched_route )
$matched_route Drest\Mapping\RouteMetaData

setRepresentation() public method

Set any predetermined representation instance
public setRepresentation ( DrestCommon\Representation\AbstractRepresentation $representation )
$representation DrestCommon\Representation\AbstractRepresentation

setUpAndRunRequest() public method

Set up and run the required call method
public setUpAndRunRequest ( )

setupRequest() protected method

Called on successful routing of a service call Prepares the service to a request to be rendered
protected setupRequest ( ) : boolean
return boolean $result - if false then fail fast no call to runCallMethod() should be made.

Property Details

$dm protected_oe property

Drest Manager
protected Manager,drest $dm
return drest\Manager

$error_handler protected_oe property

The error handler instance
protected AbstractHandler,DrestCommon\Error\Handler $error_handler
return DrestCommon\Error\Handler\AbstractHandler

$matched_route protected_oe property

When a route object is matched, it's injected into the service class
protected RouteMetaData,Drest\Mapping $matched_route
return Drest\Mapping\RouteMetaData

$representation protected_oe property

A representation instance determined either from configuration or client media accept type - can be null if none matched Note this will be present on both a fetch (GET) request and on a push (POST / PUT) request if using the drest client
protected AbstractRepresentation,DrestCommon\Representation $representation
return DrestCommon\Representation\AbstractRepresentation

$service_action_registry protected_oe property

Service Action Registry
protected Registry,Drest\Service\Action $service_action_registry
return Drest\Service\Action\Registry