Опубликовано: 21 сентября 201213 г Я правильно понимаю концепцию ипс и ООП о передаче регистра из класса в класс? class lofi { public function __construct( ipsRegistry $registry ) { $this->registry = $registry; $this->DB = $this->registry->DB(); ..... } public function init() { $this->skin = new lofi_skin( $this->registry ) } } class lofi_skin { public function __construct( ipsRegistry $registry ) { $this->registry = $registry; $this->DB = $this->registry->DB(); } } $registry = ipsRegistry::instance(); $registry->init(); $lofi = new lofi( $registry ); $lofi->init(); Или можно как-то по другому? :)
Опубликовано: 21 сентября 201213 г Передавать каждый раз не обязательно, ipsRegistry - синглтон. class lofi { public function __construct( ) { $this->registry = ipsRegistry::instance(); $this->DB = $this->registry->DB(); ..... } public function init() { $this->skin = new lofi_skin( ); } } class lofi_skin { public function __construct( ) { $this->registry = ipsRegistry::instance(); $this->DB = $this->registry->DB(); } } // Эта конструкция вызывается один раз на весь скрипт $registry = ipsRegistry::instance(); $registry->init(); // --- $lofi = new lofi(); $lofi->init();
Я правильно понимаю концепцию ипс и ООП о передаче регистра из класса в класс?
class lofi { public function __construct( ipsRegistry $registry ) { $this->registry = $registry; $this->DB = $this->registry->DB(); ..... } public function init() { $this->skin = new lofi_skin( $this->registry ) } } class lofi_skin { public function __construct( ipsRegistry $registry ) { $this->registry = $registry; $this->DB = $this->registry->DB(); } } $registry = ipsRegistry::instance(); $registry->init(); $lofi = new lofi( $registry ); $lofi->init();Или можно как-то по другому? :)