mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-12 20:49:50 +00:00
Added Helper::$settings
This commit is contained in:
parent
1de8ed18de
commit
4a6ebaa07b
2 changed files with 39 additions and 1 deletions
|
@ -158,10 +158,20 @@ class HelperTestPostsTag extends Model {
|
|||
|
||||
class TestHelper extends Helper {
|
||||
|
||||
/**
|
||||
* Settings for this helper.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $settings = array(
|
||||
'key1' => 'val1',
|
||||
'key2' => array('key2.1' => 'val2.1', 'key2.2' => 'val2.2')
|
||||
);
|
||||
|
||||
/**
|
||||
* Helpers for this helper.
|
||||
*
|
||||
* @var string
|
||||
* @var array
|
||||
*/
|
||||
public $helpers = array('Html', 'TestPlugin.OtherHelper');
|
||||
|
||||
|
@ -264,6 +274,24 @@ class HelperTest extends CakeTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test settings merging
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSettingsMerging() {
|
||||
$Helper = new TestHelper($this->View, array(
|
||||
'key3' => 'val3',
|
||||
'key2' => array('key2.2' => 'newval')
|
||||
));
|
||||
$expected = array(
|
||||
'key1' => 'val1',
|
||||
'key2' => array('key2.1' => 'val2.1', 'key2.2' => 'newval'),
|
||||
'key3' => 'val3'
|
||||
);
|
||||
$this->assertEquals($expected, $Helper->settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setting an entity and retrieving the entity, model and field.
|
||||
*
|
||||
|
|
|
@ -24,6 +24,13 @@ App::uses('Hash', 'Utility');
|
|||
*/
|
||||
class Helper extends Object {
|
||||
|
||||
/**
|
||||
* Settings for this helper.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $settings = array();
|
||||
|
||||
/**
|
||||
* List of helpers used by this helper
|
||||
*
|
||||
|
@ -164,6 +171,9 @@ class Helper extends Object {
|
|||
public function __construct(View $View, $settings = array()) {
|
||||
$this->_View = $View;
|
||||
$this->request = $View->request;
|
||||
if ($settings) {
|
||||
$this->settings = Hash::merge($this->settings, $settings);
|
||||
}
|
||||
if (!empty($this->helpers)) {
|
||||
$this->_helperMap = ObjectCollection::normalizeObjectArray($this->helpers);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue