2014-11-11 17:11:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Amp;
|
|
|
|
|
2015-01-29 04:30:02 +01:00
|
|
|
/**
|
2015-04-03 17:56:16 +02:00
|
|
|
* A "safe" struct trait for public property aggregators
|
2015-02-05 18:17:05 +01:00
|
|
|
*
|
2015-04-03 17:56:16 +02:00
|
|
|
* This trait is intended to make using public properties a little safer by throwing when
|
|
|
|
* nonexistent property names are read or written.
|
2015-01-29 04:30:02 +01:00
|
|
|
*/
|
2015-04-03 17:56:16 +02:00
|
|
|
trait Struct {
|
2014-11-11 17:11:58 +01:00
|
|
|
final public function __get($property) {
|
|
|
|
throw new \DomainException(
|
2015-04-03 17:56:16 +02:00
|
|
|
$this->generateStructPropertyError($property)
|
2014-11-11 17:11:58 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function __set($property, $value) {
|
|
|
|
throw new \DomainException(
|
2015-04-03 17:56:16 +02:00
|
|
|
$this->generateStructPropertyError($property)
|
2014-11-11 17:11:58 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-03 17:56:16 +02:00
|
|
|
private function generateStructPropertyError($property) {
|
2014-11-11 17:11:58 +01:00
|
|
|
return sprintf("Struct property %s::%s does not exist", get_class($this), $property);
|
|
|
|
}
|
|
|
|
}
|