Skip to content

Commit

Permalink
Optimize class name check.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Pustułka committed Feb 3, 2017
1 parent 45cc8da commit 58c8b6a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ORM/Association.php
Expand Up @@ -402,12 +402,14 @@ public function getTarget()
}
$this->_targetTable = $tableLocator->get($registryAlias, $config);

$targetClassName = get_class($this->_targetTable);
$className = $this->_getClassName($registryAlias, ['className' => $this->_className]);
if (!is_a($this->_targetTable, $className)) {

if ($targetClassName !== $className) {
throw new RuntimeException(sprintf(
'Invalid Table retrieved from a registry. Requested: %s, got: %s',
$className,
get_class($this->_targetTable)
$targetClassName
));
}
}
Expand Down Expand Up @@ -1301,7 +1303,9 @@ protected function _getClassName($alias, array $options = [])
$options['className'] = Inflector::camelize($alias);
}

return App::className($options['className'], 'Model/Table', 'Table') ?: 'Cake\ORM\Table';
$className = App::className($options['className'], 'Model/Table', 'Table') ?: 'Cake\ORM\Table';

return ltrim($className, '\\');
}

/**
Expand Down

0 comments on commit 58c8b6a

Please sign in to comment.