我正在制作一个PHP软件,为了运行需要实例化一堆类,如下所示:
$database = new Database; //handle some kind of CRUD
$someFunctions = new SomeFunction($database); //injecting the CRUD
$someMoreFunctions = new SomeMoreFunctions($database, someFunctions);
$evenMoreFunctions = new EvenMoreFunctions($database);
$app = new AppManager($someFunctions, someMoreFunctions, evenMoreFunctions);
.............
$app->oneFunction()->doSomething->doSomeMore(); //working with the app
我最终将必须将类的所有实例化放在单独的文件或类中以包含或实例化。目标是使用应用程序使所有实例化对开发人员透明。
我认为最好的方法是用户必须做这样的事情:
$app = App::oneFunction($maybeARecordId);
$app->doSomething();
$app->doSomeMore();
$app->maybeASaveFunction();
有关于如何做到这一点的最佳做法吗?
感谢。