Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Implement identifier name property
Browse files Browse the repository at this point in the history
- Added $identifierName property
- Added mutator and accessor for $identifierName
- Modified getIdentifier() to use the $identifierName when attempting to
  retrieve the resource ID.
  • Loading branch information
weierophinney committed Apr 4, 2013
1 parent 2e4ad3a commit 121fbda
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions library/Zend/Mvc/Controller/AbstractRestfulController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ abstract class AbstractRestfulController extends AbstractController
)
);

/**
* Name of request or query parameter containing identifier
*
* @var string
*/
protected $identifierName = 'id';

/**
* @var int From Zend\Json\Json
*/
Expand All @@ -50,6 +57,28 @@ abstract class AbstractRestfulController extends AbstractController
*/
protected $customHttpMethodsMap = array();

/**
* Set the route match/query parameter name containing the identifier
*
* @param string $name
* @return self
*/
public function setIdentifierName($name)
{
$this->identifierName = (string) $name;
return $this;
}

/**
* Retrieve the route match/query parameter name containing the identifier
*
* @return string
*/
public function getIdentifierName()
{
return $this->identifierName;
}

/**
* Create a new resource
*
Expand Down Expand Up @@ -439,12 +468,13 @@ public function addHttpMethodHandler($method, /* Callable */ $handler)
*/
protected function getIdentifier($routeMatch, $request)
{
$id = $routeMatch->getParam('id', false);
$identifier = $this->getIdentifierName();
$id = $routeMatch->getParam($identifier, false);
if ($id) {
return $id;
}

$id = $request->getQuery()->get('id', false);
$id = $request->getQuery()->get($identifier, false);
if ($id) {
return $id;
}
Expand Down

0 comments on commit 121fbda

Please sign in to comment.