Skip to content

Commit

Permalink
View: override Zend/View/Abstract's dynamic property management
Browse files Browse the repository at this point in the history
Store dynamic properties in an array.
W/o this the login page, if on PHP 8.2, says:

Deprecated: Creation of dynamic property Icinga\Web\View::$defaultTitle is deprecated in /usr/share/icingaweb2/library/vendor/Zend/View/Abstract.php on line 305
Deprecated: Creation of dynamic property Icinga\Web\View::$compact is deprecated in /usr/share/icingaweb2/library/vendor/Zend/View/Abstract.php on line 305
Deprecated: Creation of dynamic property Icinga\Web\View::$tabs is deprecated in /usr/share/icingaweb2/library/vendor/Zend/View/Abstract.php on line 305

W/o View#getVars() the login page says:

Fatal error: Uncaught ErrorException: Uncaught ErrorException: Undefined variable $hideControls in /usr/share/icingaweb2/application/views/scripts/error/error.phtml:1
  • Loading branch information
Al2Klimov committed Sep 21, 2022
1 parent 157ca19 commit 1e821ec
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion library/Icinga/Web/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

namespace Icinga\Web;

use ArrayIterator;
use Closure;
use Icinga\Application\Icinga;
use ipl\I18n\Translation;
use IteratorAggregate;
use Zend_View_Abstract;
use Icinga\Authentication\Auth;
use Icinga\Exception\ProgrammingError;
Expand Down Expand Up @@ -52,7 +54,7 @@
* @param string $value
* }
*/
class View extends Zend_View_Abstract
class View extends Zend_View_Abstract implements IteratorAggregate
{
use Translation;

Expand All @@ -61,6 +63,11 @@ class View extends Zend_View_Abstract
*/
const CHARSET = 'UTF-8';

/**
* @var array
*/
private $dynamicProperties = [];

/**
* Registered helper functions
*/
Expand All @@ -86,6 +93,51 @@ public function __construct($config = array())
parent::__construct($config);
}

public function __set($key, $val): void
{
if ('_' != substr($key, 0, 1)) {
$this->dynamicProperties[$key] = $val;

return;
}

// trigger exception
parent::__set($key, $val);
}

public function __get($key)
{
return array_key_exists($key, $this->dynamicProperties)
? $this->dynamicProperties[$key]
: parent::__get($key); // trigger error
}

public function __isset($key): bool
{
if ('_' != substr($key, 0, 1)) {
return isset($this->dynamicProperties[$key]);
}

return false;
}

public function __unset($key): void
{
if ('_' != substr($key, 0, 1) && isset($this->dynamicProperties[$key])) {
unset($this->dynamicProperties[$key]);
}
}

public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->dynamicProperties);
}

public function getVars(): array
{
return $this->dynamicProperties;
}

/**
* Initialize the view
*
Expand Down

0 comments on commit 1e821ec

Please sign in to comment.