Rest
Class Controller
- Full name:
\Zemit\Mvc\Controller\Rest
- Parent class:
\Zemit\Mvc\Controller
- This class implements:
\Zemit\Mvc\Controller\RestInterface
Inherited methods
beforeExecuteRoute
public beforeExecuteRoute(): void
attachBehavior
Attach a behavior to the object.
public attachBehavior(string $eventClass, string|null $eventType = null, int|null $priority = null): void
Parameters:
Parameter | Type | Description |
---|---|---|
$eventClass | string | The behavior to attach. |
$eventType | **string | null** |
$priority | **int | null** |
attachBehaviors
Attach multiple behaviors to the object.
public attachBehaviors(array $behaviors = [], string|null $eventType = null, int|null $priority = null): void
Parameters:
Parameter | Type | Description |
---|---|---|
$behaviors | array | An array of behaviors to attach. |
$eventType | **string | null** |
$priority | **int | null** |
isDebugEnabled
Returns whether debug mode is enabled.
public isDebugEnabled(): bool
Return Value:
True if debug mode is enabled, false otherwise.
getFractalManager
Get the Fractal Manager object.
public getFractalManager(): \Zemit\Fractal\Manager
This method returns the Fractal Manager object used for transforming data. If the Fractal Manager object is not already created, it will be created and initialized with the Fractal Serializer before being returned.
Return Value:
The Fractal Manager object.
setFractalManager
Set the Fractal Manager for the class.
public setFractalManager(\Zemit\Fractal\Manager|null $manager): void
Parameters:
Parameter | Type | Description |
---|---|---|
$manager | **\Zemit\Fractal\Manager | null** |
getFractalSerializer
Get the fractal serializer for the class.
public getFractalSerializer(): \League\Fractal\Serializer\SerializerAbstract
Return Value:
The fractal serializer instance.
setFractalSerializer
Set the Fractal serializer for the class.
public setFractalSerializer(\League\Fractal\Serializer\SerializerAbstract $serializer): void
Parameters:
Parameter | Type | Description |
---|---|---|
$serializer | \League\Fractal\Serializer\SerializerAbstract | The Fractal serializer to be set. |
getTransformer
Get the transformer for the class.
public getTransformer(): \League\Fractal\TransformerAbstract
If the transformer has not been set, a new instance of ModelTransformer will be created.
Return Value:
The transformer for the class.
setTransformer
Set the transformer for the class.
public setTransformer(\League\Fractal\TransformerAbstract|null $transformer = null): void
Parameters:
Parameter | Type | Description |
---|---|---|
$transformer | **\League\Fractal\TransformerAbstract | null** |
hasTransformer
Determine if a default transformer has been set for the fractal manager
public hasTransformer(): bool
Return Value:
Returns true if a default transformer has been set, false otherwise
transformModel
Transform a model using a transformer and optionally a fractal manager.
public transformModel(\Phalcon\Mvc\ModelInterface $model, \League\Fractal\TransformerAbstract|null $transformer = null, \Zemit\Fractal\Manager|null $fractalManager = null): array|null
Parameters:
Parameter | Type | Description |
---|---|---|
$model | \Phalcon\Mvc\ModelInterface | The model to transform. |
$transformer | **\League\Fractal\TransformerAbstract | null** |
$fractalManager | **\Zemit\Fractal\Manager | null** |
Return Value:
The transformed model as an array, or null if the transformation fails.
transformResultset
Transforms a resultset using the provided transformer and fractal manager.
public transformResultset(\Phalcon\Mvc\Model\ResultsetInterface $resultset, \League\Fractal\TransformerAbstract|null $transformer = null, \Zemit\Fractal\Manager|null $fractalManager = null): array|null
Parameters:
Parameter | Type | Description |
---|---|---|
$resultset | \Phalcon\Mvc\Model\ResultsetInterface | The resultset to be transformed. |
$transformer | **\League\Fractal\TransformerAbstract | null** |
$fractalManager | **\Zemit\Fractal\Manager | null** |
Return Value:
The transformed resultset as an array, or null if the transformation failed.
transformItem
Transform an item using the specified transformer and Fractal manager
public transformItem(mixed $data, \League\Fractal\TransformerAbstract|null $transformer = null, \Zemit\Fractal\Manager|null $fractalManager = null): array|null
Parameters:
Parameter | Type | Description |
---|---|---|
$data | mixed | The data to transform |
$transformer | **\League\Fractal\TransformerAbstract | null** |
$fractalManager | **\Zemit\Fractal\Manager | null** |
Return Value:
The transformed item as an array
transformCollection
Transform a collection of data using a specified transformer and Fractal manager.
public transformCollection(mixed $data, \League\Fractal\TransformerAbstract|null $transformer = null, \Zemit\Fractal\Manager|null $fractalManager = null): array|null
Parameters:
Parameter | Type | Description |
---|---|---|
$data | mixed | The collection of data to be transformed. |
$transformer | **\League\Fractal\TransformerAbstract | null** |
$fractalManager | **\Zemit\Fractal\Manager | null** |
Return Value:
The transformed data as an array.
getParam
Get a specific parameter value by key.
public getParam(string $key, array|string|null $filters = null, mixed $default = null, array|null $params = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$key | string | The key of the parameter. |
$filters | **array | string |
$default | mixed | Optional. The default value if the parameter does not exist. Defaults to null. |
$params | **array | null** |
Return Value:
The value of the specified parameter, after applying the filters if provided. If the parameter does not exist, then the default value is returned if provided. If both the parameter and the default value are missing, then the value from the dispatcher's parameter is returned.
Throws:
getParams
Retrieves the request parameters.
public getParams(array|null $filters = null): array
Parameters:
Parameter | Type | Description |
---|---|---|
$filters | **array | null** |
Return Value:
The request parameters.
setRestErrorResponse
Set the REST response error
public setRestErrorResponse(int $code = 400, string $status = 'Bad Request', mixed $response = null): \Phalcon\Http\ResponseInterface
Parameters:
Parameter | Type | Description |
---|---|---|
$code | int | The HTTP status code (default: 400) |
$status | string | The status message (default: 'Bad Request') |
$response | mixed | The response body (default: null) |
Return Value:
The REST response object
Throws:
setRestResponse
Sending rest response as a http response
public setRestResponse(mixed $response = null, ?int $code = null, ?string $status = null, int $jsonOptions, int $depth = 512): \Phalcon\Http\ResponseInterface
Parameters:
Parameter | Type | Description |
---|---|---|
$response | mixed | |
$code | ?int | |
$status | ?string | |
$jsonOptions | int | |
$depth | int |
Throws:
afterExecuteRoute
Update the Dispatcher after executing the route.
public afterExecuteRoute(\Phalcon\Mvc\Dispatcher $dispatcher): void
Parameters:
Parameter | Type | Description |
---|---|---|
$dispatcher | \Phalcon\Mvc\Dispatcher | The Dispatcher instance. |
Throws: