Skip to content
Permalink
Browse files

Removing deprecated options from object()

Tests updated.
  • Loading branch information...
markstory committed Jul 11, 2009
1 parent 50c6244 commit 69de1291e11374fbd2c9261bf7206e1bce3e290b
Showing with 6 additions and 19 deletions.
  1. +5 −18 cake/libs/view/helpers/js.php
  2. +1 −1 cake/tests/cases/libs/view/helpers/js.test.php
@@ -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.
@@ -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);
@@ -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)) {
@@ -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;
}
@@ -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;
}
/**
@@ -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;

0 comments on commit 69de129

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