PhD Processing Instructions Design

From: Date: Wed, 22 Jul 2009 15:36:14 +0000
Subject: PhD Processing Instructions Design
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969380677@lists.php.net to get a copy of this message
Hey guys, The first design of the PhD Processing Instructions Handler. The idea is choose the correct PIHandler class for each target you want. ex: In the Package_Default_XHTML class we have: $pihandlers = array( "dbhtml" => "PI_DBHTMLHandler", ); In your own package: $pihandlers = array( "dbhtml" => "MyOwnDBHTMLHandler", ); Also we can write a class to handler all targets: $pihandlers = array( "dbhtml" => "PIHandler", "dbman" => "PIHandler", "tdg-purp" => "PIHandler", ); The Render class will only know the parsePI method: case \XMLReader::PI: $target = $r->name; $data = $r->value; foreach ($this as $format) { $format->parsePI($target, $data); } break; The parsePI method will act like a factory to instanciate the PIHandler class: public final function parsePI($target, $data) { if (isset($this->pihandlers[$target])) { //I'm thinking in a way to not have to create a new instance here //every time. Maybe a singleton? $classname = __NAMESPACE__ . "\\" . $this->pihandlers[$target]; $pihandler = new $classname($this); return $pihandler->parse($data); } } The PIHandler classes will have to parse and process the data in the PI. Sugestions? --Moacir

<?php namespace phpdotnet\phd; class PI_DBHTMLHandler extends PIHandler { private $map = array( "background-color" => "format_background_color", "bgcolor" => "format_bgcolor", "cellpadding" => "format_cellpadding", "cellspacing" => "format_cellspacing", "class" => "format_class", "dir" => "format_dir", "filename" => "format_filename", "funcsynopsis-style" => "format_funcsynopsis_style", "img.src.path" => "format_img_src_path", "label-width" => "format_label_width", "linenumbering.everyNth" => "format_linenumbering_everyNth", "linenumbering.separator" => "format_linenumbering_separator", "linenumbering.width" => "format_linenumbering_width", "list-presentation" => "format_list_presentation", "list-width" => "format_list_width", "row-height" => "format_row_height", "start" => "format_start", //obsolete "stop-chunking" => "format_stop_chunking", "table-summary" => "format_table_summary", "table-width" => "format_table_width", "term-presentation" => "format_term_presentation", "term-separator" => "format_term_separator", "term-width" => "format_term_width", "toc" => "format_toc", ); public function __construct($format) { parent::__construct($format); } /** * Function to parse the data and redirect it to the * correct format_ function. */ public function parse($data) {} public function format_background_color($data) {} public function format_bgcolor($data) {} public function format_cellpadding($data) {} public function format_cellspacing($data) {} public function format_class($data) {} public function format_dir($data) {} public function format_filename($data) {} public function format_funcsynopsis_style($data) {} public function format_img_src_path($data) {} public function format_label_width($data) {} public function format_linenumbering_everyNth($data) {} public function format_linenumbering_separator($data) {} public function format_linenumbering_width($data) {} public function format_list_presentation($data) {} public function format_list_width($data) {} public function format_row_height($data) {} public function format_start($data) {} public function format_stop_chunking($data) {} public function format_table_summary($data) {} public function format_table_width($data) {} public function format_term_presentation($data) {} public function format_term_separator($data) {} public function format_term_width($data) {} public function format_toc($data) {} } ?> Index: phpdotnet/phd/Package/Default/XHTML.php =================================================================== --- phpdotnet/phd/Package/Default/XHTML.php (revision 284295) +++ phpdotnet/phd/Package/Default/XHTML.php (working copy) @@ -413,6 +413,10 @@ ), ); + protected $pihandlers = array( + "dbhtml" => "PI_DBHTMLHandler", + ); + public function __construct() { parent::__construct(); $this->setExt("html"); Index: phpdotnet/phd/Format.php =================================================================== --- phpdotnet/phd/Format.php (revision 284293) +++ phpdotnet/phd/Format.php (working copy) @@ -16,10 +16,12 @@ protected $outputdir; protected $chunked; + /*Processing Instructions Handlers*/ + protected $pihandlers = array(); + /* Indexing maps */ protected $indexes = array(); protected $childrens = array(); - protected $refs = array(); protected $vars = array(); protected $classes = array(); @@ -44,6 +46,14 @@ abstract public function appendData($data); abstract public function update($event, $value = null); + public final function parsePI($target, $data) { + if (isset($this->pihandlers[$target])) { + //I'm thinking in a way to not have to create a new instance here + //every time. Maybe a singleton? + $classname = __NAMESPACE__ . "\\" . $this->pihandlers[$target]; + $pihandler = new $classname($this); + return $pihandler->parse($data); + } + } + public function sortIDs() { $this->sqlite->createAggregate("indexes", array($this, "SQLiteIndex"), array($this, "SQLiteFinal"), 8); $this->sqlite->createAggregate("childrens", array($this, "SQLiteChildrens"), array($this, "SQLiteFinal"), 2); <?php namespace phpdotnet\phd; abstract class PIHandler { protected $format; public function __construct($format) { $this->format = $format; } abstract function parse($data); } ?> Index: phpdotnet/phd/Render.php =================================================================== --- phpdotnet/phd/Render.php (revision 284228) +++ phpdotnet/phd/Render.php (working copy) @@ -214,6 +214,13 @@ break; /* }}} */ + case \XMLReader::PI: + $target = $r->name; + $data = $r->value; + foreach ($this as $format) { + $format->parsePI($target, $data); + } + break; } }
« previous php.doc (#969380677) next »