我正在建立一个ADR框架,我希望能够执行某些规则以确保遵守ADR原则。
__construct
,__invoke
,respond
构造器是可选的。关于如何实现这一目标的任何想法?
发布于 2018-09-28 17:04:39
这段代码并不能完全满足要求, 但我认为它可以让您了解如何完成。
class Aroot
{
// Parent constructor
public function __construct ()
{
if (strtolower(get_class($this)) != 'aroot') {
$allowed_publics = ['__construct', '__invoke', 'respond'];
$exst_methods = get_class_methods($this);
if (!in_array('__invoke', $exst_methods)) {
echo "__invoke method is missing.\n";
}
if (!in_array('respond', $exst_methods)) {
echo "respond method is missing.\n";
}
foreach ($exst_methods as $method_name) {
if (!in_array($method_name, $allowed_publics)) {
echo "Not allowed public method $method_name \n";
}
}
}
// check private method names
if (method_exists($this, 'prohib_prv')) {
echo "Method prohib_prv should not exist.\n";
}
}
}
class Bbranch extends Aroot
{
public function prohib()
{
}
private function prohib_prv()
{
}
protected function prohib_prt()
{
}
}
$bbranch_obj = new Bbranch;
$aroot = new Aroot;
https://stackoverflow.com/questions/-100002784
复制相似问题