Skip to content
Permalink
Browse files

Allow `.` in ObjectRegistry keys.

Allow `.` in object registry keys when a configuration array is present.
This allows cache engines to have dotted names, and also helpers. Doing
this with helpers is a bit silly as you'll end up with helper names you
cannot use. But for Cache it makes sense.

Refs #6919
  • Loading branch information...
markstory committed Jul 2, 2015
1 parent 29ca3d1 commit 94635f061c6b1b530c7997369d9bced9cbda03c7
Showing with 52 additions and 1 deletion.
  1. +6 −1 src/Core/ObjectRegistry.php
  2. +20 −0 tests/TestCase/Cache/CacheTest.php
  3. +26 −0 tests/TestCase/View/HelperRegistryTest.php
@@ -69,7 +69,12 @@ abstract class ObjectRegistry
*/
public function load($objectName, $config = [])
{
list(, $name) = pluginSplit($objectName);
if (empty($config) && !isset($this->_loaded[$objectName])) {
list(, $name) = pluginSplit($objectName);
} else {
$name = $objectName;
}
$loaded = isset($this->_loaded[$name]);
if ($loaded && !empty($config)) {
$this->_checkDuplicate($name, $config);
@@ -250,6 +250,26 @@ public function testConfigRead()
$this->assertEquals($expected, Cache::config('tests'));
}
/**
* test config() with dotted name
*
* @return void
*/
public function testConfigDottedAlias()
{
Cache::config('cache.dotted', [
'className' => 'File',
'path' => TMP,
'prefix' => 'cache_value_'
]);
$engine = Cache::engine('cache.dotted');
$this->assertContains('cache.dotted', Cache::configured());
$this->assertNotContains('dotted', Cache::configured());
$this->assertInstanceOf('Cake\Cache\Engine\FileEngine', $engine);
Cache::drop('cache.dotted');
}
/**
* testGroupConfigs method
*/
@@ -195,6 +195,32 @@ public function testLoadPluginHelper()
$this->assertInstanceOf('TestPlugin\View\Helper\OtherHelperHelper', $this->Helpers->OtherHelper, 'Class is wrong');
}
/**
* test loading helpers with dotted aliases
*
* @return void
*/
public function testLoadPluginHelperDottedAlias()
{
Plugin::load(['TestPlugin']);
$result = $this->Helpers->load('thing.helper', [
'className' => 'TestPlugin.OtherHelper',
]);
$this->assertInstanceOf('TestPlugin\View\Helper\OtherHelperHelper', $result, 'Helper class is wrong.');
$this->assertInstanceOf(
'TestPlugin\View\Helper\OtherHelperHelper',
$this->Helpers->get('thing.helper'),
'Class is wrong'
);
$this->assertTrue($this->Helpers->has('thing.helper'));
$this->assertFalse($this->Helpers->has('thing'));
$this->assertFalse($this->Helpers->has('helper'));
$this->Helpers->unload('thing.helper');
$this->assertFalse($this->Helpers->has('thing.helper'), 'Should be gone now.');
}
/**
* Test reset.
*

0 comments on commit 94635f0

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