Skip to content

Commit

Permalink
Improve compatibility with PHP 7.4 (#161)
Browse files Browse the repository at this point in the history
Improve compatibility with PHP 7.4
  • Loading branch information
dakota authored Jan 7, 2020
2 parents ac2f915 + 7ae30dc commit 7538f9b
Show file tree
Hide file tree
Showing 51 changed files with 228 additions and 141 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4

dist: trusty

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"source": "https://github.com/cakephp/acl"
},
"require": {
"cakephp/cakephp": "^3.6.0",
"cakephp/cakephp": "^3.8.2",
"cakephp/plugin-installer": "*"
},
"require-dev": {
Expand Down
14 changes: 8 additions & 6 deletions src/AclExtras.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Acl Extras.
*
Expand All @@ -10,6 +11,7 @@
* @author Mark Story <[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/

namespace Acl;

use Acl\Controller\Component\AclComponent;
Expand Down Expand Up @@ -252,7 +254,7 @@ protected function _processPlugins($root, array $plugins = [])
$pluginAlias = $this->_pluginAlias($plugin);
$path = [
$this->rootNode,
$pluginAlias
$pluginAlias,
];
$path = implode('/', Hash::filter($path));
$pathNode = $this->_checkNode($path, $pluginAlias, $root->id);
Expand All @@ -268,7 +270,7 @@ protected function _processPlugins($root, array $plugins = [])
foreach (array_keys($this->pluginPrefixes[$plugin]) as $prefix) {
$path = [
$this->rootNode,
$pluginAlias
$pluginAlias,
];
$path = implode('/', Hash::filter($path));
$pluginNode = $this->_checkNode($path, $pluginAlias, $root->id);
Expand Down Expand Up @@ -326,7 +328,7 @@ protected function _updateControllers($root, $controllers, $plugin = null, $pref
$this->rootNode,
$pluginPath,
$prefix,
$controllerName
$controllerName,
];
$path = implode('/', Hash::filter($path));
$controllerNode = $this->_checkNode($path, $controllerName, $root->id);
Expand Down Expand Up @@ -445,7 +447,7 @@ protected function _getCallbacks($className, $pluginPath = null, $prefixPath = n
protected function _checkMethods($className, $controllerName, $node, $pluginPath = null, $prefixPath = null)
{
$excludes = $this->_getCallbacks($className, $pluginPath, $prefixPath);
$baseMethods = get_class_methods(new Controller);
$baseMethods = get_class_methods(new Controller());
$namespace = $this->_getNamespace($className, $pluginPath, $prefixPath);
$methods = get_class_methods($namespace);
if ($methods == null) {
Expand All @@ -464,7 +466,7 @@ protected function _checkMethods($className, $controllerName, $node, $pluginPath
$pluginPath,
$prefixPath,
$controllerName,
$action
$action,
];
$path = implode('/', Hash::filter($path));
$this->_checkNode($path, $action, $node->id);
Expand Down Expand Up @@ -512,7 +514,7 @@ protected function _getNamespace($className, $pluginPath = null, $prefixPath = n
$rootNamespace,
'Controller',
$prefixPath,
$namespace
$namespace,
];

return implode('\\', Hash::filter($namespace));
Expand Down
2 changes: 2 additions & 0 deletions src/AclInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
Expand All @@ -11,6 +12,7 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Acl;

use Cake\Controller\Component;
Expand Down
4 changes: 3 additions & 1 deletion src/Adapter/CachedDbAcl.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
Expand All @@ -11,6 +12,7 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Acl\Adapter;

use Acl\AclInterface;
Expand Down Expand Up @@ -125,7 +127,7 @@ protected function _getNodeCacheKey($ref)
if (empty($tmpRef)) {
$ref = [
'model' => $alias,
'foreign_key' => $ref[$name][$bindTable->getPrimaryKey()]
'foreign_key' => $ref[$name][$bindTable->getPrimaryKey()],
];
} else {
$ref = $tmpRef;
Expand Down
2 changes: 2 additions & 0 deletions src/Adapter/DbAcl.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
Expand All @@ -11,6 +12,7 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Acl\Adapter;

use Acl\AclInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/Adapter/IniAcl.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
Expand All @@ -11,6 +12,7 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Acl\Adapter;

use Acl\AclInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/Adapter/PhpAcl.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP configuration based AclInterface implementation
*
Expand All @@ -13,6 +14,7 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Acl\Adapter;

use Acl\AclInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/Adapter/Utility/PhpAco.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP configuration based Access Control Object
*
Expand All @@ -13,6 +14,7 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Acl\Adapter\Utility;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Adapter/Utility/PhpAro.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP configuration based Access Request Object
*
Expand All @@ -13,6 +14,7 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Acl\Adapter\Utility;

use Cake\Utility\Hash;
Expand Down
2 changes: 2 additions & 0 deletions src/Auth/ActionsAuthorize.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
Expand All @@ -12,6 +13,7 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Acl\Auth;

use Cake\Http\ServerRequest;
Expand Down
6 changes: 4 additions & 2 deletions src/Auth/BaseAuthorize.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
Expand All @@ -11,6 +12,7 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Acl\Auth;

use Cake\Auth\BaseAuthorize as ParentAuthorize;
Expand Down Expand Up @@ -45,9 +47,9 @@ abstract class BaseAuthorize extends ParentAuthorize
'edit' => 'update',
'view' => 'read',
'delete' => 'delete',
'remove' => 'delete'
'remove' => 'delete',
],
'userModel' => 'Users'
'userModel' => 'Users',
];

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Auth/CrudAuthorize.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
Expand All @@ -12,6 +13,7 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Acl\Auth;

use Cake\Controller\ComponentRegistry;
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/Component/AclComponent.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
Expand All @@ -11,6 +12,7 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Acl\Controller\Component;

use Acl\AclInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/Model/Behavior/AclBehavior.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
Expand All @@ -11,6 +12,7 @@
* @link http://cakephp.org CakePHP Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Acl\Model\Behavior;

use Cake\Core\App;
Expand Down
1 change: 1 addition & 0 deletions src/Model/Entity/Aco.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
Expand Down
1 change: 1 addition & 0 deletions src/Model/Entity/Aro.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
Expand Down
1 change: 1 addition & 0 deletions src/Model/Entity/Permission.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
Expand Down
27 changes: 15 additions & 12 deletions src/Model/Table/AclNodesTable.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
Expand All @@ -11,6 +12,7 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Acl\Model\Table;

use Cake\Core\Configure;
Expand Down Expand Up @@ -57,7 +59,7 @@ public function node($ref = null)
return null;
} elseif (is_int($ref) || ctype_digit($ref)) {
$ref = [
'id' => $ref
'id' => $ref,
];
} elseif (is_string($ref)) {
$path = explode('/', $ref);
Expand All @@ -74,9 +76,9 @@ public function node($ref = null)
'table' => $table,
'alias' => "{$type}0",
'type' => 'INNER',
'conditions' => ["{$type}0.alias" => $start]
'conditions' => ["{$type}0.alias" => $start],
]],
'order' => ["{$type}.lft" => 'DESC']
'order' => ["{$type}.lft" => 'DESC'],
];

foreach ($path as $i => $alias) {
Expand All @@ -90,22 +92,23 @@ public function node($ref = null)
"{$type}{$i}.lft" . ' > ' => new IdentifierExpression("{$type}{$j}.lft"),
"{$type}{$i}.rght" . ' < ' => new IdentifierExpression("{$type}{$j}.rght"),
"{$type}{$i}.alias" => $alias,
"{$type}{$j}.id" . ' = ' => new IdentifierExpression("{$type}{$i}.parent_id")
]
"{$type}{$j}.id" . ' = ' => new IdentifierExpression("{$type}{$i}.parent_id"),
],
];

