From aef9d158f316a8c55af9ee0d65715fc1b3a1acab Mon Sep 17 00:00:00 2001
From: Jack Worman <66142217+jack-worman@users.noreply.github.com>
Date: Sun, 10 Nov 2024 16:23:46 -0500
Subject: [PATCH] Make-Acl-stateless (#26)
---
packages/zend-acl/library/Zend/Acl.php | 50 ++++++++-----------
.../Zend/Controller/Router/Rewrite.php | 2 +-
.../library/Zend/Controller/Router/Route.php | 2 +-
.../Zend/Controller/Router/Route/Module.php | 2 +-
.../Zend/Dojo/View/Helper/RadioButton.php | 2 +-
.../Zend/Http/Client/Adapter/Proxy.php | 4 +-
packages/zend-mime/library/Zend/Mime.php | 8 +--
.../zend-mime/library/Zend/Mime/Decode.php | 6 +--
.../zend-mime/library/Zend/Mime/Message.php | 2 +-
.../library/Zend/Oauth/Consumer.php | 8 +--
.../zend-oauth/library/Zend/Oauth/Http.php | 2 +-
.../library/Zend/Oauth/Http/Utility.php | 4 +-
.../zend-oauth/library/Zend/Oauth/Token.php | 2 +-
.../library/Zend/Oauth/Token/Access.php | 2 +-
.../library/Zend/Oauth/Token/Request.php | 2 +-
.../library/Zend/Queue/Stomp/Client.php | 2 +-
.../library/Zend/View/Helper/FormElement.php | 2 +-
17 files changed, 47 insertions(+), 55 deletions(-)
diff --git a/packages/zend-acl/library/Zend/Acl.php b/packages/zend-acl/library/Zend/Acl.php
index 28843f069..f62c8ce7b 100644
--- a/packages/zend-acl/library/Zend/Acl.php
+++ b/packages/zend-acl/library/Zend/Acl.php
@@ -87,20 +87,9 @@ class Zend_Acl
*/
protected $_resources = [];
- /**
- * @var Zend_Acl_Role_Interface
- */
- protected $_isAllowedRole;
-
- /**
- * @var Zend_Acl_Resource_Interface
- */
- protected $_isAllowedResource;
-
- /**
- * @var string
- */
- protected $_isAllowedPrivilege;
+ private Zend_Acl_Role_Interface|string|null $_isAllowedRole = null;
+ private Zend_Acl_Resource_Interface|string|null $_isAllowedResource = null;
+ private ?string $_isAllowedPrivilege = null;
/**
* ACL rules; whitelist (deny everything to all) by default.
@@ -829,23 +818,26 @@ public function setRule($operation, $type, $roles = null, $resources = null, $pr
* The highest priority parent (i.e., the parent most recently added) is checked first,
* and its respective parents are checked similarly before the lower-priority parents of
* the Role are checked.
- *
- * @param Zend_Acl_Role_Interface|string $role
- * @param Zend_Acl_Resource_Interface|string $resource
- * @param string $privilege
- *
- * @uses Zend_Acl::get()
- * @uses Zend_Acl_Role_Registry::get()
- *
- * @return bool
*/
- public function isAllowed($role = null, $resource = null, $privilege = null)
- {
- // reset role & resource to null
- $this->_isAllowedRole = null;
- $this->_isAllowedResource = null;
- $this->_isAllowedPrivilege = null;
+ public function isAllowed(
+ Zend_Acl_Role_Interface|string|null $role = null,
+ Zend_Acl_Resource_Interface|string|null $resource = null,
+ ?string $privilege = null,
+ ): bool {
+ try {
+ return $this->doIsAllowed($role, $resource, $privilege);
+ } finally {
+ $this->_isAllowedRole = null;
+ $this->_isAllowedResource = null;
+ $this->_isAllowedPrivilege = null;
+ }
+ }
+ private function doIsAllowed(
+ Zend_Acl_Role_Interface|string|null $role = null,
+ Zend_Acl_Resource_Interface|string|null $resource = null,
+ ?string $privilege = null,
+ ): bool {
if (null !== $role) {
// keep track of originally called role
$this->_isAllowedRole = $role;
diff --git a/packages/zend-controller/library/Zend/Controller/Router/Rewrite.php b/packages/zend-controller/library/Zend/Controller/Router/Rewrite.php
index 37e3ccfaf..fc6bc6a6a 100644
--- a/packages/zend-controller/library/Zend/Controller/Router/Rewrite.php
+++ b/packages/zend-controller/library/Zend/Controller/Router/Rewrite.php
@@ -242,7 +242,7 @@ protected function _getRouteFromConfig(Zend_Config $info)
protected function _addChainRoutesFromConfig(
$name,
Zend_Controller_Router_Route_Interface $route,
- Zend_Config $childRoutesInfo
+ Zend_Config $childRoutesInfo,
) {
foreach ($childRoutesInfo as $childRouteName => $childRouteInfo) {
if (is_string($childRouteInfo)) {
diff --git a/packages/zend-controller/library/Zend/Controller/Router/Route.php b/packages/zend-controller/library/Zend/Controller/Router/Route.php
index 4012d6a6f..53b7bc11d 100644
--- a/packages/zend-controller/library/Zend/Controller/Router/Route.php
+++ b/packages/zend-controller/library/Zend/Controller/Router/Route.php
@@ -167,7 +167,7 @@ public static function getInstance(Zend_Config $config)
* @param mixed|null $locale
*/
public function __construct(
- $route, $defaults = [], $reqs = [], ?Zend_Translate $translator = null, $locale = null
+ $route, $defaults = [], $reqs = [], ?Zend_Translate $translator = null, $locale = null,
) {
$route = \trim((string) $route, $this->_urlDelimiter);
$this->_defaults = (array) $defaults;
diff --git a/packages/zend-controller/library/Zend/Controller/Router/Route/Module.php b/packages/zend-controller/library/Zend/Controller/Router/Route/Module.php
index b95d3dd0c..634de9e4d 100644
--- a/packages/zend-controller/library/Zend/Controller/Router/Route/Module.php
+++ b/packages/zend-controller/library/Zend/Controller/Router/Route/Module.php
@@ -116,7 +116,7 @@ public static function getInstance(Zend_Config $config)
public function __construct(
array $defaults = [],
?Zend_Controller_Dispatcher_Interface $dispatcher = null,
- ?Zend_Controller_Request_Abstract $request = null
+ ?Zend_Controller_Request_Abstract $request = null,
) {
$this->_defaults = $defaults;
diff --git a/packages/zend-dojo/library/Zend/Dojo/View/Helper/RadioButton.php b/packages/zend-dojo/library/Zend/Dojo/View/Helper/RadioButton.php
index bdc4b26c1..1b4780216 100644
--- a/packages/zend-dojo/library/Zend/Dojo/View/Helper/RadioButton.php
+++ b/packages/zend-dojo/library/Zend/Dojo/View/Helper/RadioButton.php
@@ -65,7 +65,7 @@ public function radioButton(
array $params = [],
array $attribs = [],
?array $options = null,
- $listsep = "
\n"
+ $listsep = "
\n",
) {
$attribs['name'] = $id;
if (!array_key_exists('id', $attribs)) {
diff --git a/packages/zend-http/library/Zend/Http/Client/Adapter/Proxy.php b/packages/zend-http/library/Zend/Http/Client/Adapter/Proxy.php
index 3c6d630bd..99f20ca57 100644
--- a/packages/zend-http/library/Zend/Http/Client/Adapter/Proxy.php
+++ b/packages/zend-http/library/Zend/Http/Client/Adapter/Proxy.php
@@ -126,7 +126,7 @@ public function connect($host, $port = 80, $secure = false)
* @throws Zend_Http_Client_Adapter_Exception
*/
public function write(
- $method, $uri, $http_ver = '1.1', $headers = [], $body = ''
+ $method, $uri, $http_ver = '1.1', $headers = [], $body = '',
) {
// If no proxy is set, fall back to default Socket adapter
if (!$this->config['proxy_host']) {
@@ -235,7 +235,7 @@ public function write(
* @throws Zend_Http_Client_Adapter_Exception
*/
protected function connectHandshake(
- $host, $port = 443, $http_ver = '1.1', array &$headers = []
+ $host, $port = 443, $http_ver = '1.1', array &$headers = [],
) {
$request = "CONNECT $host:$port HTTP/$http_ver\r\n".
'Host: '.$host."\r\n";
diff --git a/packages/zend-mime/library/Zend/Mime.php b/packages/zend-mime/library/Zend/Mime.php
index 74440f774..5e4feb3b7 100644
--- a/packages/zend-mime/library/Zend/Mime.php
+++ b/packages/zend-mime/library/Zend/Mime.php
@@ -426,7 +426,7 @@ public static function isPrintable($str)
public static function encodeQuotedPrintable(
$str,
$lineLength = self::LINELENGTH,
- $lineEnd = self::LINEEND
+ $lineEnd = self::LINEEND,
) {
$out = '';
$str = self::_encodeQuotedPrintable($str);
@@ -489,7 +489,7 @@ private static function _encodeQuotedPrintable($str)
* @return string
*/
public static function encodeQuotedPrintableHeader(
- $str, $charset, $lineLength = self::LINELENGTH, $lineEnd = self::LINEEND
+ $str, $charset, $lineLength = self::LINELENGTH, $lineEnd = self::LINEEND,
) {
// Reduce line-length by the length of the required delimiter, charsets and encoding
$prefix = sprintf('=?%s?Q?', $charset);
@@ -567,7 +567,7 @@ private static function getNextQuotedPrintableToken($str)
* @return string
*/
public static function encodeBase64Header(
- $str, $charset, $lineLength = self::LINELENGTH, $lineEnd = self::LINEEND
+ $str, $charset, $lineLength = self::LINELENGTH, $lineEnd = self::LINEEND,
) {
$prefix = '=?'.$charset.'?B?';
$suffix = '?=';
@@ -593,7 +593,7 @@ public static function encodeBase64Header(
* @return string
*/
public static function encodeBase64(
- $str, $lineLength = self::LINELENGTH, $lineEnd = self::LINEEND
+ $str, $lineLength = self::LINELENGTH, $lineEnd = self::LINEEND,
) {
return rtrim((string) chunk_split(base64_encode($str), $lineLength, $lineEnd));
}
diff --git a/packages/zend-mime/library/Zend/Mime/Decode.php b/packages/zend-mime/library/Zend/Mime/Decode.php
index 70f8d3532..df3b61542 100644
--- a/packages/zend-mime/library/Zend/Mime/Decode.php
+++ b/packages/zend-mime/library/Zend/Mime/Decode.php
@@ -94,7 +94,7 @@ public static function splitMime($body, $boundary)
* @throws Zend_Exception
*/
public static function splitMessageStruct(
- $message, $boundary, $EOL = Zend_Mime::LINEEND
+ $message, $boundary, $EOL = Zend_Mime::LINEEND,
) {
$parts = self::splitMime($message, $boundary);
if (count($parts) <= 0) {
@@ -126,7 +126,7 @@ public static function splitMessageStruct(
* @return null
*/
public static function splitMessage(
- $message, &$headers, &$body, $EOL = Zend_Mime::LINEEND
+ $message, &$headers, &$body, $EOL = Zend_Mime::LINEEND,
) {
// check for valid header at first line
$firstline = strtok($message, "\n");
@@ -222,7 +222,7 @@ public static function splitContentType($type, $wantedPart = null)
* @throws Zend_Exception
*/
public static function splitHeaderField(
- $field, $wantedPart = null, $firstName = 0
+ $field, $wantedPart = null, $firstName = 0,
) {
$wantedPart = strtolower((string) $wantedPart);
$firstName = strtolower((string) $firstName);
diff --git a/packages/zend-mime/library/Zend/Mime/Message.php b/packages/zend-mime/library/Zend/Mime/Message.php
index 8b06ddc22..2392d9363 100644
--- a/packages/zend-mime/library/Zend/Mime/Message.php
+++ b/packages/zend-mime/library/Zend/Mime/Message.php
@@ -260,7 +260,7 @@ protected static function _disassembleMime($body, $boundary)
* @throws Zend_Exception
*/
public static function createFromMessage(
- $message, $boundary, $EOL = Zend_Mime::LINEEND
+ $message, $boundary, $EOL = Zend_Mime::LINEEND,
) {
// require_once 'Zend/Mime/Decode.php';
$parts = Zend_Mime_Decode::splitMessageStruct($message, $boundary, $EOL);
diff --git a/packages/zend-oauth/library/Zend/Oauth/Consumer.php b/packages/zend-oauth/library/Zend/Oauth/Consumer.php
index 49f891e4e..5c36a18b9 100644
--- a/packages/zend-oauth/library/Zend/Oauth/Consumer.php
+++ b/packages/zend-oauth/library/Zend/Oauth/Consumer.php
@@ -100,7 +100,7 @@ public function __construct($options = null)
public function getRequestToken(
?array $customServiceParameters = null,
$httpMethod = null,
- ?Zend_Oauth_Http_RequestToken $request = null
+ ?Zend_Oauth_Http_RequestToken $request = null,
) {
if (null === $request) {
$request = new Zend_Oauth_Http_RequestToken($this, $customServiceParameters);
@@ -130,7 +130,7 @@ public function getRequestToken(
public function getRedirectUrl(
?array $customServiceParameters = null,
?Zend_Oauth_Token_Request $token = null,
- ?Zend_Oauth_Http_UserAuthorization $redirect = null
+ ?Zend_Oauth_Http_UserAuthorization $redirect = null,
) {
if (null === $redirect) {
$redirect = new Zend_Oauth_Http_UserAuthorization($this, $customServiceParameters);
@@ -155,7 +155,7 @@ public function getRedirectUrl(
public function redirect(
?array $customServiceParameters = null,
?Zend_Oauth_Token_Request $token = null,
- ?Zend_Oauth_Http_UserAuthorization $request = null
+ ?Zend_Oauth_Http_UserAuthorization $request = null,
) {
if ($token instanceof Zend_Oauth_Http_UserAuthorization) {
$request = $token;
@@ -182,7 +182,7 @@ public function getAccessToken(
$queryData,
Zend_Oauth_Token_Request $token,
$httpMethod = null,
- ?Zend_Oauth_Http_AccessToken $request = null
+ ?Zend_Oauth_Http_AccessToken $request = null,
) {
$authorizedToken = new Zend_Oauth_Token_AuthorizedRequest($queryData);
if (!$authorizedToken->isValid()) {
diff --git a/packages/zend-oauth/library/Zend/Oauth/Http.php b/packages/zend-oauth/library/Zend/Oauth/Http.php
index f313a4b54..96a069090 100644
--- a/packages/zend-oauth/library/Zend/Oauth/Http.php
+++ b/packages/zend-oauth/library/Zend/Oauth/Http.php
@@ -75,7 +75,7 @@ class Zend_Oauth_Http
public function __construct(
Zend_Oauth_Consumer $consumer,
?array $parameters = null,
- ?Zend_Oauth_Http_Utility $utility = null
+ ?Zend_Oauth_Http_Utility $utility = null,
) {
$this->_consumer = $consumer;
$this->_preferredRequestScheme = $this->_consumer->getRequestScheme();
diff --git a/packages/zend-oauth/library/Zend/Oauth/Http/Utility.php b/packages/zend-oauth/library/Zend/Oauth/Http/Utility.php
index 5f8f172e0..31e69d3c9 100644
--- a/packages/zend-oauth/library/Zend/Oauth/Http/Utility.php
+++ b/packages/zend-oauth/library/Zend/Oauth/Http/Utility.php
@@ -45,7 +45,7 @@ class Zend_Oauth_Http_Utility
public function assembleParams(
$url,
Zend_Oauth_Config_ConfigInterface $config,
- ?array $serviceProviderParams = null
+ ?array $serviceProviderParams = null,
) {
$params = [
'oauth_consumer_key' => $config->getConsumerKey(),
@@ -143,7 +143,7 @@ public function toAuthorizationHeader(array $params, $realm = null, $excludeCust
* @return string
*/
public function sign(
- array $params, $signatureMethod, $consumerSecret, $tokenSecret = null, $method = null, $url = null
+ array $params, $signatureMethod, $consumerSecret, $tokenSecret = null, $method = null, $url = null,
) {
$className = '';
$hashAlgo = null;
diff --git a/packages/zend-oauth/library/Zend/Oauth/Token.php b/packages/zend-oauth/library/Zend/Oauth/Token.php
index 8ffefb1db..425258e00 100644
--- a/packages/zend-oauth/library/Zend/Oauth/Token.php
+++ b/packages/zend-oauth/library/Zend/Oauth/Token.php
@@ -63,7 +63,7 @@ abstract class Zend_Oauth_Token
*/
public function __construct(
?Zend_Http_Response $response = null,
- ?Zend_Oauth_Http_Utility $utility = null
+ ?Zend_Oauth_Http_Utility $utility = null,
) {
if (null !== $response) {
$this->_response = $response;
diff --git a/packages/zend-oauth/library/Zend/Oauth/Token/Access.php b/packages/zend-oauth/library/Zend/Oauth/Token/Access.php
index 9c4dfc092..668393b17 100644
--- a/packages/zend-oauth/library/Zend/Oauth/Token/Access.php
+++ b/packages/zend-oauth/library/Zend/Oauth/Token/Access.php
@@ -49,7 +49,7 @@ class Zend_Oauth_Token_Access extends Zend_Oauth_Token
* @return string
*/
public function toHeader(
- $url, Zend_Oauth_Config_ConfigInterface $config, ?array $customParams = null, $realm = null
+ $url, Zend_Oauth_Config_ConfigInterface $config, ?array $customParams = null, $realm = null,
) {
if (!Zend_Uri::check($url)) {
// require_once 'Zend/Oauth/Exception.php';
diff --git a/packages/zend-oauth/library/Zend/Oauth/Token/Request.php b/packages/zend-oauth/library/Zend/Oauth/Token/Request.php
index 5163d0b91..774c173d8 100644
--- a/packages/zend-oauth/library/Zend/Oauth/Token/Request.php
+++ b/packages/zend-oauth/library/Zend/Oauth/Token/Request.php
@@ -36,7 +36,7 @@ class Zend_Oauth_Token_Request extends Zend_Oauth_Token
*/
public function __construct(
?Zend_Http_Response $response = null,
- ?Zend_Oauth_Http_Utility $utility = null
+ ?Zend_Oauth_Http_Utility $utility = null,
) {
parent::__construct($response, $utility);
diff --git a/packages/zend-queue/library/Zend/Queue/Stomp/Client.php b/packages/zend-queue/library/Zend/Queue/Stomp/Client.php
index d59d7a1f0..be9061d92 100644
--- a/packages/zend-queue/library/Zend/Queue/Stomp/Client.php
+++ b/packages/zend-queue/library/Zend/Queue/Stomp/Client.php
@@ -47,7 +47,7 @@ class Zend_Queue_Stomp_Client
public function __construct(
$scheme = null, $host = null, $port = null,
$connectionClass = 'Zend_Queue_Stomp_Client_Connection',
- $frameClass = 'Zend_Queue_Stomp_Frame'
+ $frameClass = 'Zend_Queue_Stomp_Frame',
) {
if ((null !== $scheme)
&& (null !== $host)
diff --git a/packages/zend-view/library/Zend/View/Helper/FormElement.php b/packages/zend-view/library/Zend/View/Helper/FormElement.php
index 49c7b3ec1..e0095ac1b 100644
--- a/packages/zend-view/library/Zend/View/Helper/FormElement.php
+++ b/packages/zend-view/library/Zend/View/Helper/FormElement.php
@@ -88,7 +88,7 @@ public function setTranslator($translator = null)
* attribs, options, listsep, disable, and escape
*/
protected function _getInfo($name, $value = null, $attribs = null,
- $options = null, $listsep = null
+ $options = null, $listsep = null,
) {
// the baseline info. note that $name serves a dual purpose;
// if an array, it's an element info array that will override