note 34487 deleted from language.oop by aidan

From: Date: Sat, 03 Jul 2004 14:51:33 +0000
Subject: note 34487 deleted from language.oop by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72443@lists.php.net to get a copy of this message
Note Submitter: spamspam@linuxmail.org ---- 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(); ?>

« previous php.notes (#72443) next »