Skip navigation.

My pasteblog

This is not my Zettelkasten but a durable .bash_history

Wednesday, 11. November 2009

symfony sfguarduser profile methods

http://devfactor.blogspot.com/2009/11/law-of-demeter.html

Most of the Symfony projects I’ve worked on are rife with lines of code like this (in the actions):

$this->getUser()->getGuardUser()->getProfile()->getEmail()

To conform to the above ideals (The Law Of Demeter) the code should be re-written as:

$this->getUser()->getEmail()


public function __call($method, $arguments)
 { 
  if(is_array($arguments))
  {
   return call_user_func_array(array($this->getGuardUser()->getProfile(), $method), $arguments);
  }
  else
  {
   return $this->getGuardUser()->getProfile()->$method();
  }
 }
November 2009
S M T W T F S
October 2009December 2009
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30