gonzalo123 / restfull
restfull silex server
dev-master
2015-02-18 18:00 UTC
Requires
- php: >=5.3.2
- silex/silex: >=v1.1.2, <4.0
- symfony/yaml: ~2.3,<3.0
This package is not auto-updated.
Last update: 2024-12-16 16:48:25 UTC
README
Simple RESTfull server with Silex
We define the resources within a yml file:
example: \Example\Data
We also define the auto dependencies:
Symfony\Component\HttpFoundation\Request: request
Doctrine\DBAL\Connection: db
And we create the resource extending G\RestFull\Resource\RestFullResource We can define parameters in constructor or in request funcions (getOne, getAll, deleteOne, addOne, editOne) parameters to be taken from DIC
namespace Example; use Symfony\Component\HttpFoundation\Request; class Data { private $request; public function __construct(Request $request) { $this->request = $request; } public function getAll() { return [ ['id' => 0, 'name' => 'Peter Parker'], ['id' => 1, 'name' => 'Clark Kent'], ]; } public function getOne($id) { return ['id' => $id, 'name' => 'Clark Kent ' . $this->request->get('a')]; } public function deleteOne($id) { return []; } public function addOne() { return []; } public function editOne($id) { return []; } }
The server is based on silex
use G\RestFull\Silex\RestFullApplication; $app = new RestFullApplication([ 'debug' => true, 'class.map.path' => __DIR__ . '/config/resourceClassMap.yml', 'auto.injection.map.path' => __DIR__ . '/config/autoDependenciesClassMap.yml', 'base.path' => 'rest' // default value ]); $app->run();