Skip to content

Commit 73b79d4

Browse files
laoneorichard67
andauthored
Replaces the extension of CMSObject with the legacy traits (#40999)
* Replaces the extension of CMSObject with the legacy traits * Update libraries/src/Changelog/Changelog.php * Fix indexer alias generation * use reflection to detect none public properties * add missing properties --------- Co-authored-by: Richard Fath <[email protected]>
1 parent a1036de commit 73b79d4

File tree

12 files changed

+124
-26
lines changed

12 files changed

+124
-26
lines changed

libraries/src/Adapter/Adapter.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
namespace Joomla\CMS\Adapter;
1111

1212
use Joomla\CMS\Factory;
13-
use Joomla\CMS\Object\CMSObject;
13+
use Joomla\CMS\Object\LegacyErrorHandlingTrait;
14+
use Joomla\CMS\Object\LegacyPropertyManagementTrait;
1415
use Joomla\Database\DatabaseAwareInterface;
1516

1617
// phpcs:disable PSR1.Files.SideEffects
@@ -26,8 +27,11 @@
2627
* @deprecated 4.3 will be removed in 6.0
2728
* Will be removed without replacement
2829
*/
29-
class Adapter extends CMSObject
30+
class Adapter
3031
{
32+
use LegacyErrorHandlingTrait;
33+
use LegacyPropertyManagementTrait;
34+
3135
/**
3236
* Associative array of adapters
3337
*

libraries/src/Adapter/AdapterInstance.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
namespace Joomla\CMS\Adapter;
1111

1212
use Joomla\CMS\Factory;
13-
use Joomla\CMS\Object\CMSObject;
13+
use Joomla\CMS\Object\LegacyErrorHandlingTrait;
14+
use Joomla\CMS\Object\LegacyPropertyManagementTrait;
1415
use Joomla\Database\DatabaseDriver;
1516

1617
// phpcs:disable PSR1.Files.SideEffects
@@ -24,8 +25,11 @@
2425
* @deprecated 4.3 will be removed in 6.0
2526
* Will be removed without replacement
2627
*/
27-
class AdapterInstance extends CMSObject
28+
class AdapterInstance
2829
{
30+
use LegacyErrorHandlingTrait;
31+
use LegacyPropertyManagementTrait;
32+
2933
/**
3034
* Parent
3135
*

libraries/src/Categories/CategoryNode.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
namespace Joomla\CMS\Categories;
1111

1212
use Joomla\CMS\Factory;
13-
use Joomla\CMS\Object\CMSObject;
13+
use Joomla\CMS\Object\LegacyErrorHandlingTrait;
14+
use Joomla\CMS\Object\LegacyPropertyManagementTrait;
1415
use Joomla\CMS\Tree\NodeInterface;
1516
use Joomla\CMS\Tree\NodeTrait;
1617
use Joomla\Registry\Registry;
@@ -24,8 +25,11 @@
2425
*
2526
* @since 1.6
2627
*/
27-
class CategoryNode extends CMSObject implements NodeInterface
28+
#[\AllowDynamicProperties]
29+
class CategoryNode implements NodeInterface
2830
{
31+
use LegacyErrorHandlingTrait;
32+
use LegacyPropertyManagementTrait;
2933
use NodeTrait;
3034

3135
/**

libraries/src/Changelog/Changelog.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
use Joomla\CMS\Http\HttpFactory;
1313
use Joomla\CMS\Language\Text;
1414
use Joomla\CMS\Log\Log;
15-
use Joomla\CMS\Object\CMSObject;
15+
use Joomla\CMS\Object\LegacyErrorHandlingTrait;
16+
use Joomla\CMS\Object\LegacyPropertyManagementTrait;
1617
use Joomla\CMS\Version;
1718
use Joomla\Registry\Registry;
1819
use RuntimeException;
@@ -26,8 +27,11 @@
2627
*
2728
* @since 4.0.0
2829
*/
29-
class Changelog extends CMSObject
30+
class Changelog
3031
{
32+
use LegacyErrorHandlingTrait;
33+
use LegacyPropertyManagementTrait;
34+
3135
/**
3236
* Update manifest `<element>` element
3337
*

libraries/src/Filesystem/Stream.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
namespace Joomla\CMS\Filesystem;
1111

1212
use Joomla\CMS\Language\Text;
13-
use Joomla\CMS\Object\CMSObject;
13+
use Joomla\CMS\Object\LegacyErrorHandlingTrait;
14+
use Joomla\CMS\Object\LegacyPropertyManagementTrait;
1415

1516
// phpcs:disable PSR1.Files.SideEffects
1617
\defined('_JEXEC') or die;
@@ -33,8 +34,11 @@
3334
* @deprecated 4.4 will be removed in 6.0
3435
* Use Joomla\Filesystem\Stream instead.
3536
*/
36-
class Stream extends CMSObject
37+
class Stream
3738
{
39+
use LegacyErrorHandlingTrait;
40+
use LegacyPropertyManagementTrait;
41+
3842
/**
3943
* File Mode
4044
*

libraries/src/Installer/InstallerExtension.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
use Joomla\CMS\Application\ApplicationHelper;
1313
use Joomla\CMS\Language\Text;
1414
use Joomla\CMS\Log\Log;
15-
use Joomla\CMS\Object\CMSObject;
15+
use Joomla\CMS\Object\LegacyErrorHandlingTrait;
16+
use Joomla\CMS\Object\LegacyPropertyManagementTrait;
1617

1718
// phpcs:disable PSR1.Files.SideEffects
1819
\defined('_JEXEC') or die;
@@ -23,8 +24,11 @@
2324
*
2425
* @since 3.1
2526
*/
26-
class InstallerExtension extends CMSObject
27+
class InstallerExtension
2728
{
29+
use LegacyErrorHandlingTrait;
30+
use LegacyPropertyManagementTrait;
31+
2832
/**
2933
* Client ID of the extension
3034
*

libraries/src/MVC/Model/BaseModel.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
use Joomla\CMS\Filesystem\Path;
1313
use Joomla\CMS\Language\Text;
14-
use Joomla\CMS\Object\CMSObject;
14+
use Joomla\CMS\Object\LegacyErrorHandlingTrait;
15+
use Joomla\CMS\Object\LegacyPropertyManagementTrait;
1516

1617
// phpcs:disable PSR1.Files.SideEffects
1718
\defined('_JEXEC') or die;
@@ -22,10 +23,14 @@
2223
*
2324
* @since 4.0.0
2425
*/
25-
abstract class BaseModel extends CMSObject implements ModelInterface, StatefulModelInterface
26+
#[\AllowDynamicProperties]
27+
abstract class BaseModel implements ModelInterface, StatefulModelInterface
2628
{
2729
use StateBehaviorTrait;
2830
use LegacyModelLoaderTrait;
31+
use LegacyErrorHandlingTrait;
32+
use LegacyPropertyManagementTrait;
33+
2934

3035
/**
3136
* The model (base) name

libraries/src/MVC/View/AbstractView.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
use Joomla\CMS\Language\LanguageAwareInterface;
1717
use Joomla\CMS\Language\LanguageAwareTrait;
1818
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
19-
use Joomla\CMS\Object\CMSObject;
19+
use Joomla\CMS\Object\LegacyErrorHandlingTrait;
20+
use Joomla\CMS\Object\LegacyPropertyManagementTrait;
2021
use Joomla\Event\DispatcherAwareInterface;
2122
use Joomla\Event\DispatcherAwareTrait;
2223
use Joomla\Event\DispatcherInterface;
@@ -33,10 +34,16 @@
3334
*
3435
* @since 2.5.5
3536
*/
36-
abstract class AbstractView extends CMSObject implements ViewInterface, DispatcherAwareInterface, DocumentAwareInterface, LanguageAwareInterface
37+
#[\AllowDynamicProperties]
38+
abstract class AbstractView implements ViewInterface, DispatcherAwareInterface, DocumentAwareInterface, LanguageAwareInterface
3739
{
3840
use DispatcherAwareTrait;
3941
use LanguageAwareTrait;
42+
use LegacyErrorHandlingTrait;
43+
use LegacyPropertyManagementTrait {
44+
get as private legacyGet;
45+
}
46+
4047

4148
/**
4249
* The active document object
@@ -154,8 +161,7 @@ public function get($property, $default = null)
154161
}
155162
}
156163

157-
// Degrade to CMSObject::get
158-
return parent::get($property, $default);
164+
return $this->legacyGet($property, $default);
159165
}
160166

161167
/**

libraries/src/Object/LegacyPropertyManagementTrait.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
namespace Joomla\CMS\Object;
1111

12+
use ReflectionObject;
13+
use ReflectionProperty;
14+
1215
// phpcs:disable PSR1.Files.SideEffects
1316
\defined('_JEXEC') or die;
1417
// phpcs:enable PSR1.Files.SideEffects
@@ -93,6 +96,24 @@ public function getProperties($public = true)
9396
unset($vars[$key]);
9497
}
9598
}
99+
100+
// Collect all none public properties of the current class and it's parents
101+
$nonePublicProperties = [];
102+
$reflection = new ReflectionObject($this);
103+
do {
104+
$nonePublicProperties = array_merge(
105+
$reflection->getProperties(ReflectionProperty::IS_PRIVATE | ReflectionProperty::IS_PROTECTED),
106+
$nonePublicProperties
107+
);
108+
} while ($reflection = $reflection->getParentClass());
109+
110+
// Unset all none public properties, this is needed as get_object_vars returns now all vars
111+
// from the current object and not only the CMSObject and the public ones from the inheriting classes
112+
foreach ($nonePublicProperties as $prop) {
113+
if (array_key_exists($prop->getName(), $vars)) {
114+
unset($vars[$prop->getName()]);
115+
}
116+
}
96117
}
97118

98119
return $vars;

libraries/src/Table/Table.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
use Joomla\CMS\Factory;
1515
use Joomla\CMS\Filesystem\Path;
1616
use Joomla\CMS\Language\Text;
17-
use Joomla\CMS\Object\CMSObject;
17+
use Joomla\CMS\Object\LegacyErrorHandlingTrait;
18+
use Joomla\CMS\Object\LegacyPropertyManagementTrait;
1819
use Joomla\Database\DatabaseDriver;
1920
use Joomla\Database\DatabaseQuery;
2021
use Joomla\Event\DispatcherAwareInterface;
@@ -34,9 +35,12 @@
3435
* @since 1.7.0
3536
*/
3637
#[\AllowDynamicProperties]
37-
abstract class Table extends CMSObject implements TableInterface, DispatcherAwareInterface
38+
abstract class Table implements TableInterface, DispatcherAwareInterface
3839
{
3940
use DispatcherAwareTrait;
41+
use LegacyErrorHandlingTrait;
42+
use LegacyPropertyManagementTrait;
43+
4044

4145
/**
4246
* Include paths for searching for Table classes.
@@ -164,8 +168,6 @@ abstract class Table extends CMSObject implements TableInterface, DispatcherAwar
164168
*/
165169
public function __construct($table, $key, DatabaseDriver $db, DispatcherInterface $dispatcher = null)
166170
{
167-
parent::__construct();
168-
169171
// Set internal variables.
170172
$this->_tbl = $table;
171173

0 commit comments

Comments
 (0)