php - singleton nasty object, unable to use other objects -
i'm trying use singleton design pattern create object , consume it.
first have system class [the factory] object
system class
class system { public function require_($file) { if( file_exists($file) ){ require( $file ) ; }else{ $this -> config_erros['require'][] = $file ; } } public function call($object , $object_name = '') { if( $object_name == '' ) { return $this -> {$object} = new $object() ; }else{ return $this -> {$object_name} = new $object() ; } } public function __autoload($class , $object_name = '') { if( is_array( $class ) && !empty( $class ) ) { $class = array_unique($class) ; foreach( $class $f ) { $this -> require_( classes_path . $class .'.php' ) ; $this -> call( $class , $object_name ) ; } }else{ $this -> require_( classes_path . $class .'.php' ) ; $this -> call( $class , $object_name ) ; } } }
i have 3 classes:
mysqly.php => class mysqly files.php => class files image.php => class image
here calling classes:
$system = new system ; $system -> __auto_load( array('mysqly','files','image') ) ;
now in system object can use as
$system -> mysqly -> query () ; // call function in mysqly class $system -> files -> read () ; // call function in files class $system -> image -> query () ; // call function in image class
as of every thing working fine.
level 2 [ define users module object in system object ]
now want add users class [ users module ] system object
here users class:
class users implements module { public function install(){ $system -> mysqly -> exec( ' create table `users` ( `id` int(11) not null auto_increment, `name` varchar(150) null, `username` varchar(50) not null, `password` varchar(32) not null, `email` varchar(32) not null, `group` int(11) not null, `register_date` int(10) not null, `last_login` int(10) default null, `active_code` varchar(32) not null, `reset_code` varchar(32) default null, `session_code` varchar(32) default null, `status` varchar(2) not null, primary key (`id`), unique key `email` (`email`), key `username` (`username`,`password`,`group`,`status`) ) engine=innodb default charset=utf8 ') ; } public function uninstall(){} public function update(){} public function close(){} }
i generate this
$system -> require_( module_path.'users.php' ) ; $system -> call ( 'users' ) ;
this fine want execute users function [ install ]
i can achieve follows:
$system -> users -> install() ;
here's problem
i want execute mysql query [ use mysqly object on system object ]
but how can execute query depended on mysqly object in system object?
thank you
Comments
Post a Comment