Having the option of customized classes but a unified class name

后端 未结 5 2002
甜味超标
甜味超标 2021-01-02 21:35

Suppose you are building a web application that is going to be a packaged product one day, one that users will want to be able to extend and customize.

It comes with

5条回答
  •  难免孤独
    2021-01-02 22:10

    I think it's more complicated with a single filename when you want to use inheritance as well. Basically class user_frontend extends core_frontend has to know where to find both classes. Both must be included.

    If you just want to do new Frontend you could use PHP5.3's class_alias to point Frontend to the main class to use. Below 5.3. you could use a ServiceFinder, that knows how to map Service Names to Classes and then get the Frontend with $service->get('frontend') or use a Dependency Injection framework.

    Edit I removed the Loader code given before, because it was suffering from exactly this problem.

提交回复
热议问题