cyve/slim-platform

PHP micro framework for REST API based on Slim

1.0.1 2020-01-12 12:02 UTC

This package is auto-updated.

Last update: 2024-04-13 18:23:19 UTC


README

PHP micro framework for REST API based on Slim and inspired by API Platform.

Installation

$ composer create-project cyve/slim-platform"
// config.php
return [
    'title' => 'Slim Platform',
    'parameters' => [],
    'resources' => [
        'book' => [
            'table' => 'book',
            'model' => [
                'title' => ['type' => 'string', 'required' => true],
                'isbn' => ['type' => 'string'],
                'description' => ['type' => 'string'],
                'author' => ['type' => 'string'],
                'publicationDate' => ['type' => 'datetime']
            ],
            'actions' => [
                'create' => ['method' => 'POST', 'uri' => '/books'],
                'read' => ['method' => 'GET', 'uri' => '/books/{id}'],
                'update' => ['method' => 'PUT', 'uri' => '/books/{id}'],
                'delete' => ['method' => 'DELETE', 'uri' => '/books/{id}'],
                'index' => ['method' => 'GET', 'uri' => '/books']
            ]
        ]
    ]
];
// index.php
require 'vendor/autoload.php';

if (is_readable('.env')) {
    $_ENV = $_ENV + parse_ini_file('.env');
}

$config = include 'config.php';
$config['parameters'] += $_ENV;

$app = new SlimPlatform\App($config);
$app->run();