PHP code example of asylum29 / api-skeleton

1. Go to this page and download the library: Download asylum29/api-skeleton library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

asylum29 / api-skeleton example snippets


// унаследуйте контроллер от BaseController
class CustomController extends BaseController
{
    /**
     * @Route("/custom", name="app_custom")
     */
    public function index(): Response
    {
        ...
        return $this->success($dataOrEntity);
    }
}

// в Entity или DTO
/** @Groups("groupName") */
private $field;
/** @Groups("groupName") */
public function getField(): fieldtype

// в контроллере
return $this->success($dataOrEntity, ['groups' => 'groupName']);

// в контроллере
return $this->success(
    $entities,
    [
        'current_page' => $page,
        'per_page' => $perPage,
        'total' => $count,
    ]
);

// в контроллере
public function index(): Response
{
    ...
    if (!$valid) {
        $this->error($message, $status);
    }
    ...
}

// в классе DTO
/** @RequestDto */
class СustomDto

// в контроллере
public function index(СustomDto $dto): Response

// в контроллере
$this->validate($object, $groups)

php bin/console make:rest