Added query_method option to PropelParamConverter (#316)
* Update PropelParamConverter.php add "query_method" option equivalence of "repository_method" in doctrine * FIX CS * FIX CS * \method_exists => && method_exists * and => &&
This commit is contained in:
parent
9c4ad7db45
commit
980cff8db6
|
@ -49,6 +49,12 @@ class PropelParamConverter implements ParamConverterInterface
|
|||
*/
|
||||
protected $withs;
|
||||
|
||||
/**
|
||||
* name of method use to call a query method
|
||||
* @var string
|
||||
*/
|
||||
protected $queryMethod;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
|
@ -125,15 +131,24 @@ class PropelParamConverter implements ParamConverterInterface
|
|||
|
||||
$this->withs = isset($options['with']) ? is_array($options['with']) ? $options['with'] : array($options['with']) : array();
|
||||
|
||||
// find by Pk
|
||||
if (false === $object = $this->findPk($classQuery, $request)) {
|
||||
// find by criteria
|
||||
if (false === $object = $this->findOneBy($classQuery, $request)) {
|
||||
if ($configuration->isOptional()) {
|
||||
//we find nothing but the object is optional
|
||||
$object = null;
|
||||
} else {
|
||||
throw new \LogicException('Unable to guess how to get a Propel object from the request information.');
|
||||
$this->queryMethod = $queryMethod = isset($options['query_method']) ? $options['query_method'] : null;
|
||||
|
||||
if ($this->queryMethod != null && method_exists($classQuery, $this->queryMethod)) {
|
||||
// find by custom method
|
||||
$query = $this->getQuery($classQuery);
|
||||
// execute a custom query
|
||||
$object = $query->$queryMethod($request->attributes);
|
||||
} else {
|
||||
// find by Pk
|
||||
if (false === $object = $this->findPk($classQuery, $request)) {
|
||||
// find by criteria
|
||||
if (false === $object = $this->findOneBy($classQuery, $request)) {
|
||||
if ($configuration->isOptional()) {
|
||||
//we find nothing but the object is optional
|
||||
$object = null;
|
||||
} else {
|
||||
throw new \LogicException('Unable to guess how to get a Propel object from the request information.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue