![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/app/code/Amasty/Label/Test/Unit/Traits/ |
<?php /** * @author Amasty Team * @copyright Copyright (c) Amasty (https://www.amasty.com) * @package Product Labels for Magento 2 */ namespace Amasty\Label\Test\Unit\Traits; /** * Provide useful methods with reflection. * * phpcs:ignoreFile */ trait ReflectionTrait { /** * @param object $object * @param string $methodName * @param array $parameters * * @return mixed * @throws \ReflectionException */ private function invokeMethod($object, $methodName, array $parameters = []) { $reflection = new \ReflectionClass(get_class($object)); $method = $reflection->getMethod($methodName); $method->setAccessible(true); return $method->invokeArgs($object, $parameters); } /** * @param object $object * @param string $propertyName * @param mixed $value * @param string $origClassName * * @return object * @throws \ReflectionException */ private function setProperty($object, $propertyName, $value, $origClassName = '') { $reflection = new \ReflectionClass($origClassName ?: get_class($object)); $property = $reflection->getProperty($propertyName); $property->setAccessible(true); $property->setValue($object, $value); return $object; } /** * @param $object * @param $propertyName * @return object * @throws \ReflectionException */ private function getProperty($object, $propertyName, $origClassName = '') { $reflection = new \ReflectionClass($origClassName ?: get_class($object)); $property = $reflection->getProperty($propertyName); $property->setAccessible(true); return $property->getValue($object); } }