Created
May 17, 2015 02:14
-
-
Save adelarcubs/a700d35845ba0e7ac1fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace User\V1\Rest\User; | |
use ZF\ApiProblem\ApiProblem; | |
use ZF\Rest\AbstractResourceListener; | |
class UserResource extends AbstractResourceListener { | |
private $em; | |
public function __construct($em) { | |
$this->em = $em; | |
} | |
/** | |
* Create a resource | |
* | |
* @param mixed $data | |
* @return ApiProblem|mixed | |
*/ | |
public function create($data) { | |
return new ApiProblem(405, 'The POST method has not been defined'); | |
} | |
/** | |
* Delete a resource | |
* | |
* @param mixed $id | |
* @return ApiProblem|mixed | |
*/ | |
public function delete($id) { | |
return new ApiProblem(405, 'The DELETE method has not been defined for individual resources'); | |
} | |
/** | |
* Delete a collection, or members of a collection | |
* | |
* @param mixed $data | |
* @return ApiProblem|mixed | |
*/ | |
public function deleteList($data) { | |
return new ApiProblem(405, 'The DELETE method has not been defined for collections'); | |
} | |
/** | |
* Fetch a resource | |
* | |
* @param mixed $id | |
* @return ApiProblem|mixed | |
*/ | |
public function fetch($id) { | |
$qb = $this->em->createQueryBuilder(); | |
$qb->select('e'); | |
$qb->from('User\Entity\User', 'e'); | |
$qb->where('e.id = :id'); | |
$qb->setParameters(array( | |
'id' => $id | |
)); | |
return $qb->getQuery()->getArrayResult(); | |
} | |
/** | |
* Fetch all or a subset of resources | |
* | |
* @param array $params | |
* @return ApiProblem|mixed | |
*/ | |
public function fetchAll($params = array()) { | |
$qb = $this->em->createQueryBuilder(); | |
$qb->select('e'); | |
$qb->from('User\Entity\User', 'e'); | |
return new UserCollection($qb->getQuery()->getArrayResult()); | |
} | |
/** | |
* Patch (partial in-place update) a resource | |
* | |
* @param mixed $id | |
* @param mixed $data | |
* @return ApiProblem|mixed | |
*/ | |
public function patch($id, $data) { | |
return new ApiProblem(405, 'The PATCH method has not been defined for individual resources'); | |
} | |
/** | |
* Replace a collection or members of a collection | |
* | |
* @param mixed $data | |
* @return ApiProblem|mixed | |
*/ | |
public function replaceList($data) { | |
return new ApiProblem(405, 'The PUT method has not been defined for collections'); | |
} | |
/** | |
* Update a resource | |
* | |
* @param mixed $id | |
* @param mixed $data | |
* @return ApiProblem|mixed | |
*/ | |
public function update($id, $data) { | |
return new ApiProblem(405, 'The PUT method has not been defined for individual resources'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment