Browse Source

Refactoring of config

euromark 11 years ago
parent
commit
d09ff353b6

+ 5 - 5
Controller/Component/AjaxComponent.php

@@ -22,7 +22,7 @@ class AjaxComponent extends Component {
 
 
 	public $respondAsAjax = false;
 	public $respondAsAjax = false;
 
 
-	protected $_defaults = array(
+	protected $_defaultConfig = array(
 		'autoDetect' => true,
 		'autoDetect' => true,
 		'resolveRedirect' => true,
 		'resolveRedirect' => true,
 		'flashKey' => 'Message.flash' // Use "messages" for Tools plugin, set to false to disable
 		'flashKey' => 'Message.flash' // Use "messages" for Tools plugin, set to false to disable
@@ -32,11 +32,11 @@ class AjaxComponent extends Component {
 	 * Constructor.
 	 * Constructor.
 	 *
 	 *
 	 * @param ComponentCollection $collection
 	 * @param ComponentCollection $collection
-	 * @param array $settings
+	 * @param array $config
 	 */
 	 */
-	public function __construct(ComponentCollection $collection, $settings = array()) {
-		$settings = array_merge($this->_defaults, (array)Configure::read('Ajax'), $settings);
-		parent::__construct($collection, $settings);
+	public function __construct(ComponentCollection $collection, $config = array()) {
+		$config = array_merge($this->_defaultConfig, (array)Configure::read('Ajax'), $config);
+		parent::__construct($collection, $config);
 	}
 	}
 
 
 	public function initialize(Controller $Controller) {
 	public function initialize(Controller $Controller) {

+ 11 - 5
Controller/Component/Auth/TinyAuthorize.php

@@ -36,7 +36,7 @@ class TinyAuthorize extends BaseAuthorize {
 
 
 	protected $_acl = null;
 	protected $_acl = null;
 
 
-	protected $_defaults = array(
+	protected $_defaultConfig = array(
 		'superadminRole' => null, // quick way to allow access to every action
 		'superadminRole' => null, // quick way to allow access to every action
 		'allowUser' => false, // quick way to allow user access to non prefixed urls
 		'allowUser' => false, // quick way to allow user access to non prefixed urls
 		'allowAdmin' => false, // quick way to allow admin access to admin prefixed urls
 		'allowAdmin' => false, // quick way to allow admin access to admin prefixed urls
@@ -49,11 +49,17 @@ class TinyAuthorize extends BaseAuthorize {
 		'aclKey' => 'role_id', // only for single roles per user (BT)
 		'aclKey' => 'role_id', // only for single roles per user (BT)
 	);
 	);
 
 
-	public function __construct(ComponentCollection $Collection, $settings = array()) {
-		$settings = array_merge($this->_defaults, $settings);
-		parent::__construct($Collection, $settings);
+	/**
+	 * TinyAuthorize::__construct()
+	 *
+	 * @param ComponentCollection $Collection
+	 * @param array $config
+	 */
+	public function __construct(ComponentCollection $Collection, $config = array()) {
+		$config = array_merge($this->_defaultConfig, $config);
+		parent::__construct($Collection, $config);
 
 
-		if (Cache::config($settings['cache']) === false) {
+		if (Cache::config($config['cache']) === false) {
 			throw new CakeException(__d('dev', 'TinyAuth could not find `%s` cache - expects at least a `default` cache', $settings['cache']));
 			throw new CakeException(__d('dev', 'TinyAuth could not find `%s` cache - expects at least a `default` cache', $settings['cache']));
 		}
 		}
 	}
 	}

+ 6 - 6
Controller/Component/AuthExtComponent.php

@@ -36,7 +36,7 @@ class AuthExtComponent extends AuthComponent {
 
 
 	public $loginError = null;
 	public $loginError = null;
 
 
-	protected $_defaults = array(
+	protected $_defaultConfig = array(
 		'multi' => null, # null=auto - yes/no multiple roles (HABTM table between users and roles)
 		'multi' => null, # null=auto - yes/no multiple roles (HABTM table between users and roles)
 		'parentModelAlias' => USER_ROLE_KEY,
 		'parentModelAlias' => USER_ROLE_KEY,
 		'userModel' => CLASS_USER //TODO: allow plugin syntax
 		'userModel' => CLASS_USER //TODO: allow plugin syntax
@@ -45,13 +45,13 @@ class AuthExtComponent extends AuthComponent {
 	/**
 	/**
 	 * Merge in Configure::read('Auth') settings
 	 * Merge in Configure::read('Auth') settings
 	 *
 	 *
-	 * @param mixed $Collection
-	 * @param mixed $settings
+	 * @param ComponentCollection $Collection
+	 * @param array $config
 	 */
 	 */
-	public function __construct(ComponentCollection $Collection, $settings = array()) {
-		$settings = array_merge($this->_defaults, (array)Configure::read('Auth'), $settings);
+	public function __construct(ComponentCollection $Collection, $config = array()) {
+		$config = array_merge($this->_defaultConfig, (array)Configure::read('Auth'), $config);
 
 
-		parent::__construct($Collection, $settings);
+		parent::__construct($Collection, $config);
 	}
 	}
 
 
 	public function initialize(Controller $Controller) {
 	public function initialize(Controller $Controller) {

+ 9 - 10
Controller/Component/AutoLoginComponent.php

@@ -43,7 +43,7 @@ class AutoLoginComponent extends Component {
 	 *
 	 *
 	 * @var array
 	 * @var array
 	 */
 	 */
-	protected $_defaults = array(
+	protected $_defaultConfig = array(
 		'active' => true,
 		'active' => true,
 		'model' => 'User',
 		'model' => 'User',
 		'username' => 'username',
 		'username' => 'username',
@@ -70,16 +70,15 @@ class AutoLoginComponent extends Component {
 	 * Initialize settings and debug.
 	 * Initialize settings and debug.
 	 *
 	 *
 	 * @param ComponentCollection $collection
 	 * @param ComponentCollection $collection
-	 * @param array $settings
+	 * @param array $config
 	 */
 	 */
-	public function __construct(ComponentCollection $collection, $settings = array()) {
-		$defaultSettings = array_merge($this->_defaults, (array)Configure::read('AutoLogin'));
-		$settings = array_merge($defaultSettings, $settings);
-
-		// make sure an upgrade does reset all cookies stored to avoid conflicts
-		$settings['cookieName'] = $settings['cookieName'] . str_replace('.', '', $this->version);
-		$this->settings = $settings;
-		parent::__construct($collection, $settings);
+	public function __construct(ComponentCollection $collection, $config = array()) {
+		$defaultConfig = (array)Configure::read('AutoLogin') + $this->_defaultConfig;
+		$config += $defaultConfig;
+
+		// Make sure an upgrade does reset all cookies stored to avoid conflicts
+		$config['cookieName'] = $config['cookieName'] . str_replace('.', '', $this->version);
+		parent::__construct($collection, $config);
 	}
 	}
 
 
 	/**
 	/**

+ 5 - 5
Controller/Component/MobileComponent.php

@@ -50,7 +50,7 @@ class MobileComponent extends Component {
 	 *
 	 *
 	 * @param array
 	 * @param array
 	 */
 	 */
-	protected $_defaults = array(
+	protected $_defaultConfig = array(
 		'on' => 'startup', // initialize (prior to controller's beforeRender) or startup
 		'on' => 'startup', // initialize (prior to controller's beforeRender) or startup
 		'engine' => 'vendor', // cake internal (deprecated), tools (deprecated) or vendor
 		'engine' => 'vendor', // cake internal (deprecated), tools (deprecated) or vendor
 		'themed' => false, // If false uses subfolders instead of themes: /View/.../mobile/
 		'themed' => false, // If false uses subfolders instead of themes: /View/.../mobile/
@@ -62,11 +62,11 @@ class MobileComponent extends Component {
 	 * MobileComponent::__construct()
 	 * MobileComponent::__construct()
 	 *
 	 *
 	 * @param ComponentCollection $collection
 	 * @param ComponentCollection $collection
-	 * @param array $settings
+	 * @param array $config
 	 */
 	 */
-	public function __construct(ComponentCollection $collection, $settings = array()) {
-		$settings = array_merge($this->_defaults, (array)Configure::read('Mobile'), $settings);
-		parent::__construct($collection, $settings);
+	public function __construct(ComponentCollection $collection, $config = array()) {
+		$config = array_merge($this->_defaultConfig, (array)Configure::read('Mobile'), $config);
+		parent::__construct($collection, $config);
 	}
 	}
 
 
 	/**
 	/**

+ 2 - 0
Test/Case/View/Helper/FormatHelperTest.php

@@ -10,6 +10,8 @@ App::uses('View', 'View');
  */
  */
 class FormatHelperTest extends MyCakeTestCase {
 class FormatHelperTest extends MyCakeTestCase {
 
 
+	public $fixtures = array('core.cake_session');
+
 	public $Format;
 	public $Format;
 
 
 	public function setUp() {
 	public function setUp() {

+ 16 - 33
View/Elements/svn_revision.ctp

@@ -1,40 +1,23 @@
 <?php
 <?php
-if (!isset($svnFile)) {
-	$svnFile = APP . '.svn/entries';
+if (!isset($svnDir)) {
+	$svnDir = APP;
 }
 }
-
-if (file_exists($svnFile) && ($svn = File($svnFile))) {
-	//die(returns($svn));
-	$svnrev = $svn[3];
-	$lastChange = trim($svn[9]);
-	$lastUser = trim($svn[11]);
-
-	if (isset($version) && $version === false || Configure::read('debug') > 0) {
-		# display the revision right away
-		$versionText = 'Rev. ' . $svnrev . ' (' . h($lastUser) . ' - ' . $this->Datetime->niceDate($lastChange, FORMAT_NICE_YMDHM) . ')';
-	} else {
-		# in productive mode we want to display a harmless looking version number
-		if (strlen($svnrev) > 3) {
-			$v = substr($svnrev, 0, strlen($svnrev) - 3) . '.' . substr($svnrev, -3, 1) . '.' . substr($svnrev, -2, 1);
-		} elseif (strlen($svnrev) === 3) {
-			$v = '0.' . substr($svnrev, -3, 1) . '.' . substr($svnrev, -2, 1);
-		} else {
-			$v = '0.0.' . substr($svnrev, -2, 1);
+$command = 'cd ' . realpath($svnDir) . ' && svn info';
+$svnrev = null;
+exec($command, $out);
+if ($out) {
+	foreach ($out as $row) {
+		if (strpos($row, 'Revision:') === 0) {
+			$svnrev = (int)substr($row, 9);
 		}
 		}
-		$versionText = 'Version ' . $v;
 	}
 	}
-
-?>
-
-<div class="svn-revision">
-<?php
-	echo $versionText;
-?>
-</div>
-
-<?php
 }
 }
-if (isset($svn)) {
-	unset($svn);
+if (!$svnrev) {
+	return;
 }
 }
 ?>
 ?>
+<span class="svn-revision">
+<?php
+	echo $svnrev;
+?>
+</span>

+ 3 - 3
View/Helper/FormatHelper.php

@@ -542,7 +542,7 @@ class FormatHelper extends TextHelper {
 		}
 		}
 		$languageChange .= '<span class="country">';
 		$languageChange .= '<span class="country">';
 		foreach ($languages as $code => $la) {
 		foreach ($languages as $code => $la) {
-			if ($lang == $code) {
+			if ($lang === $code) {
 				$languageChange .= $this->Html->image('language_flags/' . $code . '.gif', array('alt' => $code, 'title' => $la['title'] . ' (' . __('active') . ')', 'class' => 'country_flag active')) . '';
 				$languageChange .= $this->Html->image('language_flags/' . $code . '.gif', array('alt' => $code, 'title' => $la['title'] . ' (' . __('active') . ')', 'class' => 'country_flag active')) . '';
 			} else {
 			} else {
 				$languageChange .= $this->Html->link($this->Html->image('language_flags/' . $code . '.gif', array('alt' => $code, 'title' => $la['title'], 'class' => 'country_flag')), '/lang/' . $code, array('escape' => false)) . '';
 				$languageChange .= $this->Html->link($this->Html->image('language_flags/' . $code . '.gif', array('alt' => $code, 'title' => $la['title'], 'class' => 'country_flag')), '/lang/' . $code, array('escape' => false)) . '';
@@ -997,7 +997,7 @@ class FormatHelper extends TextHelper {
 	 * @return string Value in HTML tags
 	 * @return string Value in HTML tags
 	 */
 	 */
 	public function warning($value, $ok = false) {
 	public function warning($value, $ok = false) {
-		if ($ok !== true) {
+		if ($ok) {
 			return $this->ok($value, false);
 			return $this->ok($value, false);
 		}
 		}
 		return $value;
 		return $value;
@@ -1015,7 +1015,7 @@ class FormatHelper extends TextHelper {
 	 * @return string newValue nicely formatted/colored
 	 * @return string newValue nicely formatted/colored
 	 */
 	 */
 	public function ok($value, $ok = false) {
 	public function ok($value, $ok = false) {
-		if ($ok === true) {
+		if ($ok) {
 			$value = '<span class="green" style="color:green">' . $value . '</span>';
 			$value = '<span class="green" style="color:green">' . $value . '</span>';
 		} else {
 		} else {
 			$value = '<span class="red" style="color:red">' . $value . '</span>';
 			$value = '<span class="red" style="color:red">' . $value . '</span>';

+ 21 - 21
View/Helper/TreeHelper.php

@@ -23,7 +23,7 @@ class TreeHelper extends AppHelper {
 	 *
 	 *
 	 * @var array
 	 * @var array
 	 */
 	 */
-	protected $_defaults = array(
+	protected $_defaultConfig = array(
 		'model' => null,
 		'model' => null,
 		'alias' => 'name',
 		'alias' => 'name',
 		'type' => 'ul',
 		'type' => 'ul',
@@ -48,11 +48,11 @@ class TreeHelper extends AppHelper {
 	);
 	);
 
 
 	/**
 	/**
-	 * Settings property
+	 * Config settings property
 	 *
 	 *
 	 * @var array
 	 * @var array
 	 */
 	 */
-	protected $_settings = array();
+	protected $_config = array();
 
 
 	/**
 	/**
 	 * TypeAttributes property
 	 * TypeAttributes property
@@ -115,20 +115,20 @@ class TreeHelper extends AppHelper {
 	 *		and optionally set the splitDepth to get parallel lists
 	 *		and optionally set the splitDepth to get parallel lists
 	 *
 	 *
 	 * @param array $data data to loop on
 	 * @param array $data data to loop on
-	 * @param array $settings
+	 * @param array $config
 	 * @return string html representation of the passed data
 	 * @return string html representation of the passed data
 	 * @throws CakeException
 	 * @throws CakeException
 	 */
 	 */
-	public function generate(array $data, array $settings = array()) {
+	public function generate(array $data, array $config = array()) {
 		if (!$data) {
 		if (!$data) {
 			return '';
 			return '';
 		}
 		}
 
 
-		$this->_settings = $settings + $this->_defaults;
-		if ($this->_settings['autoPath'] && !isset($this->_settings['autoPath'][2])) {
-			$this->_settings['autoPath'][2] = 'active';
+		$this->_config = $config + $this->_defaultConfig;
+		if ($this->_config['autoPath'] && !isset($this->_config['autoPath'][2])) {
+			$this->_config['autoPath'][2] = 'active';
 		}
 		}
-		extract($this->_settings);
+		extract($this->_config);
 		if ($indent === null && Configure::read('debug')) {
 		if ($indent === null && Configure::read('debug')) {
 			$indent = true;
 			$indent = true;
 		}
 		}
@@ -144,7 +144,7 @@ class TreeHelper extends AppHelper {
 				}
 				}
 			}
 			}
 		}
 		}
-		$this->_settings['model'] = $model;
+		$this->_config['model'] = $model;
 
 
 		$this->_itemAttributes = $this->_typeAttributes = $this->_typeAttributesNext = array();
 		$this->_itemAttributes = $this->_typeAttributes = $this->_typeAttributesNext = array();
 		$stack = array();
 		$stack = array();
@@ -158,7 +158,7 @@ class TreeHelper extends AppHelper {
 		}
 		}
 		$return = '';
 		$return = '';
 		$addType = true;
 		$addType = true;
-		$this->_settings['totalNodes'] = count($data);
+		$this->_config['totalNodes'] = count($data);
 		$keys = array_keys($data);
 		$keys = array_keys($data);
 
 
 		if ($hideUnrelated === true || is_numeric($hideUnrelated)) {
 		if ($hideUnrelated === true || is_numeric($hideUnrelated)) {
@@ -255,9 +255,9 @@ class TreeHelper extends AppHelper {
 				$result['children'] = array();
 				$result['children'] = array();
 			}
 			}
 
 
-			$this->_settings = $elementData + $this->_settings;
-			if ($this->_settings['fullSettings']) {
-				$elementData = $this->_settings;
+			$this->_config = $elementData + $this->_config;
+			if ($this->_config['fullSettings']) {
+				$elementData = $this->_config;
 			}
 			}
 
 
 			/* Main Content */
 			/* Main Content */
@@ -298,9 +298,9 @@ class TreeHelper extends AppHelper {
 			$addType = false;
 			$addType = false;
 			if ($hasVisibleChildren) {
 			if ($hasVisibleChildren) {
 				if ($numberOfDirectChildren) {
 				if ($numberOfDirectChildren) {
-					$settings['depth'] = $depth + 1;
+					$config['depth'] = $depth + 1;
 					$return .= $this->_suffix();
 					$return .= $this->_suffix();
-					$return .= $this->generate($result['children'], $settings);
+					$return .= $this->generate($result['children'], $config);
 					if ($itemType) {
 					if ($itemType) {
 						if ($indent) {
 						if ($indent) {
 							$return .= $whiteSpace . "\t";
 							$return .= $whiteSpace . "\t";
@@ -396,7 +396,7 @@ class TreeHelper extends AppHelper {
 	 */
 	 */
 	public function addTypeAttribute($id = '', $key = '', $value = null, $previousOrNext = 'next') {
 	public function addTypeAttribute($id = '', $key = '', $value = null, $previousOrNext = 'next') {
 		$var = '_typeAttributes';
 		$var = '_typeAttributes';
-		$firstChild = isset($this->_settings['firstChild']) ? $this->_settings['firstChild'] : true;
+		$firstChild = isset($this->_config['firstChild']) ? $this->_config['firstChild'] : true;
 		if ($previousOrNext === 'next' && $firstChild) {
 		if ($previousOrNext === 'next' && $firstChild) {
 			$var = '_typeAttributesNext';
 			$var = '_typeAttributesNext';
 		}
 		}
@@ -430,7 +430,7 @@ class TreeHelper extends AppHelper {
 			$_splitCount = 0;
 			$_splitCount = 0;
 			$_splitCounter = 0;
 			$_splitCounter = 0;
 		}
 		}
-		extract($this->_settings);
+		extract($this->_config);
 		if ($splitDepth || $splitCount) {
 		if ($splitDepth || $splitCount) {
 			if (!$splitDepth) {
 			if (!$splitDepth) {
 				$_splitCount = $totalNodes / $splitCount;
 				$_splitCount = $totalNodes / $splitCount;
@@ -452,7 +452,7 @@ class TreeHelper extends AppHelper {
 			if (!$splitDepth || $depth == $splitDepth) {
 			if (!$splitDepth || $depth == $splitDepth) {
 				$_splitCounter++;
 				$_splitCounter++;
 				if ($type && ($_splitCounter % $_splitCount) === 0 && !$lastChild) {
 				if ($type && ($_splitCounter % $_splitCount) === 0 && !$lastChild) {
-					unset ($this->_settings['callback']);
+					unset ($this->_config['callback']);
 					return '</' . $type . '><' . $type . '>';
 					return '</' . $type . '><' . $type . '>';
 				}
 				}
 			}
 			}
@@ -469,7 +469,7 @@ class TreeHelper extends AppHelper {
 	 * @return void
 	 * @return void
 	 */
 	 */
 	protected function _attributes($rType, array $elementData = array(), $clear = true) {
 	protected function _attributes($rType, array $elementData = array(), $clear = true) {
-		extract($this->_settings);
+		extract($this->_config);
 		if ($rType === $type) {
 		if ($rType === $type) {
 			$attributes = $this->_typeAttributes;
 			$attributes = $this->_typeAttributes;
 			if ($clear) {
 			if ($clear) {
@@ -522,7 +522,7 @@ class TreeHelper extends AppHelper {
 	 * @throws CakeException
 	 * @throws CakeException
 	 */
 	 */
 	protected function _markUnrelatedAsHidden(&$tree, array $path, $level = 0) {
 	protected function _markUnrelatedAsHidden(&$tree, array $path, $level = 0) {
-		extract($this->_settings);
+		extract($this->_config);
 		$siblingIsActive = false;
 		$siblingIsActive = false;
 		foreach ($tree as $key => &$subTree) {
 		foreach ($tree as $key => &$subTree) {
 			if (!isset($subTree['children'])) {
 			if (!isset($subTree['children'])) {