$queryData['conditions'] = [
'or' => [
["{$type}.lft" . ' <= ' => new IdentifierExpression("{$type}0.lft"), "{$type}.rght" . ' >= ' => new IdentifierExpression("{$type}0.rght")],
["{$type}.lft" . ' <= ' => new IdentifierExpression("{$type}{$i}.lft"), "{$type}.rght" . ' >= ' => new IdentifierExpression("{$type}{$i}.rght")]
]
["{$type}.lft" . ' <= ' => new IdentifierExpression("{$type}{$i}.lft"), "{$type}.rght" . ' >= ' => new IdentifierExpression("{$type}{$i}.rght")],
],
];
}
$query = $this->find('all', $queryData);
$result = $query->toArray();
$path = array_values($path);

if (!isset($result[0]) ||
if (
!isset($result[0]) ||
(!empty($path) && $result[0]->alias != $path[count($path) - 1]) ||
(empty($path) && $result[0]->alias != $start)
) {
Expand All @@ -123,7 +126,7 @@ public function node($ref = null)
} else {
$connection = Configure::read('Acl.database');
$bindTable = TableRegistry::getTableLocator()->get($name, [
'connection' => ConnectionManager::get($connection)
'connection' => ConnectionManager::get($connection),
]);
}
$entityClass = $bindTable->getEntityClass();
Expand All @@ -143,7 +146,7 @@ public function node($ref = null)
if (empty($tmpRef)) {
$ref = [
'model' => $alias,
'foreign_key' => $ref[$name][$this->getPrimaryKey()]
'foreign_key' => $ref[$name][$this->getPrimaryKey()],
];
} else {
if (is_string($tmpRef)) {
Expand Down Expand Up @@ -174,8 +177,8 @@ public function node($ref = null)
'conditions' => [
"{$type}.lft" . ' <= ' => new IdentifierExpression("{$type}0.lft"),
"{$type}.rght" . ' >= ' => new IdentifierExpression("{$type}0.rght"),
]
]
],
],
],
'order' => ["{$type}.lft" => 'DESC'],
];
Expand Down
2 changes: 2 additions & 0 deletions src/Model/Table/AcoActionsTable.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
Expand All @@ -11,6 +12,7 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Acl\Model\Table;

use Cake\Core\App;
Expand Down
Loading

0 comments on commit 7538f9b

Please sign in to comment.