Symfony Mixins – how to extend symfony core classes without inheritance

Symfony is very powerful PHP framework, one of the most popular in the PHP world. In big projects you should probably noticed, that there isn’t easy way to extend core classes, which aren’t returned by factories, for example actions classes. Every generated module has actions.class.php, which inherits from sfActions. What, if we want to have same method in few actions, let’s call it getCurrentDay to achieve effect listed bellow?

class defaultActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $year = $request->getParameter('year', date('Y'));
    $this->day   = $this->getCurrentDay($year);
    $this->month = $this->getCurrentMonth($year);
  }
}
Current day is <strong>Monday 2010</strong>
The month is <strong>February</strong>
Read more