Browse Source

Replace deprecated methods

euromark 12 years ago
parent
commit
f01cab6c35

+ 25 - 9
Controller/Component/CommonComponent.php

@@ -26,6 +26,8 @@ class CommonComponent extends Component {
 	/**
 	/**
 	 * For automatic startup
 	 * For automatic startup
 	 * for this helper the controller has to be passed as reference
 	 * for this helper the controller has to be passed as reference
+	 *
+	 * @return void
 	 */
 	 */
 	public function initialize(Controller $Controller) {
 	public function initialize(Controller $Controller) {
 		parent::initialize($Controller);
 		parent::initialize($Controller);
@@ -36,9 +38,13 @@ class CommonComponent extends Component {
 	/**
 	/**
 	 * For this helper the controller has to be passed as reference
 	 * For this helper the controller has to be passed as reference
 	 * for manual startup with $disableStartup = true (requires this to be called prior to any other method)
 	 * for manual startup with $disableStartup = true (requires this to be called prior to any other method)
+	 *
+	 * @return void
 	 */
 	 */
 	public function startup(Controller $Controller = null) {
 	public function startup(Controller $Controller = null) {
-		/** DATA PREPARATION **/
+		parent::startup($Controller);
+
+		// Data preparation
 		if (!empty($this->Controller->request->data) && !Configure::read('DataPreparation.notrim')) {
 		if (!empty($this->Controller->request->data) && !Configure::read('DataPreparation.notrim')) {
 			$this->Controller->request->data = $this->trimDeep($this->Controller->request->data);
 			$this->Controller->request->data = $this->trimDeep($this->Controller->request->data);
 		}
 		}
@@ -52,7 +58,7 @@ class CommonComponent extends Component {
 			$this->Controller->request->params['pass'] = $this->trimDeep($this->Controller->request->params['pass']);
 			$this->Controller->request->params['pass'] = $this->trimDeep($this->Controller->request->params['pass']);
 		}
 		}
 
 
-		/** Information Gathering **/
+		// Information gathering
 		if (!Configure::read('App.disableMobileDetection') && ($mobile = $this->Session->read('Session.mobile')) === null) {
 		if (!Configure::read('App.disableMobileDetection') && ($mobile = $this->Session->read('Session.mobile')) === null) {
 			App::uses('UserAgentLib', 'Tools.Lib');
 			App::uses('UserAgentLib', 'Tools.Lib');
 			$UserAgentLib = new UserAgentLib();
 			$UserAgentLib = new UserAgentLib();
@@ -60,7 +66,7 @@ class CommonComponent extends Component {
 			$this->Session->write('Session.mobile', $mobile);
 			$this->Session->write('Session.mobile', $mobile);
 		}
 		}
 
 
-		/** Layout **/
+		// Auto layout switch
 		if ($this->Controller->request->is('ajax')) {
 		if ($this->Controller->request->is('ajax')) {
 			$this->Controller->layout = 'ajax';
 			$this->Controller->layout = 'ajax';
 		}
 		}
@@ -70,10 +76,8 @@ class CommonComponent extends Component {
 	 * Called after the Controller::beforeRender(), after the view class is loaded, and before the
 	 * Called after the Controller::beforeRender(), after the view class is loaded, and before the
 	 * Controller::render()
 	 * Controller::render()
 	 *
 	 *
-	 * Created: 2010-10-10
 	 * @param object $Controller Controller with components to beforeRender
 	 * @param object $Controller Controller with components to beforeRender
 	 * @return void
 	 * @return void
-	 * @author deltachaos
 	 */
 	 */
 	public function beforeRender(Controller $Controller) {
 	public function beforeRender(Controller $Controller) {
 		if ($this->RequestHandler->isAjax()) {
 		if ($this->RequestHandler->isAjax()) {
@@ -140,8 +144,8 @@ class CommonComponent extends Component {
 	/**
 	/**
 	 * Updates FlashMessage SessionContent (to enable unlimited messages of one case)
 	 * Updates FlashMessage SessionContent (to enable unlimited messages of one case)
 	 *
 	 *
-	 * @param STRING messagestring
-	 * @param STRING class ['error', 'warning', 'success', 'info']
+	 * @param string messagestring
+	 * @param string class ['error', 'warning', 'success', 'info']
 	 * @return void
 	 * @return void
 	 */
 	 */
 	public function flashMessage($messagestring, $class = null) {
 	public function flashMessage($messagestring, $class = null) {
@@ -167,8 +171,8 @@ class CommonComponent extends Component {
 	 * FlashMessages that are not saved (only for current view)
 	 * FlashMessages that are not saved (only for current view)
 	 * will be merged into the session flash ones prior to output
 	 * will be merged into the session flash ones prior to output
 	 *
 	 *
-	 * @param STRING messagestring
-	 * @param STRING class ['error', 'warning', 'success', 'info']
+	 * @param string messagestring
+	 * @param string class ['error', 'warning', 'success', 'info']
 	 * @return void
 	 * @return void
 	 */
 	 */
 	public static function transientFlashMessage($messagestring, $class = null) {
 	public static function transientFlashMessage($messagestring, $class = null) {
@@ -1189,6 +1193,9 @@ class CommonComponent extends Component {
 	 * Returns searchArray (options['wildcard'] TRUE/FALSE)
 	 * Returns searchArray (options['wildcard'] TRUE/FALSE)
 	 * TODO: move to SearchLib etc
 	 * TODO: move to SearchLib etc
 	 *
 	 *
+	 * @param string $keyword
+	 * @param string $searchphrase
+	 * @param array $options
 	 * @return array Cleaned array('keyword'=>'searchphrase') or array('keyword LIKE'=>'searchphrase')
 	 * @return array Cleaned array('keyword'=>'searchphrase') or array('keyword LIKE'=>'searchphrase')
 	 */
 	 */
 	public function getSearchItem($keyword = null, $searchphrase = null, $options = array()) {
 	public function getSearchItem($keyword = null, $searchphrase = null, $options = array()) {
@@ -1209,6 +1216,7 @@ class CommonComponent extends Component {
 
 
 	/**
 	/**
 	 * Returns auto-generated password
 	 * Returns auto-generated password
+	 *
 	 * @param string $type: user, ...
 	 * @param string $type: user, ...
 	 * @param integer $length (if no type is submitted)
 	 * @param integer $length (if no type is submitted)
 	 * @return pwd on success, empty string otherwise
 	 * @return pwd on success, empty string otherwise
@@ -1229,6 +1237,8 @@ class CommonComponent extends Component {
 	/**
 	/**
 	 * TODO: move to Lib
 	 * TODO: move to Lib
 	 * Checks if string contains @ sign
 	 * Checks if string contains @ sign
+	 *
+	 * @param string
 	 * @return true if at least one @ is in the string, false otherwise
 	 * @return true if at least one @ is in the string, false otherwise
 	 */
 	 */
 	public static function containsAtSign($string = null) {
 	public static function containsAtSign($string = null) {
@@ -1280,6 +1290,7 @@ class CommonComponent extends Component {
 	 * Get the Corresponding Message to an HTTP Error Code
 	 * Get the Corresponding Message to an HTTP Error Code
 	 *
 	 *
 	 * @param integer $code: 100...505
 	 * @param integer $code: 100...505
+	 * @param boolean $autoTranslate
 	 * @return array codes if code is NULL, otherwise string $code (empty string on failure)
 	 * @return array codes if code is NULL, otherwise string $code (empty string on failure)
 	 */
 	 */
 	public function responseCodes($code = null, $autoTranslate = false) {
 	public function responseCodes($code = null, $autoTranslate = false) {
@@ -1351,7 +1362,9 @@ class CommonComponent extends Component {
 
 
 	/**
 	/**
 	 * Get the Corresponding Message to an HTTP Error Code
 	 * Get the Corresponding Message to an HTTP Error Code
+	 *
 	 * @param integer $code: 4xx...5xx
 	 * @param integer $code: 4xx...5xx
+	 * @return string
 	 */
 	 */
 	public function smtpResponseCodes($code = null, $autoTranslate = false) {
 	public function smtpResponseCodes($code = null, $autoTranslate = false) {
 		# 550 5.1.1 User is unknown
 		# 550 5.1.1 User is unknown
@@ -1376,6 +1389,9 @@ class CommonComponent extends Component {
 	 * isnt this covered by core Set stuff anyway?)
 	 * isnt this covered by core Set stuff anyway?)
 	 *
 	 *
 	 * tryout: sorting multidim. array by field [0]..[x]; z.b. $array['Model']['name'] DESC etc.
 	 * tryout: sorting multidim. array by field [0]..[x]; z.b. $array['Model']['name'] DESC etc.
+	 *
+	 * @return array()
+	 * @deprecated
 	 */
 	 */
 	public function sortArray($array, $obj, $direction = null) {
 	public function sortArray($array, $obj, $direction = null) {
 		if (empty($direction) || empty($array) || empty($obj)) {
 		if (empty($direction) || empty($array) || empty($obj)) {

+ 2 - 2
Model/Behavior/LogableBehavior.php

@@ -46,7 +46,7 @@ if (!defined('CLASS_USER')) {
  *
  *
  * - In AppController (or single controller if only needed once) add these lines to beforeFilter :
  * - In AppController (or single controller if only needed once) add these lines to beforeFilter :
  *
  *
- * 	if (count($this->uses) && $this->{$this->modelClass}->Behaviors->attached('Logable')) {
+ * 	if (count($this->uses) && $this->{$this->modelClass}->Behaviors->loaded('Logable')) {
  *			$this->{$this->modelClass}->setUserData($this->activeUser);
  *			$this->{$this->modelClass}->setUserData($this->activeUser);
  *		}
  *		}
  *
  *
@@ -280,7 +280,7 @@ class LogableBehavior extends ModelBehavior {
 	 * Use this to supply a model with the data of the logged in User.
 	 * Use this to supply a model with the data of the logged in User.
 	 * Intended to be called in AppController::beforeFilter like this :
 	 * Intended to be called in AppController::beforeFilter like this :
 	 *
 	 *
-	 * 	if ($this->{$this->modelClass}->Behaviors->attached('Logable')) {
+	 * 	if ($this->{$this->modelClass}->Behaviors->loaded('Logable')) {
 	 *			$this->{$this->modelClass}->setUserData($activeUser);/
 	 *			$this->{$this->modelClass}->setUserData($activeUser);/
 	 *		}
 	 *		}
 	 *
 	 *

+ 1 - 1
Model/Behavior/SluggedBehavior.php

@@ -99,7 +99,7 @@ class SluggedBehavior extends ModelBehavior {
 		$this->settings[$Model->alias] = Set::merge($this->_defaultSettings, $config);
 		$this->settings[$Model->alias] = Set::merge($this->_defaultSettings, $config);
 		extract($this->settings[$Model->alias]);
 		extract($this->settings[$Model->alias]);
 		$label = $this->settings[$Model->alias]['label'] = (array)$label;
 		$label = $this->settings[$Model->alias]['label'] = (array)$label;
-		if ($Model->Behaviors->attached('Translate')) {
+		if ($Model->Behaviors->loaded('Translate')) {
 			$notices = false;
 			$notices = false;
 		}
 		}
 		if ($notices) {
 		if ($notices) {

+ 35 - 3
Test/Case/Controller/Component/CommonComponentTest.php

@@ -2,7 +2,7 @@
 
 
 App::uses('CommonComponent', 'Tools.Controller/Component');
 App::uses('CommonComponent', 'Tools.Controller/Component');
 App::uses('Component', 'Controller');
 App::uses('Component', 'Controller');
-App::uses('AppController', 'Controller');
+App::uses('Controller', 'Controller');
 App::uses('AppModel', 'Model');
 App::uses('AppModel', 'Model');
 
 
 /**
 /**
@@ -270,6 +270,37 @@ class CommonComponentTest extends CakeTestCase {
 		$this->assertEquals('Contributor', $res);
 		$this->assertEquals('Contributor', $res);
 	}
 	}
 
 
+	/**
+	 * CommonComponentTest::testDataTrim()
+	 *
+	 * @return void
+	 */
+	public function testDataTrim() {
+		$array = array('Some' => array('Deep' => array('array' => '  bla  ')));
+
+		$this->Controller = new CommonComponentTestController(new CakeRequest, new CakeResponse);
+		$this->Controller->request->data = $array;
+		$this->Controller->request->query = $array;
+		$this->Controller->constructClasses();
+		$this->Controller->startupProcess();
+
+		$expected = array('Some' => array('Deep' => array('array' => 'bla')));
+		$this->assertSame($expected, $this->Controller->request->data);
+		$this->assertSame($expected, $this->Controller->request->query);
+
+		// Overwrite
+		Configure::write('DataPreparation.notrim', true);
+
+		$this->Controller = new CommonComponentTestController(new CakeRequest, new CakeResponse);
+		$this->Controller->request->data = $array;
+		$this->Controller->request->query = $array;
+		$this->Controller->constructClasses();
+		$this->Controller->startupProcess();
+
+		$this->assertSame($array, $this->Controller->request->data);
+		$this->assertSame($array, $this->Controller->request->query);
+	}
+
 }
 }
 
 
 /*** additional helper classes ***/
 /*** additional helper classes ***/
@@ -286,9 +317,10 @@ class ToolsUser extends AppModel {
 
 
 }
 }
 
 
-class CommonComponentTestController extends AppController {
+// Use Controller instead of AppController to avoid conflicts
+class CommonComponentTestController extends Controller {
 
 
-	public $components = array('Tools.Common', 'Auth');
+	public $components = array('Session', 'Tools.Common', 'Auth');
 
 
 	public $failed = false;
 	public $failed = false;
 
 

+ 1 - 1
Test/Case/Model/Behavior/ResetBehaviorTest.php

@@ -18,7 +18,7 @@ class ResetBehaviorTest extends MyCakeTestCase {
 		$this->ResetBehavior = new ResetBehavior();
 		$this->ResetBehavior = new ResetBehavior();
 
 
 		$this->Model = ClassRegistry::init('MyComment');
 		$this->Model = ClassRegistry::init('MyComment');
-		$this->Model->Behaviors->attach('Tools.Reset');
+		$this->Model->Behaviors->load('Tools.Reset');
 	}
 	}
 
 
 	public function testObject() {
 	public function testObject() {

+ 1 - 1
Test/Case/View/Helper/TreeHelperTest.php

@@ -29,7 +29,7 @@ class TreeHelperTest extends MyCakeTestCase {
 
 
 		$this->Tree = new TreeHelper(new View(null));
 		$this->Tree = new TreeHelper(new View(null));
 		$this->Model = ClassRegistry::init('AfterTree');
 		$this->Model = ClassRegistry::init('AfterTree');
-		$this->Model->Behaviors->attach('Tree');
+		$this->Model->Behaviors->load('Tree');
 
 
 		$this->Model->truncate();
 		$this->Model->truncate();