gwynne Fri Jul 27 23:09:29 2007 UTC Added files: /phd TODO
Modified files: /phd README build.php /phd/formats xhtml.php /phd/include PhDReader.class.php /phd/setup CLI.class.php Configurator.class.php HTTP.class.php Option_Metadata.inc.php SAPI.interface.php Template_File.class.php setup.messages.php setup.php Log: whole bunch of stuff: - A number of WS changes in bjori's code (nothing against bjori, but I can't read such compressed code) - Added license information and vim modelines to most files - Added a TODO with some initial thoughts - The test build.php now depends on a config.php existing (create it with setup/setup.php) - Change the includes a little. - The base PhDReader class is now abstract and declares abstract methods for themes to implement. - Added __construct() and __destruct() skeletons where needed; it's good style. - Use NULL, TRUE, FALSE in all capitals, again readable style. - Use ${} syntax in strings instead of {$} syntax. Improves syntax highlighting in some editors. - Use references to $this in callback arrays, why not? - Documented a few functions a little. - Did I mention vim modelines? There's a lot of those :).
http://cvs.php.net/viewvc.cgi/phd/README?r1=1.3&r2=1.4&diff_format=u Index: phd/README diff -u phd/README:1.3 phd/README:1.4 --- phd/README:1.3 Fri Jul 27 21:26:21 2007 +++ phd/README Fri Jul 27 23:09:27 2007 @@ -2,7 +2,7 @@ Copyright(c) 2007 Gwynne Raskind and Hannes Magnusson All Rights Reserved. <[EMAIL PROTECTED]> -$Id: README,v 1.3 2007/07/27 21:26:21 gwynne Exp $ +$Id: README,v 1.4 2007/07/27 23:09:27 gwynne Exp $ At this time, all code and ideas here are completely experimental and untested. Don't even pretend you know what you're doing in here unless you're one of the @@ -26,3 +26,8 @@ and I'd like to have this be their chance to prove their worth. Until that decision is made, I'll make every effort to make their use less of a hassle for those who can't compile their own PHP. + + + +vim600: sw=4 ts=4syntax=php et +vim<600: sw=4 ts=4 http://cvs.php.net/viewvc.cgi/phd/build.php?r1=1.3&r2=1.4&diff_format=u Index: phd/build.php diff -u phd/build.php:1.3 phd/build.php:1.4 --- phd/build.php:1.3 Fri Jul 27 21:37:08 2007 +++ phd/build.php Fri Jul 27 23:09:27 2007 @@ -1,15 +1,15 @@ <?php -require "include/PhDReader.class.php"; -require "formats/xhtml.php"; +require_once 'config.php'; +require_once 'formats/xhtml.php'; - -$phd = new PhDXHTMLReader("/home/bjori/php/doc/.manual.xml"); -$phd->seek("function.dotnet-load"); -echo date(DATE_RSS), " done seeking\n"; +$phd = new PhDXHTMLReader( "${OPTIONS[ 'xml_root' ]}/.manual.xml" ); +$phd->seek( "function.dotnet-load" ); +echo date( DATE_RSS )." done seeking\n"; ob_start(); -while($phd->nextNode()) { +while( $phd->nextNode() ) { print $phd->transform(); } $phd->close(); +?> http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.2&r2=1.3&diff_format=u Index: phd/formats/xhtml.php diff -u phd/formats/xhtml.php:1.2 phd/formats/xhtml.php:1.3 --- phd/formats/xhtml.php:1.2 Fri Jul 27 21:37:08 2007 +++ phd/formats/xhtml.php Fri Jul 27 23:09:27 2007 @@ -1,6 +1,28 @@ <?php + +/* $Id: xhtml.php,v 1.3 2007/07/27 23:09:27 gwynne Exp $ + +-------------------------------------------------------------------------+ + | Copyright(c) 2007 | + | Authors: | + | Gwynne Raskind <[EMAIL PROTECTED]> | + | Hannes Magnusson <[EMAIL PROTECTED]> | + | This source file is subject to the license that is bundled with this | + | package in the file LICENSE, and is available through the | + | world-wide-web at the following url: | + | http://phd.php.net/LICENSE | + +-------------------------------------------------------------------------+ + | The XHTML output format class. This should not be instantiated | + | directly; it is intended for extension by a theme class. | + | XXX This is temporarily untrue for "let's get it started" purposes. | + +-------------------------------------------------------------------------+ +*/ + +/* Grab the PhDReader parent class. */ +require_once 'include/PhDReader.class.php'; + class PhDXHTMLReader extends PhDReader { - protected $map = array( /* {{{ */ + + protected $map = array( 'application' => 'span', 'classname' => 'span', 'code' => 'code', @@ -35,78 +57,113 @@ 'simpara' => 'p', 'title' => 'h1', 'year' => 'span', - ); /* }}} */ + ); + + public function __construct( $file, $encoding = 'utf-8', $options = NULL ) { + parent::__construct( $file, $encoding, $options ); + } + + public function __destruct() { + } + + public function getFormatName() { + + return 'XHTML 1.0 Transitional'; + + } + + public function format_refentry( $open ) { - public function format_refentry($open) { - if($open) { + if ( $open ) { return '<div>'; } echo "</div>"; - if ($this->hasAttributes && $this->moveToAttributeNs("id", "http://www.w3.org/XML/1998/namespace")) { + if ( $this->hasAttributes && $this->moveToAttributeNs( "id", "http://www.w3.org/XML/1998/namespace" ) ) { $id = $this->value; } $content = ob_get_contents(); ob_clean(); - file_put_contents("cache/$id.html", $content); + file_put_contents( "cache/$id.html", $content ); + } - public function format_function($open) { - return sprintf('<a href="function.%1$s.html">%1$s</a>', $this->readContent()); + + public function format_function( $open ) { + + return sprintf( '<a href="function.%1$s.html">%1$s</a>', $this->readContent() ); + } - public function format_refsect1($open) { - if($open) { - return sprintf('<div class="refsect %s">', $this->readAttribute("role")); + + public function format_refsect1( $open ) { + + if ( $open ) { + return sprintf( '<div class="refsect %s">', $this->readAttribute( "role" ) ); } return "</div>\n"; + } - public function format_link($open) { + + public function format_link( $open ) { + $this->moveToNextAttribute(); $href = $this->value; $class = $this->name; - $content = $this->readContent("link"); - return sprintf('<a href="%s" class="%s">%s</a>', $href, $class, $content); + $content = $this->readContent( "link" ); + return sprintf( '<a href="%s" class="%s">%s</a>', $href, $class, $content ); + } - public function format_methodsynopsis($open) { - /* We read this element to END_ELEMENT so $open is useless */ + public function format_methodsynopsis( $open ) { + + /* We read this element to END_ELEMENT so $open is useless */ $content = '<div class="methodsynopsis">'; $root = $this->name; - while($this->readNode($root)) { - if($this->nodeType == XMLReader::END_ELEMENT) { + while( $this->readNode( $root ) ) { + if ( $this->nodeType == XMLReader::END_ELEMENT ) { $content .= "</span>\n"; continue; } $name = $this->name; switch($name) { - case "type": - case "parameter": - case "methodname": - $content .= sprintf('<span class="%s">%s</span>', $name, $this->readContent($name)); - break; - case "methodparam": - $content .= '<span class="methodparam">'; - break; + case "type": + case "parameter": + case "methodname": + $content .= sprintf( '<span class="%s">%s</span>', $name, $this->readContent( $name ) ); + break; + + case "methodparam": + $content .= '<span class="methodparam">'; + break; } } $content .= "</div>"; return $content; + } - public function transormFromMap($open, $name) { - $tag = $this->map[$name]; + + protected function transformFromMap( $open, $name ) { + + $tag = $this->map[ $name ]; if($open) { - return sprintf('<%s class="%s">', $tag, $name); + return sprintf( '<%s class="%s">', $tag, $name ); } return "</$tag>"; + } - public function format_listing_hyperlink_function($matches) { - $link = str_replace('_', '-', $matches[1]); - $link = "function{$link}.html"; - return '<a class="phpfunc" href="' . $link . '">' . $matches[1] . '</a></span>' . $matches[2]; - } - public function highlight_php_code($str) { /* copy&paste from livedocs */ - if (is_array($str)) { - $str = $str[0]; + + public function format_listing_hyperlink_function( $matches ) { + + $link = str_replace( '_', '-', $matches[ 1 ] ); + $link = "function${link}.html"; + return '<a class="phpfunc" href="'.$link.'">'.$matches[ 1 ].'</a></span>'.$matches[ 2 ]; + + } + + public function highlight_php_code( $str ) { /* copy&paste from livedocs */ + + if ( is_array( $str ) ) { + $str = $str[ 0 ]; } $tmp = str_replace( @@ -126,11 +183,19 @@ "\n ", ' ' ), - highlight_string($str, true) + highlight_string( $str, TRUE ) ); - $tmp = preg_replace_callback('{([\w_]+)\s*</span>(\s*<span\s+class="keyword">\s*\()}m', array($this, 'format_listing_hyperlink_function'), $tmp); - return sprintf('<div class="phpcode">%s</div>', $tmp); + $tmp = preg_replace_callback( '{([\w_]+)\s*</span>(\s*<span\s+class="keyword">\s*\()}m', + array( &$this, 'format_listing_hyperlink_function' ), $tmp ); + return sprintf( '<div class="phpcode">%s</div>', $tmp ); + } -} +}; + +/* +* vim600: sw=4 ts=4 fdm=syntax syntax=php et +* vim<600: sw=4 ts=4 +*/ +?> http://cvs.php.net/viewvc.cgi/phd/include/PhDReader.class.php?r1=1.1&r2=1.2&diff_format=u Index: phd/include/PhDReader.class.php diff -u phd/include/PhDReader.class.php:1.1 phd/include/PhDReader.class.php:1.2 --- phd/include/PhDReader.class.php:1.1 Fri Jul 27 21:37:07 2007 +++ phd/include/PhDReader.class.php Fri Jul 27 23:09:28 2007 @@ -1,89 +1,165 @@ <?php -class PhDReader extends XMLReader { + +/* $Id: PhDReader.class.php,v 1.2 2007/07/27 23:09:28 gwynne Exp $ + +-------------------------------------------------------------------------+ + | Copyright(c) 2007 | + | Authors: | + | Gwynne Raskind <[EMAIL PROTECTED]> | + | Hannes Magnusson <[EMAIL PROTECTED]> | + | This source file is subject to the license that is bundled with this | + | package in the file LICENSE, and is available through the | + | world-wide-web at the following url: | + | http://phd.php.net/LICENSE | + +-------------------------------------------------------------------------+ + | The base class for reading the giant XML blob. This is intended for | + | extension by output formats, and then for further extension by output | + | themes. This class should not be instantiated directly. | + +-------------------------------------------------------------------------+ +*/ + +abstract class PhDReader extends XMLReader { + protected $map = array(); - public function __construct($file, $encoding = "UTF-8", $options = null) { - if (!parent::open($file, $encoding, $options)) { + public function __construct( $file, $encoding = "utf-8", $options = NULL ) { + + if ( !parent::open( $file, $encoding, $options ) ) { throw new Exception(); } + } - public function seek($id) { - while(parent::read()) { - if ($this->nodeType == XMLREADER::ELEMENT && $this->hasAttributes && $this->moveToAttributeNs("id", "http://www.w3.org/XML/1998/namespace") && $this->value == $id) { + + public function __destruct() { + } + + /* Format subclasses must implement these to make them real formats. */ + abstract public function getFormatName(); + abstract protected function transformFromMap( $open, $name ); + + /* These are new functions, extending XMLReader. */ + + /* Seek to an ID within the file. */ + public function seek( $id ) { + + while( parent::read() ) { + if ( $this->nodeType == XMLREADER::ELEMENT && $this->hasAttributes && + $this->moveToAttributeNs( "id", "http://www.w3.org/XML/1998/namespace" ) && $this->value == $id ) { return $this->moveToElement(); } } - return false; + return FALSE; + } + + /* Go to the next useful node in the file. */ public function nextNode() { - while($this->read()) { - switch($this->nodeType) { - case XMLReader::ELEMENT: - if($this->isEmptyElement) { continue; } - case XMLReader::TEXT: - case XMLReader::CDATA: - case XMLReader::END_ELEMENT: - return true; + while( $this->read() ) { + switch( $this->nodeType ) { + + case XMLReader::ELEMENT: + if ( $this->isEmptyElement ) { + continue; + } + + case XMLReader::TEXT: + case XMLReader::CDATA: + case XMLReader::END_ELEMENT: + return TRUE; } } - return false; + return FALSE; + } - public function readNode($nodeName) { - return $this->read() && !($this->nodeType == XMLReader::END_ELEMENT && $this->name == $nodeName); + + /* Read a node with the right name? */ + public function readNode( $nodeName ) { + + return $this->read() && !( $this->nodeType == XMLReader::END_ELEMENT && $this->name == $nodeName ); + } - public function readContent($node = null) { + + /* Get the content of a named node, or the current node. */ + public function readContent( $node = NULL ) { + $retval = ""; - if (!$node) { + if ( !$node ) { $node = $this->name; } - if ($this->readNode($node)) { + if ( $this->readNode( $node ) ) { $retval = $this->value; $this->read(); // Jump over END_ELEMENT too } return $retval; + } - public function readAttribute($attr) { - return $this->moveToAttribute($attr) ? $this->value : ""; + + /* Get the attribute value by name, if exists. */ + public function readAttribute( $attr ) { + + return $this->moveToAttribute( $attr ) ? $this->value : ""; + } - public function __call($func, $args) { - if($this->nodeType == XMLReader::END_ELEMENT) { /* ignore */ return;} - trigger_error("No mapper for $func", E_USER_WARNING); + + /* Handle unmapped nodes. */ + public function __call( $func, $args ) { + + if ( $this->nodeType == XMLReader::END_ELEMENT ) { + /* ignore */ return; + } + trigger_error( "No mapper for $func", E_USER_WARNING ); /* NOTE: - * The _content_ of the element will get processed even though we dont - * know how to handle the elment itself - */ + * The _content_ of the element will get processed even though we dont + * know how to handle the elment itself + */ return ""; + } + + /* Perform a transformation. */ public function transform() { + $type = $this->nodeType; $name = $this->name; - switch($type) { - case XMLReader::ELEMENT: - case XMLReader::END_ELEMENT: - if(isset($this->map[$name])) { - return $this->transormFromMap($type == XMLReader::ELEMENT, $name); - } - return call_user_func(array($this, "format_" . $name), $type == XMLReader::ELEMENT); - break; - case XMLReader::TEXT: - return $this->value; - break; - case XMLReader::CDATA: - return $this->highlight_php_code($this->value); - break; - case XMLReader::COMMENT: - case XMLReader::WHITESPACE: - case XMLReader::SIGNIFICANT_WHITESPACE: - /* swallow it */ - $this->read(); - return $this->transform(); - default: - trigger_error("Dunno what to do with {$this->name} {$this->nodeType}", E_USER_ERROR); - return ""; + switch( $type ) { + + case XMLReader::ELEMENT: + case XMLReader::END_ELEMENT: + if( isset( $this->map[ $name ] ) ) { + return $this->transformFromMap( $type == XMLReader::ELEMENT, $name ); + } + return call_user_func( array( &$this, "format_${name}" ), $type == XMLReader::ELEMENT ); + break; + + case XMLReader::TEXT: + return $this->value; + break; + + case XMLReader::CDATA: + return $this->highlight_php_code( $this->value ); + break; + + case XMLReader::COMMENT: + case XMLReader::WHITESPACE: + case XMLReader::SIGNIFICANT_WHITESPACE: + /* swallow it */ + /* XXX This could lead to a recursion overflow if a lot of comment nodes get strung together. */ + $this->read(); + return $this->transform(); + + default: + trigger_error( "Dunno what to do with {$this->name} {$this->nodeType}", E_USER_ERROR ); + return ""; } - } -} + } + +}; + +/* +* vim600: sw=4 ts=4 fdm=syntax syntax=php et +* vim<600: sw=4 ts=4 +*/ +?> http://cvs.php.net/viewvc.cgi/phd/setup/CLI.class.php?r1=1.3&r2=1.4&diff_format=u Index: phd/setup/CLI.class.php diff -u phd/setup/CLI.class.php:1.3 phd/setup/CLI.class.php:1.4 --- phd/setup/CLI.class.php:1.3 Wed Jul 25 21:59:54 2007 +++ phd/setup/CLI.class.php Fri Jul 27 23:09:28 2007 @@ -1,6 +1,6 @@ <?php -/* $Id: CLI.class.php,v 1.3 2007/07/25 21:59:54 gwynne Exp $ +/* $Id: CLI.class.php,v 1.4 2007/07/27 23:09:28 gwynne Exp $ +-------------------------------------------------------------------------+ | Copyright(c) 2007 | | Authors: | @@ -171,4 +171,8 @@ }; +/* +* vim600: sw=4 ts=4 fdm=syntax syntax=php et +* vim<600: sw=4 ts=4 +*/ ?> http://cvs.php.net/viewvc.cgi/phd/setup/Configurator.class.php?r1=1.2&r2=1.3&diff_format=u Index: phd/setup/Configurator.class.php diff -u phd/setup/Configurator.class.php:1.2 phd/setup/Configurator.class.php:1.3 --- phd/setup/Configurator.class.php:1.2 Wed Jul 25 21:59:54 2007 +++ phd/setup/Configurator.class.php Fri Jul 27 23:09:28 2007 @@ -1,6 +1,6 @@ <?php -/* $Id: Configurator.class.php,v 1.2 2007/07/25 21:59:54 gwynne Exp $ +/* $Id: Configurator.class.php,v 1.3 2007/07/27 23:09:28 gwynne Exp $ +-------------------------------------------------------------------------+ | Copyright(c) 2007 | | Authors: | @@ -98,4 +98,9 @@ }; + +/* +* vim600: sw=4 ts=4 fdm=syntax syntax=php et +* vim<600: sw=4 ts=4 +*/ ?> http://cvs.php.net/viewvc.cgi/phd/setup/HTTP.class.php?r1=1.2&r2=1.3&diff_format=u Index: phd/setup/HTTP.class.php diff -u phd/setup/HTTP.class.php:1.2 phd/setup/HTTP.class.php:1.3 --- phd/setup/HTTP.class.php:1.2 Wed Jul 25 21:59:54 2007 +++ phd/setup/HTTP.class.php Fri Jul 27 23:09:28 2007 @@ -1,6 +1,6 @@ <?php -/* $Id: HTTP.class.php,v 1.2 2007/07/25 21:59:54 gwynne Exp $ +/* $Id: HTTP.class.php,v 1.3 2007/07/27 23:09:28 gwynne Exp $ +-------------------------------------------------------------------------+ | Copyright(c) 2007 | | Authors: | @@ -45,4 +45,8 @@ }; +/* +* vim600: sw=4 ts=4 fdm=syntax syntax=php et +* vim<600: sw=4 ts=4 +*/ ?> http://cvs.php.net/viewvc.cgi/phd/setup/Option_Metadata.inc.php?r1=1.3&r2=1.4&diff_format=u Index: phd/setup/Option_Metadata.inc.php diff -u phd/setup/Option_Metadata.inc.php:1.3 phd/setup/Option_Metadata.inc.php:1.4 --- phd/setup/Option_Metadata.inc.php:1.3 Wed Jul 25 21:59:54 2007 +++ phd/setup/Option_Metadata.inc.php Fri Jul 27 23:09:28 2007 @@ -1,6 +1,6 @@ <?php -/* $Id: Option_Metadata.inc.php,v 1.3 2007/07/25 21:59:54 gwynne Exp $ +/* $Id: Option_Metadata.inc.php,v 1.4 2007/07/27 23:09:28 gwynne Exp $ +-------------------------------------------------------------------------+ | Copyright(c) 2007 | | Authors: | @@ -328,4 +328,8 @@ create_function( '$v', 'return strncmp( "__", $v, 2 );' ) ); } +/* +* vim600: sw=4 ts=4 fdm=syntax syntax=php et +* vim<600: sw=4 ts=4 +*/ ?> http://cvs.php.net/viewvc.cgi/phd/setup/SAPI.interface.php?r1=1.2&r2=1.3&diff_format=u Index: phd/setup/SAPI.interface.php diff -u phd/setup/SAPI.interface.php:1.2 phd/setup/SAPI.interface.php:1.3 --- phd/setup/SAPI.interface.php:1.2 Wed Jul 25 21:59:54 2007 +++ phd/setup/SAPI.interface.php Fri Jul 27 23:09:28 2007 @@ -1,6 +1,6 @@ <?php -/* $Id: SAPI.interface.php,v 1.2 2007/07/25 21:59:54 gwynne Exp $ +/* $Id: SAPI.interface.php,v 1.3 2007/07/27 23:09:28 gwynne Exp $ +-------------------------------------------------------------------------+ | Copyright(c) 2007 | | Authors: | @@ -26,4 +26,8 @@ }; +/* +* vim600: sw=4 ts=4 fdm=syntax syntax=php et +* vim<600: sw=4 ts=4 +*/ ?> http://cvs.php.net/viewvc.cgi/phd/setup/Template_File.class.php?r1=1.3&r2=1.4&diff_format=u Index: phd/setup/Template_File.class.php diff -u phd/setup/Template_File.class.php:1.3 phd/setup/Template_File.class.php:1.4 --- phd/setup/Template_File.class.php:1.3 Wed Jul 25 21:59:54 2007 +++ phd/setup/Template_File.class.php Fri Jul 27 23:09:28 2007 @@ -1,6 +1,6 @@ <?php -/* $Id: Template_File.class.php,v 1.3 2007/07/25 21:59:54 gwynne Exp $ +/* $Id: Template_File.class.php,v 1.4 2007/07/27 23:09:28 gwynne Exp $ +-------------------------------------------------------------------------+ | Copyright(c) 2007 | | Authors: | @@ -147,4 +147,8 @@ } +/* +* vim600: sw=4 ts=4 fdm=syntax syntax=php et +* vim<600: sw=4 ts=4 +*/ ?> http://cvs.php.net/viewvc.cgi/phd/setup/setup.messages.php?r1=1.2&r2=1.3&diff_format=u Index: phd/setup/setup.messages.php diff -u phd/setup/setup.messages.php:1.2 phd/setup/setup.messages.php:1.3 --- phd/setup/setup.messages.php:1.2 Wed Jul 25 21:59:54 2007 +++ phd/setup/setup.messages.php Fri Jul 27 23:09:28 2007 @@ -1,6 +1,6 @@ <?php -/* $Id: setup.messages.php,v 1.2 2007/07/25 21:59:54 gwynne Exp $ +/* $Id: setup.messages.php,v 1.3 2007/07/27 23:09:28 gwynne Exp $ +-------------------------------------------------------------------------+ | Copyright(c) 2007 | | Authors: | @@ -163,4 +163,8 @@ }; +/* +* vim600: sw=4 ts=4 fdm=syntax syntax=php et +* vim<600: sw=4 ts=4 +*/ ?> http://cvs.php.net/viewvc.cgi/phd/setup/setup.php?r1=1.2&r2=1.3&diff_format=u Index: phd/setup/setup.php diff -u phd/setup/setup.php:1.2 phd/setup/setup.php:1.3 --- phd/setup/setup.php:1.2 Wed Jul 25 21:59:54 2007 +++ phd/setup/setup.php Fri Jul 27 23:09:28 2007 @@ -1,6 +1,6 @@ <?php -/* $Id: setup.php,v 1.2 2007/07/25 21:59:54 gwynne Exp $ +/* $Id: setup.php,v 1.3 2007/07/27 23:09:28 gwynne Exp $ +-------------------------------------------------------------------------+ | Copyright(c) 2007 | | Authors: | @@ -21,7 +21,7 @@ */ // Used for versioning. -$REVISION = '$Id: setup.php,v 1.2 2007/07/25 21:59:54 gwynne Exp $'; +$REVISION = '$Id: setup.php,v 1.3 2007/07/27 23:09:28 gwynne Exp $'; // Chosen interface for the setup. Determined from SAPI name at main()-time. $chosenInterface = NULL; @@ -95,4 +95,8 @@ PhD_Warning( PhD_Warnings::UNSAVED_CHANGES ); } +/* +* vim600: sw=4 ts=4 fdm=syntax syntax=php et +* vim<600: sw=4 ts=4 +*/ ?>