Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/remove PHP 8.2 depreciation messages #397

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
122 changes: 64 additions & 58 deletions library/Zend/Controller/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
abstract class Zend_Controller_Action implements Zend_Controller_Action_Interface
{
/**
* @var array of existing class methods
* @var array|null array of existing class methods
*/
protected $_classMethods;
protected $_classMethods = null;

/**
* Word delimiters (used for normalizing view script paths)
* @var array
* @var array|null
*/
protected $_delimiters;
protected $_delimiters = null;

/**
* Array of arguments provided to the constructor, minus the
Expand Down Expand Up @@ -93,9 +93,9 @@ abstract class Zend_Controller_Action implements Zend_Controller_Action_Interfac

/**
* Compatibility for php 8.2 to stop error Deprecated: Creation of dynamic property
* @var object
* @var object|null
*/
public $contexts = null;
public $contexts = null;

/**
* Helper Broker to assist in routing help requests to the proper object
Expand Down Expand Up @@ -206,16 +206,17 @@ public function initView()
* By default, the rendered contents are appended to the response. You may
* specify the named body content segment to set by specifying a $name.
*
* @see Zend_Controller_Response_Abstract::appendBody()
* @param string|null $action Defaults to action registered in request object
* @param string|null $name Response object named path segment to use; defaults to null
* @param bool $noController Defaults to false; i.e. use controller name as subdir in which to search for view script
* @param string|null $action Defaults to action registered in request object
* @param string|null $name Response object named path segment to use; defaults to null
* @param bool $noController Defaults to false; i.e. use controller name as subdir in which to search for view script
* @return void
* @throws Zend_Controller_Exception
* @see Zend_Controller_Response_Abstract::appendBody()
*/
public function render($action = null, $name = null, $noController = false)
public function render(?string $action = null, ?string $name = null, bool $noController = false)
{
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
return $this->_helper->viewRenderer->render($action, $name, $noController);
$this->_helper->viewRenderer->render($action, $name, $noController);
krytenuk marked this conversation as resolved.
Show resolved Hide resolved
}

$view = $this->initView();
Expand All @@ -239,14 +240,15 @@ public function render($action = null, $name = null, $noController = false)
* By default, the rendered contents are appended to the response. You may
* specify the named body content segment to set by specifying a $name.
*
* @param string $script
* @param string $name
* @param string $script
* @param string|null $name
* @return void
* @throws Zend_Controller_Exception
*/
public function renderScript($script, $name = null)
public function renderScript(string $script, string $name = null)
{
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
return $this->_helper->viewRenderer->renderScript($script, $name);
$this->_helper->viewRenderer->renderScript($script, $name);
}

$view = $this->initView();
Expand All @@ -261,12 +263,12 @@ public function renderScript($script, $name = null)
*
* Used by render() to determine the path to the view script.
*
* @param string $action Defaults to action registered in request object
* @param bool $noController Defaults to false; i.e. use controller name as subdir in which to search for view script
* @param string|null $action Defaults to action registered in request object
* @param bool|null $noController Defaults to false; i.e. use controller name as subdir in which to search for view script
* @return string
* @throws Zend_Controller_Exception with bad $action
*/
public function getViewScript($action = null, $noController = null)
public function getViewScript(?string $action = null, ?bool $noController = null): string
{
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
$viewRenderer = $this->_helper->getHelper('viewRenderer');
Expand All @@ -279,6 +281,7 @@ public function getViewScript($action = null, $noController = null)
$request = $this->getRequest();
if (null === $action) {
$action = $request->getActionName();

} elseif (!is_string($action)) {
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Exception('Invalid action specifier for view render');
Expand Down Expand Up @@ -308,7 +311,7 @@ public function getViewScript($action = null, $noController = null)
*
* @return Zend_Controller_Request_Abstract
*/
public function getRequest()
public function getRequest(): ?Zend_Controller_Request_Abstract
{
return $this->_request;
}
Expand All @@ -317,9 +320,9 @@ public function getRequest()
* Set the Request object
*
* @param Zend_Controller_Request_Abstract $request
* @return $this
* @return Zend_Controller_Action
krytenuk marked this conversation as resolved.
Show resolved Hide resolved
*/
public function setRequest(Zend_Controller_Request_Abstract $request)
public function setRequest(Zend_Controller_Request_Abstract $request): Zend_Controller_Action
{
$this->_request = $request;
return $this;
Expand All @@ -330,7 +333,7 @@ public function setRequest(Zend_Controller_Request_Abstract $request)
*
* @return Zend_Controller_Response_Abstract
*/
public function getResponse()
public function getResponse(): ?Zend_Controller_Response_Abstract
{
return $this->_response;
}
Expand All @@ -339,9 +342,9 @@ public function getResponse()
* Set the Response object
*
* @param Zend_Controller_Response_Abstract $response
* @return $this
* @return Zend_Controller_Action
*/
public function setResponse(Zend_Controller_Response_Abstract $response)
public function setResponse(Zend_Controller_Response_Abstract $response): Zend_Controller_Action
{
$this->_response = $response;
return $this;
Expand All @@ -351,9 +354,9 @@ public function setResponse(Zend_Controller_Response_Abstract $response)
* Set invocation arguments
*
* @param array $args
* @return $this
* @return Zend_Controller_Action
*/
protected function _setInvokeArgs(array $args = [])
protected function _setInvokeArgs(array $args = []): Zend_Controller_Action
{
$this->_invokeArgs = $args;
return $this;
Expand All @@ -364,7 +367,7 @@ protected function _setInvokeArgs(array $args = [])
*
* @return array
*/
public function getInvokeArgs()
public function getInvokeArgs(): array
{
return $this->_invokeArgs;
}
Expand All @@ -375,7 +378,7 @@ public function getInvokeArgs()
* @param string $key
* @return mixed
*/
public function getInvokeArg($key)
public function getInvokeArg(string $key)
{
if (isset($this->_invokeArgs[$key])) {
return $this->_invokeArgs[$key];
Expand All @@ -387,21 +390,21 @@ public function getInvokeArg($key)
/**
* Get a helper by name
*
* @param string $helperName
* @param string $helperName
* @return Zend_Controller_Action_Helper_Abstract
*/
public function getHelper($helperName)
public function getHelper(string $helperName): Zend_Controller_Action_Helper_Abstract
{
return $this->_helper->{$helperName};
}

/**
* Get a clone of a helper by name
*
* @param string $helperName
* @param string $helperName
* @return Zend_Controller_Action_Helper_Abstract
*/
public function getHelperCopy($helperName)
public function getHelperCopy(string $helperName): Zend_Controller_Action_Helper_Abstract
{
return clone $this->_helper->{$helperName};
}
Expand All @@ -410,9 +413,9 @@ public function getHelperCopy($helperName)
* Set the front controller instance
*
* @param Zend_Controller_Front $front
* @return $this
* @return Zend_Controller_Action
*/
public function setFrontController(Zend_Controller_Front $front)
public function setFrontController(Zend_Controller_Front $front): Zend_Controller_Action
{
$this->_frontController = $front;
return $this;
Expand All @@ -422,8 +425,9 @@ public function setFrontController(Zend_Controller_Front $front)
* Retrieve Front Controller
*
* @return Zend_Controller_Front
* @throws Zend_Controller_Exception
*/
public function getFrontController()
public function getFrontController(): Zend_Controller_Front
{
// Used cache version if found
if (null !== $this->_frontController) {
Expand Down Expand Up @@ -478,12 +482,12 @@ public function postDispatch()
* overridden to implement magic (dynamic) actions, or provide run-time
* dispatching.
*
* @param string $methodName
* @param array $args
* @param string $methodName
* @param array $args
* @return void
* @throws Zend_Controller_Action_Exception
*/
public function __call($methodName, $args)
public function __call(string $methodName, array $args)
{
require_once 'Zend/Controller/Action/Exception.php';
if ('Action' == substr($methodName, -6)) {
Expand All @@ -499,6 +503,7 @@ public function __call($methodName, $args)
*
* @param string $action Method name of action
* @return void
* @throws Zend_Controller_Action_Exception
*/
public function dispatch($action)
{
Expand Down Expand Up @@ -551,8 +556,9 @@ public function dispatch($action)
* @param null|Zend_Controller_Response_Abstract $response Optional response
* object to use
* @return Zend_Controller_Response_Abstract
* @throws Zend_Controller_Action_Exception
*/
public function run(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null)
public function run(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null): ?Zend_Controller_Response_Abstract
{
if (null !== $request) {
$this->setRequest($request);
Expand Down Expand Up @@ -587,7 +593,7 @@ public function run(Zend_Controller_Request_Abstract $request = null, Zend_Contr
* @param mixed $default
* @return mixed
*/
protected function _getParam($paramName, $default = null)
protected function _getParam(string $paramName, $default = null)
{
return $this->getParam($paramName, $default);
}
Expand All @@ -603,7 +609,7 @@ protected function _getParam($paramName, $default = null)
* @param mixed $default
* @return mixed
*/
public function getParam($paramName, $default = null)
public function getParam(string $paramName, $default = null)
{
$value = $this->getRequest()->getParam($paramName);
if ((null === $value || '' === $value) && (null !== $default)) {
Expand All @@ -622,7 +628,7 @@ public function getParam($paramName, $default = null)
* @deprecated Deprecated as of Zend Framework 1.7. Use
* setParam() instead.
*/
protected function _setParam($paramName, $value)
protected function _setParam(string $paramName, $value): Zend_Controller_Action
{
return $this->setParam($paramName, $value);
}
Expand All @@ -634,7 +640,7 @@ protected function _setParam($paramName, $value)
* @param mixed $value
* @return $this
*/
public function setParam($paramName, $value)
public function setParam(string $paramName, $value): Zend_Controller_Action
{
$this->getRequest()->setParam($paramName, $value);

Expand All @@ -650,7 +656,7 @@ public function setParam($paramName, $value)
* @deprecated Deprecated as of Zend Framework 1.7. Use
* hasParam() instead.
*/
protected function _hasParam($paramName)
protected function _hasParam(string $paramName): bool
{
return $this->hasParam($paramName);
}
Expand All @@ -662,7 +668,7 @@ protected function _hasParam($paramName)
* @param string $paramName
* @return boolean
*/
public function hasParam($paramName)
public function hasParam(string $paramName): bool
{
return null !== $this->getRequest()->getParam($paramName);
}
Expand All @@ -675,7 +681,7 @@ public function hasParam($paramName)
* @deprecated Deprecated as of Zend Framework 1.7. Use
* getAllParams() instead.
*/
protected function _getAllParams()
protected function _getAllParams(): array
{
return $this->getAllParams();
}
Expand All @@ -686,7 +692,7 @@ protected function _getAllParams()
*
* @return array
*/
public function getAllParams()
public function getAllParams(): array
{
return $this->getRequest()->getParams();
}
Expand All @@ -713,14 +719,14 @@ public function getAllParams()
* simply pass null values for them before specifying the parameters.
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @param string|null $controller
* @param string|null $module
* @param array|null $params
* @return void
* @deprecated Deprecated as of Zend Framework 1.7. Use
* forward() instead.
*/
final protected function _forward($action, $controller = null, $module = null, array $params = null)
final protected function _forward(string $action, ?string $controller = null, ?string $module = null, array $params = null): void
{
$this->forward($action, $controller, $module, $params);
}
Expand All @@ -746,12 +752,12 @@ final protected function _forward($action, $controller = null, $module = null, a
* simply pass null values for them before specifying the parameters.
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @param string|null $controller
* @param string|null $module
* @param array|null $params
* @return void
*/
final public function forward($action, $controller = null, $module = null, array $params = null)
final public function forward(string $action, ?string $controller = null, ?string $module = null, array $params = null): void
{
$request = $this->getRequest();

Expand Down Expand Up @@ -783,7 +789,7 @@ final public function forward($action, $controller = null, $module = null, array
* @deprecated Deprecated as of Zend Framework 1.7. Use
* redirect() instead.
*/
protected function _redirect($url, array $options = [])
protected function _redirect(string $url, array $options = []): void
{
$this->redirect($url, $options);
}
Expand All @@ -797,7 +803,7 @@ protected function _redirect($url, array $options = [])
* @param array $options Options to be used when redirecting
* @return void
*/
public function redirect($url, array $options = [])
public function redirect(string $url, array $options = []): void
{
$this->_helper->redirector->gotoUrl($url, $options);
}
Expand Down
Loading
Loading