Skip to content
Permalink
Browse files

Add BehaviorRegistry::className().

This helps in behavior class resolution since core behaviors are
under ORM/Behavior while in app they are under Model/Behavior.
  • Loading branch information...
ADmad committed Dec 2, 2017
1 parent 1785901 commit 5e8cdc51e2a4f02eae565af46a01005afcf5b48d
Showing with 33 additions and 3 deletions.
  1. +15 −3 src/ORM/BehaviorRegistry.php
  2. +18 −0 tests/TestCase/ORM/BehaviorRegistryTest.php
@@ -84,12 +84,11 @@ public function setTable(Table $table)
/**
* Resolve a behavior classname.
*
* Part of the template method for Cake\Core\ObjectRegistry::load()
*
* @param string $class Partial classname to resolve.
* @return string|false Either the correct classname or false.
* @since 3.5.7
*/
protected function _resolveClassName($class)
public static function className($class)
{
$result = App::className($class, 'Model/Behavior', 'Behavior');
if (!$result) {
@@ -99,6 +98,19 @@ protected function _resolveClassName($class)
return $result;
}
/**
* Resolve a behavior classname.
*
* Part of the template method for Cake\Core\ObjectRegistry::load()
*
* @param string $class Partial classname to resolve.
* @return string|false Either the correct classname or false.
*/
protected function _resolveClassName($class)
{
return static::className($class);
}
/**
* Throws an exception when a behavior is missing.
*
@@ -51,6 +51,24 @@ public function tearDown()
parent::tearDown();
}
/**
* Test classname resolution.
*
* @return void
*/
public function testClassName()
{
Plugin::load('TestPlugin');
$expected = 'Cake\ORM\Behavior\TranslateBehavior';
$result = BehaviorRegistry::className('Translate');
$this->assertSame($expected, $result);
$expected = 'TestPlugin\Model\Behavior\PersisterOneBehavior';
$result = BehaviorRegistry::className('TestPlugin.PersisterOne');
$this->assertSame($expected, $result);
}
/**
* Test loading behaviors.
*

0 comments on commit 5e8cdc5

Please sign in to comment.
You can’t perform that action at this time.