{
"require": {
"gonzalo123/g": "dev-master"
},
"autoload": {
"psr-0": {
"": ["app/"]
}
}
}
<?php
include __DIR__ . '/vendor/autoload.php';
$app = G\Application::factory([
'config.path' => __DIR__ . '/config',
'view.path' => __DIR__ . '/views',
]);
$app->run();
mkdir config
mkdir view
home:
path: /
defaults: { _controller: AppController::homeAction}
services:
Symfony\Component\HttpFoundation\JSonResponse:
class: Symfony\Component\HttpFoundation\JSonResponse
Symfony\Component\HttpFoundation\Response:
class: Symfony\Component\HttpFoundation\Response
<?php
class AppController
{
public function homeAction()
{
return "AppController::home";
}
}
another route:
hello:
path: /hello/{name}
defaults: { _controller: AppController::helloAction}
class AppController
{
private $request;
public function __construct(Request $request)
{
$this->request = $request;
}
public function helloAction($name, JsonResponse $response)
{
return $response->setData([$name, 1, 2]);
}
}
we add to our services.yml:
restResources:
book:
path: /resource/book
class: BookResource
And we define our BookResource
<?php
use G\RESTFull\Get;
use G\RESTFull\GetAll;
use G\RESTFull\Delete;
use G\RESTFull\Create;
use G\RESTFull\Update;
class BookResource implements Get, GetAll, Delete, Create, Update
{
public function getAction($id)
{
return "BookResource:getAction " . $id;
}
public function getAllAction()
{
return "BookResource:getAllAction";
}
public function saveAction($id)
{
return "BookResource:saveAction " . $id;
}
public function addAction()
{
return "BookResource:addAction";
}
public function deleteAction($id)
{
return "BookResource:deleteAction " . $id;
}
}