Skip to content

Instantly share code, notes, and snippets.

@onatskyy
Created July 6, 2015 13:24
Show Gist options
  • Save onatskyy/14902cc7977024e09816 to your computer and use it in GitHub Desktop.
Save onatskyy/14902cc7977024e09816 to your computer and use it in GitHub Desktop.
WriteAttributeExtensionTrait
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