Created
July 6, 2015 13:24
-
-
Save onatskyy/14902cc7977024e09816 to your computer and use it in GitHub Desktop.
WriteAttributeExtensionTrait
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
trait WriteAttributeExtensionTrait | |
{ | |
/** | |
* @param string|object $classOrObject | |
* @param string $attributeName | |
* @param mixed $attributeValue | |
*/ | |
public function writeAttribute($classOrObject, $attributeName, $attributeValue) | |
{ | |
$rp = new \ReflectionProperty($classOrObject, $attributeName); | |
$rp->setAccessible(true); | |
$rp->setValue($classOrObject, $attributeValue); | |
$rp->setAccessible(false); | |
} | |
/** | |
* @param string|object $classOrObject | |
* @param mixed $attributeValue | |
*/ | |
public function writeIdAttribute($classOrObject, $attributeValue) | |
{ | |
$this->writeAttribute($classOrObject, 'id', $attributeValue); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment