Commit 33d6acba by Carsten Brandt

Improved behavior support, fixes #2550

call hasMethod() instead of using method_exists
parent 6f9e9cd5
...@@ -121,7 +121,7 @@ class Formatter extends Component ...@@ -121,7 +121,7 @@ class Formatter extends Component
$params = [$value]; $params = [$value];
} }
$method = 'as' . $format; $method = 'as' . $format;
if (method_exists($this, $method)) { if ($this->hasMethod($method)) {
return call_user_func_array([$this, $method], $params); return call_user_func_array([$this, $method], $params);
} else { } else {
throw new InvalidParamException("Unknown type: $format"); throw new InvalidParamException("Unknown type: $format");
......
...@@ -136,13 +136,13 @@ trait ActiveRelationTrait ...@@ -136,13 +136,13 @@ trait ActiveRelationTrait
* Finds the related records for the specified primary record. * Finds the related records for the specified primary record.
* This method is invoked when a relation of an ActiveRecord is being accessed in a lazy fashion. * This method is invoked when a relation of an ActiveRecord is being accessed in a lazy fashion.
* @param string $name the relation name * @param string $name the relation name
* @param ActiveRecordInterface $model the primary model * @param ActiveRecordInterface|BaseActiveRecord $model the primary model
* @return mixed the related record(s) * @return mixed the related record(s)
* @throws InvalidParamException if the relation is invalid * @throws InvalidParamException if the relation is invalid
*/ */
public function findFor($name, $model) public function findFor($name, $model)
{ {
if (method_exists($model, 'get' . $name)) { if ($model->hasMethod('get' . $name)) {
$method = new \ReflectionMethod($model, 'get' . $name); $method = new \ReflectionMethod($model, 'get' . $name);
$realName = lcfirst(substr($method->getName(), 3)); $realName = lcfirst(substr($method->getName(), 3));
if ($realName !== $name) { if ($realName !== $name) {
......
...@@ -136,7 +136,7 @@ class Validator extends Component ...@@ -136,7 +136,7 @@ class Validator extends Component
{ {
$params['attributes'] = $attributes; $params['attributes'] = $attributes;
if ($type instanceof \Closure || method_exists($object, $type)) { if ($type instanceof \Closure || $object->hasMethod($type)) {
// method-based validator // method-based validator
$params['class'] = __NAMESPACE__ . '\InlineValidator'; $params['class'] = __NAMESPACE__ . '\InlineValidator';
$params['method'] = $type; $params['method'] = $type;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment