浏览代码

Set class is part of Shim plugin, also add a few fixes when migration a 2.x app.

Mark Scherer 10 年之前
父节点
当前提交
ffad1c6639
共有 3 个文件被更改,包括 27 次插入42 次删除
  1. 17 5
      src/Controller/Component/CommonComponent.php
  2. 0 35
      src/Utility/Set.php
  3. 10 2
      src/Utility/Time.php

+ 17 - 5
src/Controller/Component/CommonComponent.php

@@ -1,6 +1,7 @@
 <?php
 namespace Tools\Controller\Component;
 
+use Cake\Utility\Inflector;
 use Shim\Controller\Component\Component;
 use Cake\Core\Configure;
 use Cake\Event\Event;
@@ -41,12 +42,11 @@ class CommonComponent extends Component {
 	 * @return array Actions
 	 */
 	public function listActions() {
-		$class = Inflector::camelize($this->Controller->name) . 'Controller';
-		$parentClassMethods = get_class_methods(get_parent_class($class));
-		$subClassMethods = get_class_methods($class);
+		$parentClassMethods = get_class_methods(get_parent_class($this->Controller));
+		$subClassMethods = get_class_methods($this->Controller);
 		$classMethods = array_diff($subClassMethods, $parentClassMethods);
-		foreach ($classMethods as $key => $value) {
-			if (substr($value, 0, 1) === '_') {
+		foreach ($classMethods as $key => $classMethod) {
+			if (substr($classMethod, 0, 1) === '_') {
 				unset($classMethods[$key]);
 			}
 		}
@@ -89,6 +89,18 @@ class CommonComponent extends Component {
 	}
 
 	/**
+	 * Add helper just in time (inside actions - only when needed)
+	 * aware of plugins
+	 *
+	 * @deprecated In 3.x, but kept for easier migration for now. Will be removed in the future.
+	 * @param mixed $helpers (single string or multiple array)
+	 * @return void
+	 */
+	public function loadHelper($helpers = []) {
+		$this->Controller->helpers = array_merge($this->Controller->helpers, (array)$helpers);
+	}
+
+	/**
 	 * Used to get the value of a passed param.
 	 *
 	 * @param mixed $var

+ 0 - 35
src/Utility/Set.php

@@ -1,35 +0,0 @@
-<?php
-namespace Tools\Utility;
-
-/**
- * BC wrapper for 2.x methods until they can be rewritten.
- */
-class Set {
-
-	/**
-	 * Pushes the differences in $array2 onto the end of $array
-	 *
-	 * @param array $array Original array
-	 * @param array $array2 Differences to push
-	 * @return array Combined array
-	 * @link http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::pushDiff
-	 */
-	public static function pushDiff($array, $array2) {
-		if (empty($array) && !empty($array2)) {
-			return $array2;
-		}
-		if (!empty($array) && !empty($array2)) {
-			foreach ($array2 as $key => $value) {
-				if (!array_key_exists($key, $array)) {
-					$array[$key] = $value;
-				} else {
-					if (is_array($value)) {
-						$array[$key] = Set::pushDiff($array[$key], $array2[$key]);
-					}
-				}
-			}
-		}
-		return $array;
-	}
-
-}

+ 10 - 2
src/Utility/Time.php

@@ -146,8 +146,16 @@ class Time extends CakeTime {
 			$end = date(FORMAT_DB_DATE, $end);
 		}
 
-		$endDate = new \DateTime($end);
-		$startDate = new \DateTime($start);
+		$startDate = $start;
+		if (!is_object($start)) {
+			$startDate = new \DateTime($start);
+		}
+
+		$endDate = $end;
+		if (!is_object($end)) {
+			$endDate = new \DateTime($end);
+		}
+
 		if ($startDate > $endDate) {
 			return -1;
 		}