Traits were added in PHP 5.4 and allows to make great decisions, when it comes to improving application architecture.
From In-Portal perspective traits look like regular classes, that can be:
- registered within a factory
- use in other traits/classes (file containing used trait will be automatically loaded)
Although I've noticed a side effect, which leads to "Trait '.....' not found" fatal error, when rebuilding unit config cache (that happens also on the deploy) in case if a newly added trait is used in the sub-class of
UsersEventHandler class. Also it wasn't clear how that class is invoked in deployment process. This is what happened:
- the "adm:OnStartup" event was fired as part of "kApplication::Init" method call
- one of the hooks to that event was "u:OnAutoLoginUser" event
- that resulted in "UsersEventHandler" class (or it's sub-class, when available) being included
- that triggered new trait lookup
All that was happening before new unit config cache (that contained that trait location on disk) was saved to db/memcache.
- introduce "full_init" flag in URL (enabled by default, but not visible in any url)
- when present call the "adm:OnStartup" event
- pass "full_init=0" flag value when:
- doing deploy (from CLI and WEB)
- doing any other action from "Tools > System Tools" section