mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fixing method dispatching errors in JsHelper with regards to Object::object, and PHP4 workarounds.
This commit is contained in:
parent
a7e300a7c1
commit
08f0c7c157
2 changed files with 26 additions and 1 deletions
|
@ -115,7 +115,7 @@ class JsHelper extends AppHelper {
|
|||
* @param string $method Method to be called
|
||||
* @param array $params Parameters for the method being called.
|
||||
* @access public
|
||||
* @return mixed
|
||||
* @return mixed Depends on the return of the dispatched method, or it could be an instance of the EngineHelper
|
||||
**/
|
||||
function call__($method, $params) {
|
||||
if (isset($this->{$this->__engineName}) && method_exists($this->{$this->__engineName}, $method)) {
|
||||
|
@ -150,6 +150,20 @@ class JsHelper extends AppHelper {
|
|||
trigger_error(sprintf(__('JsHelper:: Missing Method %s is undefined', true), $method), E_USER_WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround for Object::Object() existing. Since Object::object exists, it does not
|
||||
* fall into call__ and is not passed onto the engine helper. See JsBaseEngineHelper::object() for
|
||||
* more information on this method.
|
||||
*
|
||||
* @param mixed $data Data to convert into JSON
|
||||
* @param array $options Options to use for encoding JSON. See JsBaseEngineHelper::object() for more details.
|
||||
* @return string encoded JSON
|
||||
* @deprecated Remove when support for PHP4 and Object::object are removed.
|
||||
**/
|
||||
function object($data = array(), $options = array()) {
|
||||
return $this->{$this->__engineName}->object($data, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes all Javascript generated so far to a code block or
|
||||
* caches them to a file and returns a linked script.
|
||||
|
|
|
@ -415,6 +415,17 @@ CODE;
|
|||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that Object::Object() is not breaking json output in JsHelper
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testObjectPassThrough() {
|
||||
$result = $this->Js->object(array('one' => 'first', 'two' => 'second'));
|
||||
$expected = '{"one":"first","two":"second"}';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue