Skip to content

Commit

Permalink
Removing deprecated options from object()
Browse files Browse the repository at this point in the history
Tests updated.
  • Loading branch information
markstory committed Jul 11, 2009
1 parent 50c6244 commit 69de129
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
23 changes: 5 additions & 18 deletions cake/libs/view/helpers/js.php
Expand Up @@ -299,9 +299,6 @@ function prompt($message, $default = '') {
*
* - 'prefix' - String prepended to the returned data.
* - 'postfix' - String appended to the returned data.
* - 'stringKeys' - A list of array keys to be treated as a string
* - 'quoteKeys' - If false treats $options['stringKeys'] as a list of keys **not** to be quoted.
* - 'q' - Type of quote to use.
*
* @param array $data Data to be converted.
* @param array $options Set of options, see above.
Expand All @@ -310,8 +307,7 @@ function prompt($message, $default = '') {
**/
function object($data = array(), $options = array()) {
$defaultOptions = array(
'block' => false, 'prefix' => '', 'postfix' => '',
'stringKeys' => array(), 'quoteKeys' => true, 'q' => '"'
'prefix' => '', 'postfix' => '',
);
$options = array_merge($defaultOptions, $options);

Expand All @@ -322,7 +318,7 @@ function object($data = array(), $options = array()) {
$out = $keys = array();
$numeric = true;

if ($this->useNative) {
if ($this->useNative && function_exists('json_encode')) {
$rt = json_encode($data);
} else {
if (is_null($data)) {
Expand All @@ -341,17 +337,12 @@ function object($data = array(), $options = array()) {

foreach ($data as $key => $val) {
if (is_array($val) || is_object($val)) {
$val = $this->object($val, array_merge($options, array('block' => false)));
$val = $this->object($val, $options);
} else {
$quoteStrings = (
!count($options['stringKeys']) ||
($options['quoteKeys'] && in_array($key, $options['stringKeys'], true)) ||
(!$options['quoteKeys'] && !in_array($key, $options['stringKeys'], true))
);
$val = $this->value($val, $quoteStrings);
$val = $this->value($val);
}
if (!$numeric) {
$val = $options['q'] . $this->value($key, false) . $options['q'] . ':' . $val;
$val = '"' . $this->value($key, false) . '":' . $val;
}
$out[] = $val;
}
Expand All @@ -363,10 +354,6 @@ function object($data = array(), $options = array()) {
}
}
$rt = $options['prefix'] . $rt . $options['postfix'];

if ($options['block']) {
$rt = $this->codeBlock($rt, array_diff_key($options, $defaultOptions));
}
return $rt;
}
/**
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/libs/view/helpers/js.test.php
Expand Up @@ -392,7 +392,7 @@ function testObject() {
*
* @return void
**/
function XXtestObjectAgainstJsonEncode() {
function testObjectAgainstJsonEncode() {
$skip = $this->skipIf(!function_exists('json_encode'), 'json_encode() not found, comparison tests skipped. %s');
if ($skip) {
return;
Expand Down

0 comments on commit 69de129

Please sign in to comment.