Skip to content

Commit

Permalink
Make-Acl-stateless (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-worman authored Nov 10, 2024
1 parent 2bf92a7 commit aef9d15
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 55 deletions.
50 changes: 21 additions & 29 deletions packages/zend-acl/library/Zend/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function radioButton(
array $params = [],
array $attribs = [],
?array $options = null,
$listsep = "<br />\n"
$listsep = "<br />\n",
) {
$attribs['name'] = $id;
if (!array_key_exists('id', $attribs)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/zend-http/library/Zend/Http/Client/Adapter/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down Expand Up @@ -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";
Expand Down
8 changes: 4 additions & 4 deletions packages/zend-mime/library/Zend/Mime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 = '?=';
Expand All @@ -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));
}
Expand Down
6 changes: 3 additions & 3 deletions packages/zend-mime/library/Zend/Mime/Decode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/zend-mime/library/Zend/Mime/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions packages/zend-oauth/library/Zend/Oauth/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion packages/zend-oauth/library/Zend/Oauth/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions packages/zend-oauth/library/Zend/Oauth/Http/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/zend-oauth/library/Zend/Oauth/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/zend-oauth/library/Zend/Oauth/Token/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/zend-oauth/library/Zend/Oauth/Token/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion packages/zend-queue/library/Zend/Queue/Stomp/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aef9d15

Please sign in to comment.