Currently the project uses the YII framework, controller calls the façade method, the façade calls the adapter method, the adapter invokes the API method, the API encapsulates the SQL method, but in most cases it's just a simple call, but limited to the current project's rules, All have to write methods, and the method is simple return, so wrote a demo, simulated the next.
<?php
class Aapi
{public
static function Tt1 ($name, $age)
{
print_r ($name);
echo $age;
}
}
Class Aadapter
{public
function __call ($func, $params)
{
$class = substr (Get_called_class (), 0,-7 ) . ' Api ';
return Call_user_func_array (Array ($class, $func), $params);
}
Class Afacade
{public
static function __callstatic ($func, $params)
{
//can also be used here debug_backtrace ()
$class = substr (Get_called_class (), 0,-6). ' Adapter ';
$obj = new $class ();
return Call_user_func_array (Array ($obj, $func), $params);
}
Class Acontroller
{public
function Actionc ()
{
afacade::tt1 ([' Name '], ' age ');
}
$a = new Acontroller;
$a->actionc ();