note 34487 added to language.oop

From: Date: Mon, 28 Jul 2003 23:46:31 +0000
Subject: note 34487 added to language.oop
Groups: php.notes 
Request: Send a blank email to php-notes+get-52874@lists.php.net to get a copy of this message
Here's an example of how I use the Factory Pattern and dynamic class loading & instantiation (note that I'm useing the forcetype trick to encode the resource requested in the URL as part of the path): <?php class Factory { var $pcon; var $qstr = "select ClassName,ClassFile from Resources inner join ResourceTypes on Resources.ResourceType = ResourceTypes.id where ResourceName='%s';"; function Factory(){ $this->pcon = pg_pconnect("dbname=RCMS"); } function Generate(){ $urlArray = explode("/",$_SERVER["REQUEST_URI"]); $tmp = explode("?",$urlArray[2]); $resource = $tmp[0]; $qr = pg_query( $this->pcon, sprintf($this->qstr,pg_escape_string($resource)) ); if($ra = pg_fetch_row($qr)){ require($ra[1]); return new $ra[0](pg_escape_string($resource),$this->pcon); }; require("NotFound.class.php"); return new NotFound(); } } $ItemFactory = new Factory(); ?> ---- Manual Page -- http://www.php.net/manual/en/language.oop.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34487 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34487&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34487&report=yes

« previous php.notes (#52874) next »