예제 #1
0
 protected function addRoutes(ControllerCollection $controllers)
 {
     $controllers->post('/key', [$this, 'create']);
     $controllers->get('/key/{id}', [$this, 'show']);
     $controllers->put('/key/{id}', [$this, 'update']);
     $controllers->delete('/key/{id}', [$this, 'delete']);
 }
예제 #2
0
 public function connect(Application $app)
 {
     $this->app = $app;
     // api v1
     $api = new ControllerCollection(new Route());
     $api->get('/{model}', __CLASS__ . '::listAction')->assert('model', '^([a-z]+)$');
     $api->get('/{model}/{id}', __CLASS__ . '::itemAction')->assert('model', '^([a-z]+)$')->assert('id', '^([a-z0-9]+)$');
     $api->delete('/{model}/{id}', __CLASS__ . '::deleteAction')->assert('model', '^([a-z]+)$')->assert('id', '^([a-z0-9]+)$');
     $api->put('/{model}/{id}', __CLASS__ . '::updateAction')->assert('model', '^([a-z]+)$')->assert('id', '^([a-z0-9]+)$');
     $api->post('/{model}', __CLASS__ . '::createAction')->assert('model', '^([a-z]+)$');
     //        $model = $this->checkModel('message');
     //
     //        foreach (range(900, 1000) as $id)
     //        {
     //            $message = new $model;
     //
     //            $message->text = $id;
     //            $message->date = time();
     //
     //            $this->dm->persist($message);
     //        }
     //
     //        $this->dm->flush();
     return $api;
 }
예제 #3
0
 /**
  *
  *
  * @param ControllerCollection $factory
  * @return null
  */
 public function createRoutes(ControllerCollection $factory)
 {
     $factory->get('/files', [$this, 'get']);
     $factory->get('/files/{hash}', [$this, 'getOne']);
     $factory->post('/files/{hash}', [$this, 'userAction']);
     $factory->delete('/files/{hash}', [$this, 'remove'])->onlyAdmin();
     $factory->put('/files/{hash}', [$this, 'update'])->onlyAdmin();
     $factory->get('/artists', [$this, 'getArtists']);
 }
예제 #4
0
 protected function addRoutes(ControllerCollection $controllers)
 {
     $controllers->post('/api/users', array($this, 'newAction'));
     $controllers->get('/api/users/{name}', array($this, 'showAction'))->bind('api_users_show');
     $controllers->get('/api/users', array($this, 'listAction'));
     $controllers->put('/api/users/{name}', array($this, 'updateAction'));
     $controllers->delete('/api/users/{name}', array($this, 'deleteAction'));
     $controllers->match('api/users/{name}', array($this, 'updateAction'))->method('PATCH');
 }
 /**
  * Setup the basic crud endpoints for this controller
  * @param ControllerCollection $controller
  * @return ControllerCollection
  */
 public function addCrudOperations(ControllerCollection $controller)
 {
     $controller->get("/search", array($this, "search"));
     $controller->get("/{id}", array($this, "get"));
     $controller->post("/", array($this, "create"));
     $controller->put("/{id}", array($this, "update"));
     $controller->delete("/{id}", array($this, "delete"));
     return $controller;
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function connect(Application $app)
 {
     $modelName = $this->modelName;
     $prefix = sprintf('rest_controller.%s.', $this->modelName);
     if (null !== $this->modelClass) {
         $app[$prefix . 'model_class'] = $this->modelClass;
     }
     if (null !== $this->lastModifiedGetter) {
         $app[$prefix . 'last_modified_getter'] = $this->lastModifiedGetter;
     }
     if (isset($app[$prefix . 'model_class'])) {
         $app[$prefix . 'query_class'] = $app[$prefix . 'model_class'] . 'Query';
     } else {
         throw new \InvalidArgumentException(sprintf('You have to configure the "%s.model_class" parameter.', $prefix));
     }
     $controllers = new ControllerCollection($app['route_factory']);
     /**
      * Returns all objects
      */
     $controllers->get('/', function () use($app, $prefix) {
         $query = new $app[$prefix . 'query_class']();
         return new Response($query->find()->exportTo($app['json_parser']), 200, array('Content-Type' => 'application/json'));
     });
     /**
      * Returns a specific object identified by a given id
      */
     $controllers->get('/{id}', function ($id) use($app, $prefix, $modelName) {
         $query = new $app[$prefix . 'query_class']();
         $object = $query->findPk($id);
         if (!$object instanceof $app[$prefix . 'model_class']) {
             throw new NotFoundHttpException(sprintf('%s with id "%d" does not exist.', ucfirst($modelName), $id));
         }
         $response = new Response($object->exportTo($app['json_parser']), 200, array('Content-Type' => 'application/json'));
         if (isset($app[$prefix . 'last_modified_getter'])) {
             $response->setLastModified($object->{$app}[$prefix . 'last_modified_getter']());
         }
         return $response;
     });
     /**
      * Create a new object
      */
     $controllers->post('/', function (Request $request) use($app, $prefix) {
         $object = new $app[$prefix . 'model_class']();
         $object->fromArray($request->request->all());
         $object->save();
         return new Response($object->exportTo($app['json_parser']), 201, array('Content-Type' => 'application/json'));
     });
     /**
      * Update a object identified by a given id
      */
     $controllers->put('/{id}', function ($id, Request $request) use($app, $prefix, $modelName) {
         $query = new $app[$prefix . 'query_class']();
         $object = $query->findPk($id);
         if (!$object instanceof $app[$prefix . 'model_class']) {
             throw new NotFoundHttpException(sprintf('%s with id "%d" does not exist.', ucfirst($modelName), $id));
         }
         $object->fromArray($request->request->all());
         $object->save();
         if (isset($app['monolog'])) {
             $app['monolog']->addInfo(sprintf('Update %s with id %d', ucfirst($modelName), $id));
         }
         return new Response($object->exportTo($app['json_parser']), 200, array('Content-Type' => 'application/json'));
     });
     /**
      * Delete a object identified by a given id
      */
     $controllers->delete('/{id}', function ($id) use($app, $prefix) {
         $query = new $app[$prefix . 'query_class']();
         $query->filterByPrimaryKey($id)->delete();
         return new Response('', 204, array('Content-Type' => 'application/json'));
     });
     return $controllers;
 }