Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Context] Czy to taka konstrukcja nie łamie założeń?
starach
post
Post #1





Grupa: Zarejestrowani
Postów: 999
Pomógł: 30
Dołączył: 14.01.2007
Skąd: wiesz ?

Ostrzeżenie: (0%)
-----


Wykombinowałem sobie żeby inicjalizacja Context'u wyglądała następującą:
  1. <?php
  2. $c = new Context();
  3. $c->Router(new Router());
  4. $c->Loader(Loader::createInstance()->setRouter($c->Router()));
  5. ?>
Czy nie łamie to ogólnie przyjętych zasad?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
wookieb
post
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




O jakie zasady ci chodzi?
Go to the top of the page
+Quote Post
starach
post
Post #3





Grupa: Zarejestrowani
Postów: 999
Pomógł: 30
Dołączył: 14.01.2007
Skąd: wiesz ?

Ostrzeżenie: (0%)
-----


Cytat(wookieb @ 7.06.2009, 21:53:55 ) *
O jakie zasady ci chodzi?
Chociażby właśnie o to co napisał phpion (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)
  1. <?php
  2. class Context
  3. {
  4.    private $aObjects = array();
  5.    public function Loader(LoaderInterface $l = null)
  6.    {
  7.        if($l !== null) {
  8.            $this->setObject($l, 'LoaderInterface');
  9.        } else {
  10.            return $this->getObject('LoaderInterface');
  11.        }
  12.    }
  13.    public function Router(RouterInterface $r = null)
  14.    {
  15.        if($r !== null)    {
  16.            $this->setObject($r, 'RouterInterface');
  17.        } else {
  18.            return $this->getObject('RouterInterface');
  19.        }
  20.    }
  21.    public function getObject($class)
  22.    {
  23.        if(!isset($this->aObjects[$class])) {
  24.            throw new Error('context.objectnotfound', array('class' => $class));
  25.        }
  26.        return $this->aObjects[$class];
  27.    }
  28.    public function setObject($object, $id = null)
  29.    {
  30.        if(method_exists($object, 'setContext'))
  31.        {
  32.            $object->setContext($this);
  33.        }
  34.        $class = $id !== null ? $id : get_class($object);
  35.        $this->aObjects[$class] = $object;
  36.    }
  37. }
  38. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 13.10.2025 - 19:34