1
0
mirror of https://github.com/danog/amp.git synced 2025-01-08 05:58:22 +01:00
amp/lib/Struct.php

28 lines
733 B
PHP
Raw Normal View History

2014-11-11 17:11:58 +01:00
<?php
namespace Amp;
/**
* A "safe" struct trait for public property aggregators
2015-02-05 18:17:05 +01:00
*
* This trait is intended to make using public properties a little safer by throwing when
* nonexistent property names are read or written.
*/
trait Struct {
2014-11-11 17:11:58 +01:00
final public function __get($property) {
throw new \DomainException(
$this->generateStructPropertyError($property)
2014-11-11 17:11:58 +01:00
);
}
final public function __set($property, $value) {
throw new \DomainException(
$this->generateStructPropertyError($property)
2014-11-11 17:11:58 +01: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);
}
}