Skip to content

Commit

Permalink
updated PushHttpProxy for dynamic properties in PHP 8.2 and later
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketMan committed Dec 31, 2023
1 parent 39afe7b commit 8365706
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
7 changes: 7 additions & 0 deletions custom/PushHttpProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace ZK\PushNotification;

use ZK\Controllers\NowAiringServer;
use ZK\Engine\DynamicPropertyTrait;

use Ratchet\RFC6455\Messaging\Frame;

Expand Down Expand Up @@ -73,6 +74,12 @@ class PushHttpProxy {
protected $httpEndpoints;
protected $current;

/**
* Support dynamic properties specifically for use by the 'filter'
* function (see above).
*/
use DynamicPropertyTrait;

public function __construct(\React\EventLoop\LoopInterface $loop) {
$this->loop = $loop;
$this->subscriber = new \Ratchet\Client\Connector($loop);
Expand Down
58 changes: 58 additions & 0 deletions engine/DynamicPropertyTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Zookeeper Online
*
* @author Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2023 Jim Mason <[email protected]>
* @link https://zookeeper.ibinx.com/
* @license GPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* version 3, along with this program. If not, see
* http://www.gnu.org/licenses/
*
*/

namespace ZK\Engine;

/**
* DynamicPropertyTrait implements dynamic properties for a class.
*
* Automatic dynamic properties are deprecated as of PHP 8.2;
* see: https://www.php.net/manual/en/migration82.deprecated.php
*
* This trait adds support for dynamic properties to any class,
* for any version of PHP.
*/
trait DynamicPropertyTrait {
protected $propertyMap = [];

public function __isset($var) {
return key_exists($var, $this->propertyMap);
}

public function __get($var) {
if(key_exists($var, $this->propertyMap))
return $this->propertyMap[$var];

$shortName = (new \ReflectionClass($this))->getShortName();
trigger_error("Undefined property $shortName::$var", E_USER_WARNING);
}

public function __set($var, $val) {
$this->propertyMap[$var] = $val;
}

public function __unset($var) {
unset($this->propertyMap[$var]);
}
}

0 comments on commit 8365706

Please sign in to comment.