# Controller

## Actions

Each actions is prefixed with request method and suffixed with `Action`. For example, when user makes `GET` request on `foo` action, `getFooAction()` is called.

All dependencies are automatically injected using `constructor` and `method` injections.

Below is an example of a standard controller providing CRUD actions.

```php
<?php

namespace Vendor\Domain\Controller;

use Vendor\Domain\Record\User;
use Vendor\Domain\Entity\Users;
use Vendor\Domain\Form\CreateUser;
use Vendor\Domain\Form\UpdateUser;
use Vendor\Domain\Form\PatchUser;

class MyController
{
    public function getIndexAction()
    {
        return [
            'users' => (new Users())->all(),
        ];
    }

    public function postIndexAction(CreateUser $createUser)
    {
        $user = new User();
        $createUser->populateToRecord($user);

        return [
            'user' => $user->save(),
        ];
    }

    public function getOneAction(User $user)
    {
        return [
            'user' => $user,
        ];
    }

    public function postOneAction(User $user, UpdateUser $updateUser)
    {
        $updateUser->populateToRecord($user);

        return [
            'user' => $user->save(),
        ];
    }

    public function patchOneAction(User $user, UpdateUser $updateUser)
    {
        $updateUser->populateToRecord($user);

        return [
            'user' => $user->save(),
        ];
    }

    public function deleteOneAction(User $user)
    {
        return [
            'deleted' => $user->delete(),
        ];
    }
}
```
