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;
|
protected $withs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* name of method use to call a query method
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $queryMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
|
@ -125,6 +131,14 @@ class PropelParamConverter implements ParamConverterInterface
|
||||||
|
|
||||||
$this->withs = isset($options['with']) ? is_array($options['with']) ? $options['with'] : array($options['with']) : array();
|
$this->withs = isset($options['with']) ? is_array($options['with']) ? $options['with'] : array($options['with']) : array();
|
||||||
|
|
||||||
|
$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
|
// find by Pk
|
||||||
if (false === $object = $this->findPk($classQuery, $request)) {
|
if (false === $object = $this->findPk($classQuery, $request)) {
|
||||||
// find by criteria
|
// find by criteria
|
||||||
|
@ -137,6 +151,7 @@ class PropelParamConverter implements ParamConverterInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (null === $object && false === $configuration->isOptional()) {
|
if (null === $object && false === $configuration->isOptional()) {
|
||||||
throw new NotFoundHttpException(sprintf('%s object not found.', $configuration->getClass()));
|
throw new NotFoundHttpException(sprintf('%s object not found.', $configuration->getClass()));
|
||||||
|
|
Loading…
Reference in a new issue