Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
119 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace LeKoala\DevToolkit\Helpers; | ||
|
||
use ReflectionObject; | ||
|
||
class DevUtils | ||
{ | ||
/** | ||
* @param object $obj | ||
* @param string $prop | ||
* @param mixed $val | ||
* @return void | ||
*/ | ||
public static function updateProp(object $obj, string $prop, $val): void | ||
{ | ||
$refObject = new ReflectionObject($obj); | ||
$refProperty = $refObject->getProperty($prop); | ||
$refProperty->setAccessible(true); | ||
$refProperty->setValue($obj, $val); | ||
} | ||
|
||
/** | ||
* @param object $obj | ||
* @param string $prop | ||
* @param callable $cb | ||
* @return void | ||
*/ | ||
public static function updatePropCb(object $obj, string $prop, callable $cb): void | ||
{ | ||
$refObject = new ReflectionObject($obj); | ||
$refProperty = $refObject->getProperty($prop); | ||
$refProperty->setAccessible(true); | ||
$refProperty->setValue($obj, $cb($refProperty->getValue($obj))); | ||
} | ||
|
||
/** | ||
* @param object $obj | ||
* @param string $prop | ||
* @return mixed | ||
*/ | ||
public static function getProp(object $obj, string $prop) | ||
{ | ||
$refObject = new ReflectionObject($obj); | ||
$refProperty = $refObject->getProperty($prop); | ||
$refProperty->setAccessible(true); | ||
return $refProperty->getValue($obj); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters