Browse Source

Moving normalizeList() (basics) to Set::normalize()

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4307 3807eeeb-6ff5-0310-8944-8be069107fe0
nate 19 years ago
parent
commit
06f83ea86d
4 changed files with 52 additions and 5 deletions
  1. 1 0
      cake/basics.php
  2. 2 2
      cake/libs/model/model.php
  3. 4 3
      cake/libs/router.php
  4. 45 0
      cake/libs/set.php

+ 1 - 0
cake/basics.php

@@ -631,6 +631,7 @@
  * @return array
  */
 	function normalizeList($list, $assoc = true, $sep = ',', $trim = true) {
+		trigger_error('normalizeList Deprecated: use Set::normalize');
 		if (is_string($list)) {
 			$list = explode($sep, $list);
 			if ($trim) {

+ 2 - 2
cake/libs/model/model.php

@@ -389,7 +389,7 @@ class Model extends Overloadable {
 
 		if ($this->actsAs !== null && empty($this->behaviors)) {
 			$callbacks = array('setup', 'beforeFind', 'afterFind', 'beforeSave', 'afterSave', 'beforeDelete', 'afterDelete', 'afterError');
-			$this->actsAs = normalizeList($this->actsAs);
+			$this->actsAs = Set::normalize($this->actsAs);
 
 			foreach ($this->actsAs as $behavior => $config) {
 				$className = $behavior . 'Behavior';
@@ -669,7 +669,7 @@ class Model extends Overloadable {
 
 					$this->{$type}[$assocKey][$key] = $data;
 				} elseif ($key == 'with') {
-					$this->{$type}[$assocKey][$key] = normalizeList($this->{$type}[$assocKey][$key]);
+					$this->{$type}[$assocKey][$key] = Set::normalize($this->{$type}[$assocKey][$key]);
 				}
 
 				if ($key == 'foreignKey' && !isset($this->keyToTable[$this->{$type}[$assocKey][$key]])) {

+ 4 - 3
cake/libs/router.php

@@ -327,10 +327,11 @@ class Router extends Overloadable {
  */
 	function getParam($name = 'controller') {
 		$_this =& Router::getInstance();
-		if ($current) {
-			return $_this->__params[count($_this->__params) - 1];
+		$params = Router::getParams();
+		if (isset($params[$name])) {
+			return $params[$name];
 		}
-		return $_this->__params[0];
+		return null;
 	}
 /**
  * Gets path information

+ 45 - 0
cake/libs/set.php

@@ -296,6 +296,51 @@ class Set extends Object {
 		}
 		return $return;
 	}
+/**
+ * Normalizes a string or array list
+ *
+ * @param mixed $list
+ * @param boolean $assoc If true, $list will be converted to an associative array
+ * @param string $sep If $list is a string, it will be split into an array with $sep
+ * @param boolean $trim If true, separated strings will be trimmed
+ * @return array
+ */
+	function normalize($list, $assoc = true, $sep = ',', $trim = true) {
+		if (is_string($list)) {
+			$list = explode($sep, $list);
+			if ($trim) {
+				$list = array_map('trim', $list);
+			}
+			if ($assoc) {
+				return Set::normalize($list);
+			}
+		} elseif (is_array($list)) {
+			$keys = array_keys($list);
+			$count = count($keys);
+			$numeric = true;
+
+			if (!$assoc) {
+				for ($i = 0; $i < $count; $i++) {
+					if (!is_int($keys[$i])) {
+						$numeric = false;
+						break;
+					}
+				}
+			}
+			if (!$numeric || $assoc) {
+				$newList = array();
+				for ($i = 0; $i < $count; $i++) {
+					if (is_int($keys[$i])) {
+						$newList[$list[$keys[$i]]] = null;
+					} else {
+						$newList[$keys[$i]] = $list[$keys[$i]];
+					}
+				}
+				$list = $newList;
+			}
+		}
+		return $list;
+	}
 }
 
 ?>