Full stack framework based on symfony's components
dev-master
2013-10-08 10:39 UTC
Requires
- doctrine/dbal: 2.3.4
- symfony/config: v2.3.1
- symfony/dependency-injection: v2.3.1
- symfony/event-dispatcher: v2.3.1
- symfony/http-foundation: v2.3.1
- symfony/http-kernel: v2.3.1
- symfony/routing: v2.3.1
- symfony/yaml: v2.3.1
- twig/twig: v1.13.1
Requires (Dev)
- phpunit/phpunit: 3.7.22
This package is not auto-updated.
Last update: 2024-12-16 17:06:48 UTC
README
instalation:
composer
{
"require": {
"gonzalo123/g": "dev-master"
},
"autoload": {
"psr-0": {
"": ["app/"]
}
}
}
index.php:
<?php include __DIR__ . '/vendor/autoload.php'; $app = G\Application::factory([ 'config.path' => __DIR__ . '/config', 'view.path' => __DIR__ . '/views', ]); $app->run();
config and view folders
mkdir config
mkdir view
/config/routes.yml
home:
path: /
defaults: { _controller: AppController::homeAction}
/config/services.yml
services:
Symfony\Component\HttpFoundation\JSonResponse:
class: Symfony\Component\HttpFoundation\JSonResponse
Symfony\Component\HttpFoundation\Response:
class: Symfony\Component\HttpFoundation\Response
Controller
<?php class AppController { public function homeAction() { return "AppController::home"; } }
Complex controller
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]); } }
RESTFull controllers
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; } }