Skip navigation.

My pasteblog

This is not my Zettelkasten but a durable .bash_history

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();
  }
 }

Radiofeature: "Meine Ohren und ich"

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.

January 2010
S M T W T F S
December 2009February 2010
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