From 57ec38d1363651a706622053f9fbb609f7879c6e Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 27 Feb 2024 11:36:10 +0800 Subject: [PATCH] MDL-80677 core: Move deprecated attributes to \core\attribute NS Note: Removing the manual require for the attribute from moodlelib because the class does not have to exist at time of definition, only when the Reflection API instantiates an instance in \core\deprecation, by which point the autoloader is available. --- lib/classes/{ => attribute}/deprecated.php | 6 ++---- .../{ => attribute}/deprecated_with_reference.php | 4 ++-- lib/classes/deprecation.php | 3 +++ lib/classes/param.php | 1 + lib/moodlelib.php | 1 - lib/tests/deprecation_test.php | 9 ++++++--- lib/tests/fixtures/deprecated_fixtures.php | 2 +- lib/upgrade.txt | 2 +- 8 files changed, 16 insertions(+), 12 deletions(-) rename lib/classes/{ => attribute}/deprecated.php (97%) rename lib/classes/{ => attribute}/deprecated_with_reference.php (94%) diff --git a/lib/classes/deprecated.php b/lib/classes/attribute/deprecated.php similarity index 97% rename from lib/classes/deprecated.php rename to lib/classes/attribute/deprecated.php index 452f7844f2e..c68317bdf39 100644 --- a/lib/classes/deprecated.php +++ b/lib/classes/attribute/deprecated.php @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -namespace core; - -use Attribute; +namespace core\attribute; /** * Attribute to describe a deprecated item. @@ -25,7 +23,7 @@ use Attribute; * @copyright 2023 Andrew Lyons * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -#[Attribute] +#[\Attribute] class deprecated { /** * A deprecated item. diff --git a/lib/classes/deprecated_with_reference.php b/lib/classes/attribute/deprecated_with_reference.php similarity index 94% rename from lib/classes/deprecated_with_reference.php rename to lib/classes/attribute/deprecated_with_reference.php index 82b1621d7dc..751cd8f111e 100644 --- a/lib/classes/deprecated_with_reference.php +++ b/lib/classes/attribute/deprecated_with_reference.php @@ -14,10 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -namespace core; +namespace core\attribute; /** - * Attribute to describe a deprecated item. + * Attribute to describe a deprecated item which contains a reference to the owning feature. * * @package core * @copyright 2023 Andrew Lyons diff --git a/lib/classes/deprecation.php b/lib/classes/deprecation.php index 47f3e75a6f9..00738d8faa3 100644 --- a/lib/classes/deprecation.php +++ b/lib/classes/deprecation.php @@ -16,6 +16,9 @@ namespace core; +use core\attribute\deprecated; +use core\attribute\deprecated_with_reference; + /** * Deprecation utility. * diff --git a/lib/classes/param.php b/lib/classes/param.php index e6cba152b07..9c817ff4f5b 100644 --- a/lib/classes/param.php +++ b/lib/classes/param.php @@ -18,6 +18,7 @@ namespace core; use coding_exception; use core_text; +use core\attribute\deprecated; use core\ip_utils; use invalid_parameter_exception; use moodle_exception; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 1db650c1cf2..dccf07fc873 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -74,7 +74,6 @@ define('HOURMINS', 60); // We currently include \core\param manually here to avoid broken upgrades. // This may change after the next LTS release as LTS releases require the previous LTS release. require_once(__DIR__ . '/classes/deprecation.php'); -require_once(__DIR__ . '/classes/deprecated.php'); require_once(__DIR__ . '/classes/param.php'); /** diff --git a/lib/tests/deprecation_test.php b/lib/tests/deprecation_test.php index ac0beab12f5..dc0a1721fd0 100644 --- a/lib/tests/deprecation_test.php +++ b/lib/tests/deprecation_test.php @@ -16,15 +16,18 @@ namespace core; +use core\attribute\deprecated; +use core\attribute\deprecated_with_reference; + /** - * Tests for \core\deprecated and \core\deprecation. + * Tests for \core\attribute\sdeprecated and \core\deprecation. * * @package core * @category test * @copyright 2024 Andrew Lyons * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @covers \core\deprecated - * @covers \core\deprecated_with_reference + * @covers \core\attribute\deprecated + * @covers \core\attribute\deprecated_with_reference * @covers \core\deprecation */ class deprecation_test extends \advanced_testcase { diff --git a/lib/tests/fixtures/deprecated_fixtures.php b/lib/tests/fixtures/deprecated_fixtures.php index e3c11beb7ec..699862b3aa7 100644 --- a/lib/tests/fixtures/deprecated_fixtures.php +++ b/lib/tests/fixtures/deprecated_fixtures.php @@ -16,7 +16,7 @@ namespace core\fixtures; -use core\deprecated; +use core\attribute\deprecated; /** * A file containing a variety of fixturs for deprecated attribute tests. diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 10ce896f2a7..e16ebd775ac 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -39,7 +39,7 @@ information provided here is intended especially for developers. * The following callbacks have been migrated to hooks: - before_standard_html_head() -> core\hook\output\standard_head_html_prepend * Deprecated PARAM_ types with the exception of PARAM_CLEAN now emit a deprecation exception. These were all deprecated in Moodle 2.0. -* A new \core\deprecated attribute can be used to more clearly describe deprecated methods. +* A new \core\attribute\deprecated attribute can be used to more clearly describe deprecated methods. * A new \core\deprecation class can be used to inspect for deprecated attributes: - `\core\deprecation::is_deprecated(example::class);` - `\core\deprecation::emit_deprecation_if_present([self::class, 'some_method']);`