Skip to content

Commit 08f0c7c

Browse files
committed
Fixing method dispatching errors in JsHelper with regards to Object::object, and PHP4 workarounds.
1 parent a7e300a commit 08f0c7c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

cake/libs/view/helpers/js.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function __construct($settings = array()) {
115115
* @param string $method Method to be called
116116
* @param array $params Parameters for the method being called.
117117
* @access public
118-
* @return mixed
118+
* @return mixed Depends on the return of the dispatched method, or it could be an instance of the EngineHelper
119119
**/
120120
function call__($method, $params) {
121121
if (isset($this->{$this->__engineName}) && method_exists($this->{$this->__engineName}, $method)) {
@@ -150,6 +150,20 @@ function call__($method, $params) {
150150
trigger_error(sprintf(__('JsHelper:: Missing Method %s is undefined', true), $method), E_USER_WARNING);
151151
}
152152

153+
/**
154+
* Workaround for Object::Object() existing. Since Object::object exists, it does not
155+
* fall into call__ and is not passed onto the engine helper. See JsBaseEngineHelper::object() for
156+
* more information on this method.
157+
*
158+
* @param mixed $data Data to convert into JSON
159+
* @param array $options Options to use for encoding JSON. See JsBaseEngineHelper::object() for more details.
160+
* @return string encoded JSON
161+
* @deprecated Remove when support for PHP4 and Object::object are removed.
162+
**/
163+
function object($data = array(), $options = array()) {
164+
return $this->{$this->__engineName}->object($data, $options);
165+
}
166+
153167
/**
154168
* Writes all Javascript generated so far to a code block or
155169
* caches them to a file and returns a linked script.

cake/tests/cases/libs/view/helpers/js.test.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,17 @@ function testSubmitWithMock() {
415415
);
416416
$this->assertTags($result, $expected);
417417
}
418+
419+
/**
420+
* Test that Object::Object() is not breaking json output in JsHelper
421+
*
422+
* @return void
423+
**/
424+
function testObjectPassThrough() {
425+
$result = $this->Js->object(array('one' => 'first', 'two' => 'second'));
426+
$expected = '{"one":"first","two":"second"}';
427+
$this->assertEqual($result, $expected);
428+
}
418429
}
419430

420431

0 commit comments

Comments
 (0)