Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,19 +2,18 @@
/**
* PHP configuration based AclInterface implementation
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Controller.Component.Acl
* @since CakePHP(tm) v 2.1
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
@ -23,9 +22,20 @@
*
* @package Cake.Controller.Component.Acl
*/
class PhpAcl extends Object implements AclInterface {
class PhpAcl extends CakeObject implements AclInterface {
/**
* Constant for deny
*
* @var bool
*/
const DENY = false;
/**
* Constant for allow
*
* @var bool
*/
const ALLOW = true;
/**
@ -58,7 +68,7 @@ class PhpAcl extends Object implements AclInterface {
*/
public function __construct() {
$this->options = array(
'policy' => self::DENY,
'policy' => static::DENY,
'config' => APP . 'Config' . DS . 'acl.php',
);
}
@ -71,7 +81,7 @@ class PhpAcl extends Object implements AclInterface {
*/
public function initialize(Component $Component) {
if (!empty($Component->settings['adapter'])) {
$this->options = array_merge($this->options, $Component->settings['adapter']);
$this->options = $Component->settings['adapter'] + $this->options;
}
App::uses('PhpReader', 'Configure');
@ -91,11 +101,11 @@ class PhpAcl extends Object implements AclInterface {
*/
public function build(array $config) {
if (empty($config['roles'])) {
throw new AclException(__d('cake_dev','"roles" section not found in configuration.'));
throw new AclException(__d('cake_dev', '"roles" section not found in configuration.'));
}
if (empty($config['rules']['allow']) && empty($config['rules']['deny'])) {
throw new AclException(__d('cake_dev','Neither "allow" nor "deny" rules were provided in configuration.'));
throw new AclException(__d('cake_dev', 'Neither "allow" nor "deny" rules were provided in configuration.'));
}
$rules['allow'] = !empty($config['rules']['allow']) ? $config['rules']['allow'] : array();
@ -114,7 +124,7 @@ class PhpAcl extends Object implements AclInterface {
* @param string $aro ARO The requesting object identifier.
* @param string $aco ACO The controlled object identifier.
* @param string $action Action (defaults to *)
* @return boolean Success
* @return bool Success
*/
public function allow($aro, $aco, $action = "*") {
return $this->Aco->access($this->Aro->resolve($aro), $aco, $action, 'allow');
@ -126,7 +136,7 @@ class PhpAcl extends Object implements AclInterface {
* @param string $aro ARO The requesting object identifier.
* @param string $aco ACO The controlled object identifier.
* @param string $action Action (defaults to *)
* @return boolean Success
* @return bool Success
*/
public function deny($aro, $aco, $action = "*") {
return $this->Aco->access($this->Aro->resolve($aro), $aco, $action, 'deny');
@ -138,7 +148,7 @@ class PhpAcl extends Object implements AclInterface {
* @param string $aro ARO The requesting object identifier.
* @param string $aco ACO The controlled object identifier.
* @param string $action Action (defaults to *)
* @return boolean Success
* @return bool Success
*/
public function inherit($aro, $aco, $action = "*") {
return false;
@ -151,13 +161,13 @@ class PhpAcl extends Object implements AclInterface {
* @param string $aro ARO
* @param string $aco ACO
* @param string $action Action
* @return boolean true if access is granted, false otherwise
* @return bool true if access is granted, false otherwise
*/
public function check($aro, $aco, $action = "*") {
$allow = $this->options['policy'];
$prioritizedAros = $this->Aro->roles($aro);
if ($action && $action != "*") {
if ($action && $action !== "*") {
$aco .= '/' . $action;
}
@ -167,14 +177,14 @@ class PhpAcl extends Object implements AclInterface {
return $allow;
}
foreach ($path as $depth => $node) {
foreach ($path as $node) {
foreach ($prioritizedAros as $aros) {
if (!empty($node['allow'])) {
$allow = $allow || count(array_intersect($node['allow'], $aros)) > 0;
$allow = $allow || count(array_intersect($node['allow'], $aros));
}
if (!empty($node['deny'])) {
$allow = $allow && count(array_intersect($node['deny'], $aros)) == 0;
$allow = $allow && !count(array_intersect($node['deny'], $aros));
}
}
}
@ -186,7 +196,6 @@ class PhpAcl extends Object implements AclInterface {
/**
* Access Control Object
*
*/
class PhpAco {
@ -206,6 +215,11 @@ class PhpAco {
'*' => '.*',
);
/**
* Constructor
*
* @param array $rules Rules array
*/
public function __construct(array $rules = array()) {
foreach (array('allow', 'deny') as $type) {
if (empty($rules[$type])) {
@ -219,6 +233,7 @@ class PhpAco {
/**
* return path to the requested ACO with allow and deny rules attached on each level
*
* @param string $aco ACO string
* @return array
*/
public function path($aco) {
@ -236,7 +251,7 @@ class PhpAco {
}
foreach ($root as $node => $elements) {
$pattern = '/^' . str_replace(array_keys(self::$modifiers), array_values(self::$modifiers), $node) . '$/';
$pattern = '/^' . str_replace(array_keys(static::$modifiers), array_values(static::$modifiers), $node) . '$/';
if ($node == $aco[$level] || preg_match($pattern, $aco[$level])) {
// merge allow/denies with $path of current level
@ -263,6 +278,10 @@ class PhpAco {
/**
* allow/deny ARO access to ARO
*
* @param string $aro ARO string
* @param string $aco ACO string
* @param string $action Action string
* @param string $type access type
* @return void
*/
public function access($aro, $aco, $action, $type = 'deny') {
@ -273,7 +292,7 @@ class PhpAco {
foreach ($aco as $i => $node) {
if (!isset($tree[$node])) {
$tree[$node] = array(
$tree[$node] = array(
'children' => array(),
);
}
@ -303,7 +322,7 @@ class PhpAco {
return array_map('strtolower', $aco);
}
// strip multiple occurences of '/'
// strip multiple occurrences of '/'
$aco = preg_replace('#/+#', '/', $aco);
// make case insensitive
$aco = ltrim(strtolower($aco), '/');
@ -319,7 +338,6 @@ class PhpAco {
*/
public function build(array $allow, array $deny = array()) {
$this->_tree = array();
$tree = array();
foreach ($allow as $dotPath => $aros) {
if (is_string($aros)) {
@ -342,7 +360,6 @@ class PhpAco {
/**
* Access Request Object
*
*/
class PhpAro {
@ -385,6 +402,13 @@ class PhpAro {
*/
protected $_tree = array();
/**
* Constructor
*
* @param array $aro The aro data
* @param array $map The identifier mappings
* @param array $aliases The aliases to map.
*/
public function __construct(array $aro = array(), array $map = array(), array $aliases = array()) {
if (!empty($map)) {
$this->map = $map;
@ -436,7 +460,7 @@ class PhpAro {
$mapped = '';
if (is_array($aro)) {
if (isset($aro['model']) && isset($aro['foreign_key']) && $aro['model'] == $aroGroup) {
if (isset($aro['model']) && isset($aro['foreign_key']) && $aro['model'] === $aroGroup) {
$mapped = $aroGroup . '/' . $aro['foreign_key'];
} elseif (isset($aro[$model][$field])) {
$mapped = $aroGroup . '/' . $aro[$model][$field];
@ -453,7 +477,7 @@ class PhpAro {
$aroModel = Inflector::camelize($aroModel);
if ($aroModel == $model || $aroModel == $aroGroup) {
if ($aroModel === $model || $aroModel === $aroGroup) {
$mapped = $aroGroup . '/' . $aroValue;
}
}
@ -468,7 +492,7 @@ class PhpAro {
return $this->aliases[$mapped];
}
}
return self::DEFAULT_ROLE;
return static::DEFAULT_ROLE;
}
/**
@ -519,8 +543,8 @@ class PhpAro {
* @param array $alias alias from => to (e.g. Role/13 -> Role/editor)
* @return void
*/
public function addAlias(array $alias) {
$this->aliases = array_merge($this->aliases, $alias);
public function addAlias(array $alias) {
$this->aliases = $alias + $this->aliases;
}
/**