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:
Abdallah ARFFAK 2016-04-13 18:07:35 +01:00 committed by Marc J. Schmidt
parent 9c4ad7db45
commit 980cff8db6
No known key found for this signature in database
GPG key ID: 152515A32C34AD1B

View file

@ -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.');
}
}
}
}