Skip to main content

Attributes

At a PSX controller you can describe various information using attributes. It is required that you controller method has at least a HTTP Method (one of Get, Post, Put, Patch or Delete) and a Path attribute.

class Population extends ControllerAbstract
{
#[Get]
#[Path('/population')]
public function getAll(#[Query] ?int $startIndex = null, #[Query] ?int $count = null): Model\PopulationCollection
{
return $this->populationTable->getCollection($startIndex, $count);
}

#[Post]
#[Path('/population')]
public function create(#[Body] Model\Population $payload): Model\Message
{
$id = $this->populationService->create($payload);

$message = new Model\Message();
$message->setSuccess(true);
$message->setMessage('Population record successfully created');
$message->setId($id);
return $message;
}
}

PSX tries to automatically add the missing attributes based on the defined arguments and return types. If you like to explicit define the values you can use the following attributes.

AttributeTargetExampleDescription
AuthorizationClass/Method#[Authorization(true)]The operation needs authorization
BodyParameter#[Body]Maps an argument to the HTTP body payload
DeleteClass/Method#[Delete]HTTP DELETE method
DeprecatedClass/Method#[Deprecated(true)]The operation is deprecated
DescriptionClass/Method#[Description("foobar")]Description of this operation
ExcludeClass/Method#[Exclude]Whether to exclude this operation
GetClass/Method#[Get]HTTP GET method
HeaderParameter#[Header]Maps an argument to a value from the HTTP header
OperationIdClass/Method#[OperationId("my.method")]The operation id
ParamParameter#[Param]Maps an argument to a dynamic path fragment
PatchClass/Method#[Patch]HTTP PATCH method
PathClass/Method#[Path("/endpoint")]The endpoint path
PostClass/Method#[Post]HTTP POST method
PutClass/Method#[Put]HTTP PUT method
QueryParameter#[Query]Maps an argument to a value from the query parameters
SecurityClass/Method#[Security(["scope"])]The scopes assigned to this operations
StatusCodeClass/Method#[StatusCode(201)]Describes the response status code
TagsClass/Method#[Tags(["tag"])]Tags assigned to this operation