Skip to content

Commit

Permalink
Update to use Hash.
Browse files Browse the repository at this point in the history
Update CakeSession & Configure to use Hash.
  • Loading branch information
markstory committed Mar 27, 2012
1 parent 8becc4c commit 29048b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
30 changes: 5 additions & 25 deletions lib/Cake/Core/Configure.php
Expand Up @@ -13,7 +13,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('Set', 'Utility');
App::uses('Hash', 'Utility');
App::uses('ConfigReaderInterface', 'Configure');

/**
Expand Down Expand Up @@ -127,12 +127,7 @@ public static function write($config, $value = null) {
}

foreach ($config as $name => $value) {
$pointer = &self::$_values;
foreach (explode('.', $name) as $key) {
$pointer = &$pointer[$key];
}
$pointer = $value;
unset($pointer);
self::$_values = Hash::insert(self::$_values, $name, $value);
}

if (isset($config['debug']) && function_exists('ini_set')) {
Expand Down Expand Up @@ -163,18 +158,7 @@ public static function read($var = null) {
if ($var === null) {
return self::$_values;
}
if (isset(self::$_values[$var])) {
return self::$_values[$var];
}
$pointer = &self::$_values;
foreach (explode('.', $var) as $key) {
if (isset($pointer[$key])) {
$pointer = &$pointer[$key];
} else {
return null;
}
}
return $pointer;
return Hash::get(self::$_values, $var);
}

/**
Expand All @@ -193,11 +177,7 @@ public static function read($var = null) {
public static function delete($var = null) {
$keys = explode('.', $var);
$last = array_pop($keys);
$pointer = &self::$_values;
foreach ($keys as $key) {
$pointer = &$pointer[$key];
}
unset($pointer[$last]);
self::$_values = Hash::remove(self::$_values, $var);
}

/**
Expand Down Expand Up @@ -286,7 +266,7 @@ public static function load($key, $config = 'default', $merge = true) {
$keys = array_keys($values);
foreach ($keys as $key) {
if (($c = self::read($key)) && is_array($values[$key]) && is_array($c)) {
$values[$key] = Set::merge($c, $values[$key]);
$values[$key] = Hash::merge($c, $values[$key]);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/Cake/Model/Datasource/CakeSession.php
Expand Up @@ -22,7 +22,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('Set', 'Utility');
App::uses('Hash', 'Utility');
App::uses('Security', 'Utility');

/**
Expand Down Expand Up @@ -216,7 +216,7 @@ public static function check($name = null) {
if (empty($name)) {
return false;
}
$result = Set::classicExtract($_SESSION, $name);
$result = Hash::get($_SESSION, $name);
return isset($result);
}

Expand Down Expand Up @@ -364,9 +364,9 @@ public static function read($name = null) {
if (empty($name)) {
return false;
}
$result = Set::classicExtract($_SESSION, $name);
$result = Hash::get($_SESSION, $name);

if (!is_null($result)) {
if (isset($result)) {
return $result;
}
self::_setError(2, "$name doesn't exist");
Expand Down Expand Up @@ -405,8 +405,8 @@ public static function write($name, $value = null) {
$write = array($name => $value);
}
foreach ($write as $key => $val) {
self::_overwrite($_SESSION, Set::insert($_SESSION, $key, $val));
if (Set::classicExtract($_SESSION, $key) !== $val) {
self::_overwrite($_SESSION, Hash::insert($_SESSION, $key, $val));
if (Hash::get($_SESSION, $key) !== $val) {
return false;
}
}
Expand Down

0 comments on commit 29048b3

Please sign in to comment.