Do I need to extend SimpleController?


#1

Quick question…

Do I need to extend SimpleController in my classes? What do I miss if I do?

Reasoning: I want to make some of my controllers/business logic UF-agnostic, so I can develop and unit-test separately, from the rest of the platform.

Thanks


#2

Business logic you should be able to keep separate. Controllers however are unlikely, as they will act as the bridge from the business logic to UF.

That said, it should technically be achievable to an extent for unspecific controllers, compatibility with laravel however would be impossible (different method signitures, etc).


#3

FYI, SimpleController contains the logic for access to the ci ContainerInterface, so if you don’t extends it, you won’t be able to use any services : https://github.com/userfrosting/UserFrosting/blob/develop/app/sprinkles/core/src/Controller/SimpleController.php#L36

In UF 4.2, we’re adding Traits and logic to help test controllers and sprinkles, as well as documentation (coming soon !).

IMO, sprinkles should be tested agains’t the whole UF stacks if you want to make sure it implement correctly in the framework, and it doesn’t break the framework. Of course, if you have standalone classes, it won’t matter.