From 6c364e3002222788054d07ac528cb6490878292a Mon Sep 17 00:00:00 2001 From: Yoan-Alexander Grigorov Date: Fri, 2 Feb 2024 13:19:07 +0100 Subject: [PATCH] :sparkles: Added trait for accessing values of private properties --- src/Support/GetPrivatePropertyValue.php | 24 +++++++++++++++ tests/Support/GetPrivatePropertyValueTest.php | 29 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/Support/GetPrivatePropertyValue.php create mode 100644 tests/Support/GetPrivatePropertyValueTest.php diff --git a/src/Support/GetPrivatePropertyValue.php b/src/Support/GetPrivatePropertyValue.php new file mode 100644 index 0000000..8ab870a --- /dev/null +++ b/src/Support/GetPrivatePropertyValue.php @@ -0,0 +1,24 @@ +getProperty($property); + /** @noinspection PhpExpressionResultUnusedInspection */ + $propertyReflection->setAccessible(true); + + return $propertyReflection->getValue($object); + } +} diff --git a/tests/Support/GetPrivatePropertyValueTest.php b/tests/Support/GetPrivatePropertyValueTest.php new file mode 100644 index 0000000..e8250b7 --- /dev/null +++ b/tests/Support/GetPrivatePropertyValueTest.php @@ -0,0 +1,29 @@ +getPrivatePropertyValue($object, 'property')); + } +}