From 15284136ffc82218e4fbe4ba6a801c3fc7366394 Mon Sep 17 00:00:00 2001 From: haszi Date: Sun, 10 Nov 2024 18:57:05 +0100 Subject: [PATCH] Separate regular PhD output from error handling (#176) - Move error handling code into a class and remove PhD message output handling from it. - Introduce a new class to handle PhD message output. - Make the implicit dependency on the output functionality of classes explicit. - Update PEAR package.xml. - Fix tests. - Use proper variadic parameters - Use class constants - Use first-class callable syntax --------- Co-authored-by: haszi --- package.xml | 4 +- phpdotnet/phd/ErrorHandler.php | 72 +++++++++ phpdotnet/phd/Format.php | 6 +- phpdotnet/phd/Format/Abstract/Manpage.php | 9 +- phpdotnet/phd/Format/Abstract/XHTML.php | 7 +- phpdotnet/phd/Index.php | 5 +- phpdotnet/phd/Options/Handler.php | 18 +-- phpdotnet/phd/OutputHandler.php | 117 +++++++++++++++ phpdotnet/phd/Package/Generic/BigXHTML.php | 11 +- .../phd/Package/Generic/ChunkedXHTML.php | 11 +- phpdotnet/phd/Package/Generic/Manpage.php | 15 +- phpdotnet/phd/Package/Generic/PDF.php | 9 +- phpdotnet/phd/Package/Generic/TocFeed.php | 12 +- phpdotnet/phd/Package/Generic/XHTML.php | 11 +- phpdotnet/phd/Package/IDE/Base.php | 13 +- phpdotnet/phd/Package/IDE/Funclist.php | 11 +- phpdotnet/phd/Package/IDE/JSON.php | 9 +- phpdotnet/phd/Package/IDE/PHP.php | 9 +- phpdotnet/phd/Package/IDE/PHPStub.php | 10 +- phpdotnet/phd/Package/IDE/SQLite.php | 9 +- phpdotnet/phd/Package/IDE/XML.php | 9 +- phpdotnet/phd/Package/PEAR/BigXHTML.php | 12 +- phpdotnet/phd/Package/PEAR/CHM.php | 9 +- phpdotnet/phd/Package/PEAR/ChunkedXHTML.php | 11 +- phpdotnet/phd/Package/PEAR/TocFeed.php | 8 +- phpdotnet/phd/Package/PEAR/Web.php | 10 +- phpdotnet/phd/Package/PEAR/XHTML.php | 9 +- phpdotnet/phd/Package/PHP/BigPDF.php | 13 +- phpdotnet/phd/Package/PHP/BigXHTML.php | 11 +- phpdotnet/phd/Package/PHP/CHM.php | 9 +- phpdotnet/phd/Package/PHP/ChunkedXHTML.php | 9 +- phpdotnet/phd/Package/PHP/EnhancedCHM.php | 15 +- phpdotnet/phd/Package/PHP/Epub.php | 9 +- phpdotnet/phd/Package/PHP/HowTo.php | 9 +- phpdotnet/phd/Package/PHP/KDevelop.php | 11 +- phpdotnet/phd/Package/PHP/Manpage.php | 9 +- phpdotnet/phd/Package/PHP/PDF.php | 15 +- phpdotnet/phd/Package/PHP/TocFeed.php | 8 +- phpdotnet/phd/Package/PHP/Web.php | 15 +- phpdotnet/phd/Package/PHP/XHTML.php | 11 +- phpdotnet/phd/Reader.php | 7 +- phpdotnet/phd/Reader/Partial.php | 19 +-- phpdotnet/phd/TestGenericChunkedXHTML.php | 9 +- phpdotnet/phd/TestPHPChunkedXHTML.php | 7 +- phpdotnet/phd/functions.php | 140 ------------------ render.php | 46 +++--- tests/bug_GH-87.phpt | 8 +- tests/bug_doc-en_GH-3353.phpt | 8 +- tests/bug_doc-en_GH-3428.phpt | 12 +- tests/example_numbering_001.phpt | 8 +- tests/index/bug_GH-98.phpt | 4 +- tests/index/indexing_001.phpt | 4 +- tests/options/default_handler_005.phpt | 8 +- tests/options/default_handler_006.phpt | 8 +- tests/options/default_handler_009.phpt | 6 +- tests/options/default_handler_010.phpt | 6 +- tests/package/generic/001.phpt | 4 +- tests/package/generic/002.phpt | 4 +- tests/package/generic/003.phpt | 4 +- .../generic/attribute_formatting_001.phpt | 4 +- .../generic/attribute_formatting_002.phpt | 4 +- .../generic/attribute_formatting_003.phpt | 4 +- tests/package/generic/caption_001.phpt | 4 +- tests/package/generic/simplelist_001.phpt | 4 +- .../generic/whitespace_formatting_001.phpt | 4 +- tests/package/php/bug49101-1.phpt | 4 +- tests/package/php/bug49101-2.phpt | 4 +- tests/package/php/bug49102-1.phpt | 4 +- tests/package/php/bug_doc-en_GH-3179.phpt | 4 +- tests/package/php/class_rendering_001.phpt | 4 +- tests/package/php/class_rendering_002.phpt | 4 +- tests/package/php/class_rendering_003.phpt | 8 +- tests/package/php/constant_links_001.phpt | 4 +- .../package/php/exception_rendering_001.phpt | 4 +- .../package/php/exception_rendering_002.phpt | 4 +- .../package/php/exception_rendering_003.phpt | 8 +- tests/package/php/faq001.phpt | 4 +- tests/package/php/type_rendering_001.phpt | 4 +- tests/package/php/type_rendering_002.phpt | 4 +- tests/package/php/type_rendering_003.phpt | 4 +- .../php/variablelist_rendering_001.phpt | 4 +- tests/reader/partial_reader_001.phpt | 4 +- tests/reader/reader_001.phpt | 2 +- tests/setup.php | 10 +- 84 files changed, 565 insertions(+), 439 deletions(-) create mode 100644 phpdotnet/phd/ErrorHandler.php create mode 100644 phpdotnet/phd/OutputHandler.php delete mode 100644 phpdotnet/phd/functions.php diff --git a/package.xml b/package.xml index de14264d..85a290cd 100644 --- a/package.xml +++ b/package.xml @@ -122,17 +122,19 @@ + + - + diff --git a/phpdotnet/phd/ErrorHandler.php b/phpdotnet/phd/ErrorHandler.php new file mode 100644 index 00000000..f59f7b39 --- /dev/null +++ b/phpdotnet/phd/ErrorHandler.php @@ -0,0 +1,72 @@ + 'E_DEPRECATED ', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR ', + E_STRICT => 'E_STRICT ', + E_WARNING => 'E_WARNING ', + E_NOTICE => 'E_NOTICE ', + + // User Triggered Errors + E_USER_ERROR => 'E_USER_ERROR ', + E_USER_WARNING => 'E_USER_WARNING ', + E_USER_NOTICE => 'E_USER_NOTICE ', + E_USER_DEPRECATED => 'E_USER_DEPRECATED ', + ]; + + private bool $recursive = false; + + public function __construct( + private OutputHandler $outputHandler + ) {} + + public function handleError($errno, $msg, $file, $line) { + // Respect the error_reporting setting + if (!(error_reporting() & $errno)) { + return false; + } + + // Recursive protection + if ($this->recursive) { + // Thats bad.. lets print a backtrace right away + debug_print_backtrace(); + // Fallback to the default errorhandler + return false; + } + $this->recursive = true; + + switch($errno) { + // User triggered errors + case E_USER_ERROR: + case E_USER_WARNING: + case E_USER_NOTICE: + $this->outputHandler->printUserError($msg, $file, $line, self::ERROR_MAP[$errno]); + break; + + // PHP triggered errors + case E_DEPRECATED: + case E_RECOVERABLE_ERROR: + case E_STRICT: + case E_WARNING: + case E_NOTICE: + $this->outputHandler->printPhpError($msg, $file, $line, self::ERROR_MAP[$errno]); + break; + + default: + $this->recursive = false; + return false; + } + + // Abort on fatal errors + if ($errno & (E_USER_ERROR|E_RECOVERABLE_ERROR)) { + exit(1); + } + + $this->recursive = false; + return true; + } +} diff --git a/phpdotnet/phd/Format.php b/phpdotnet/phd/Format.php index 215c932e..1375138f 100644 --- a/phpdotnet/phd/Format.php +++ b/phpdotnet/phd/Format.php @@ -22,6 +22,7 @@ abstract class Format extends ObjectStorage const LDESC = 2; protected Config $config; + protected OutputHandler $outputHandler; private $elementmap = array(); private $textmap = array(); @@ -64,8 +65,9 @@ abstract class Format extends ObjectStorage */ protected $CURRENT_ID = ""; - public function __construct(Config $config) { + public function __construct(Config $config, OutputHandler $outputHandler) { $this->config = $config; + $this->outputHandler = $outputHandler; if ($this->config->indexcache()) { $this->indexRepository = $this->config->indexcache(); if (!($this instanceof Index)) { @@ -312,7 +314,7 @@ public function getFormatName() { /* Buffer where append data instead of the standard stream (see format's appendData()) */ final public function parse($xml) { - $reader = new Reader(); + $reader = new Reader($this->outputHandler); $render = new Render(); $reader->XML("" . $xml . ""); diff --git a/phpdotnet/phd/Format/Abstract/Manpage.php b/phpdotnet/phd/Format/Abstract/Manpage.php index 9e940279..85c72725 100644 --- a/phpdotnet/phd/Format/Abstract/Manpage.php +++ b/phpdotnet/phd/Format/Abstract/Manpage.php @@ -4,8 +4,11 @@ abstract class Format_Abstract_Manpage extends Format { public $role = false; - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler, + ) { + parent::__construct($config, $outputHandler); } public function UNDEF($open, $name, $attrs, $props) { @@ -55,5 +58,3 @@ public function createLink($for, &$desc = null, $type = Format::SDESC) { } } - - diff --git a/phpdotnet/phd/Format/Abstract/XHTML.php b/phpdotnet/phd/Format/Abstract/XHTML.php index ef1cc3ac..d07f13ce 100644 --- a/phpdotnet/phd/Format/Abstract/XHTML.php +++ b/phpdotnet/phd/Format/Abstract/XHTML.php @@ -14,8 +14,11 @@ abstract class Format_Abstract_XHTML extends Format { protected $mediamanager = null; protected $lang = 'en'; - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); } public function transformFromMap($open, $tag, $name, $attrs, $props) { diff --git a/phpdotnet/phd/Index.php b/phpdotnet/phd/Index.php index 620da3c4..39deaca6 100644 --- a/phpdotnet/phd/Index.php +++ b/phpdotnet/phd/Index.php @@ -107,10 +107,11 @@ class Index extends Format public function __construct( IndexRepository $indexRepository, - Config $config + Config $config, + OutputHandler $outputHandler ) { $this->indexRepository = $indexRepository; - parent::__construct($config); + parent::__construct($config, $outputHandler); } public function transformFromMap($open, $tag, $name, $attrs, $props) { diff --git a/phpdotnet/phd/Options/Handler.php b/phpdotnet/phd/Options/Handler.php index 6f7e2bc3..48bf0d0c 100644 --- a/phpdotnet/phd/Options/Handler.php +++ b/phpdotnet/phd/Options/Handler.php @@ -5,7 +5,8 @@ class Options_Handler implements Options_Interface { public function __construct( private Config $config, - private Format_Factory $formatFactory + private Format_Factory $formatFactory, + private OutputHandler $outputHandler ) {} /** @@ -211,11 +212,11 @@ public function option_output(string $k, mixed $v): array trigger_error("Only a single output location can be supplied", E_USER_ERROR); } if (!file_exists($v)) { - v("Creating output directory..", VERBOSE_MESSAGES); + $this->outputHandler->v("Creating output directory..", VERBOSE_MESSAGES); if (!mkdir($v, 0777, true)) { trigger_error(vsprintf("Can't create output directory : %s", [$v]), E_USER_ERROR); } - v("Output directory created", VERBOSE_MESSAGES); + $this->outputHandler->v("Output directory created", VERBOSE_MESSAGES); } elseif (!is_dir($v)) { trigger_error("Output directory is a file?", E_USER_ERROR); } @@ -510,17 +511,14 @@ public function option_xinclude(string $k, mixed $v): array */ public function option_version(string $k, mixed $v): never { - $color = $this->config->phd_info_color(); - $output = $this->config->phd_info_output(); - fprintf($output, "%s\n", term_color('PhD Version: ' . $this->config::VERSION, $color)); - + $this->outputHandler->printPhdInfo('PhD Version: ' . $this->config::VERSION); $packageList = $this->config->getSupportedPackages(); foreach ($packageList as $package) { $version = $this->formatFactory::createFactory($package)->getPackageVersion(); - fprintf($output, "\t%s: %s\n", term_color($package, $color), term_color($version, $color)); + $this->outputHandler->printPhdInfo("\t$package: $version"); } - fprintf($output, "%s\n", term_color('PHP Version: ' . phpversion(), $color)); - fprintf($output, "%s\n", term_color($this->config->copyright(), $color)); + $this->outputHandler->printPhdInfo('PHP Version: ' . phpversion()); + $this->outputHandler->printPhdInfo($this->config->copyright()); exit(0); } diff --git a/phpdotnet/phd/OutputHandler.php b/phpdotnet/phd/OutputHandler.php new file mode 100644 index 00000000..0f623076 --- /dev/null +++ b/phpdotnet/phd/OutputHandler.php @@ -0,0 +1,117 @@ + 'Indexing ', + VERBOSE_FORMAT_RENDERING => 'Rendering Format ', + VERBOSE_THEME_RENDERING => 'Rendering Theme ', + VERBOSE_RENDER_STYLE => 'Rendering Style ', + VERBOSE_PARTIAL_READING => 'Partial Reading ', + VERBOSE_PARTIAL_CHILD_READING => 'Partial Child Reading ', + VERBOSE_TOC_WRITING => 'Writing TOC ', + VERBOSE_CHUNK_WRITING => 'Writing Chunk ', + VERBOSE_MESSAGES => 'Heads up ', + + // PhD warnings + VERBOSE_NOVERSION => 'No version information', + VERBOSE_BROKEN_LINKS => 'Broken links ', + VERBOSE_OLD_LIBXML => 'Old libxml2 ', + VERBOSE_MISSING_ATTRIBUTES => 'Missing attributes ', + ]; + + public function __construct( + private Config $config + ) {} + + /** + * Method to get a color escape sequence + */ + private function term_color(string $text, string|false $color): string { + return $this->config->color_output() && $color !== false ? "\033[" . $color . "m" . $text . "\033[m" : $text; + } + + public function printPhdInfo(string $msg, string $info = ""): int { + $color = $this->config->phd_info_color(); + $outputStream = $this->config->phd_info_output(); + + return $this->print($msg, $outputStream, $color, $info); + } + + private function printPhdWarning(string $msg, string $warning = ""): int { + $color = $this->config->phd_warning_color(); + $outputStream = $this->config->phd_warning_output(); + + return $this->print($msg, $outputStream, $color, $warning); + } + + public function printUserError(string $msg, string $file, int $line, string $error = ""): int { + $color = $this->config->user_error_color(); + $outputStream = $this->config->user_error_output(); + $data = \sprintf("%s:%d\n\t%s", $file, $line, $msg); + + return $this->print($data, $outputStream, $color, $error); + } + + public function printPhpError(string $msg, string $file, int $line, string $error = ""): int { + $color = $this->config->php_error_color(); + $outputStream = $this->config->php_error_output(); + $data = \sprintf("%s:%d\n\t%s", $file, $line, $msg); + + return $this->print($data, $outputStream, $color, $error); + } + + private function print(string $msg, $outputStream, string|false $color = false, string $infoOrErrorString = ""): int { + if ($infoOrErrorString === "") { + $colorMsg = $this->term_color(\sprintf("%s", $msg), $color); + + return \fprintf($outputStream, "%s\n", $colorMsg); + } + + $time = \date($this->config->date_format()); + $timestamp = $this->term_color(\sprintf("[%s - %s]", $time, $infoOrErrorString), $color); + + return \fprintf($outputStream, "%s %s\n", $timestamp, $msg); + } + + /** + * Print info messages: v("printf-format-text" [, $arg1, ...], $verbose-level) + */ + public function v(...$args): bool { + $messageCategory = \array_pop($args); + $msg = \vsprintf(\array_shift($args), $args); + + // Respect the error_reporting setting + if (!(\error_reporting() & $messageCategory)) { + return false; + } + + switch($messageCategory) { + case VERBOSE_INDEXING: + case VERBOSE_FORMAT_RENDERING: + case VERBOSE_THEME_RENDERING: + case VERBOSE_RENDER_STYLE: + case VERBOSE_PARTIAL_READING: + case VERBOSE_PARTIAL_CHILD_READING: + case VERBOSE_TOC_WRITING: + case VERBOSE_CHUNK_WRITING: + case VERBOSE_MESSAGES: + $this->printPhdInfo($msg, self::CONSTANT_TO_MESSAGE_CATEGORY_MAP[$messageCategory]); + break; + + case VERBOSE_NOVERSION: + case VERBOSE_BROKEN_LINKS: + case VERBOSE_OLD_LIBXML: + case VERBOSE_MISSING_ATTRIBUTES: + $this->printPhdWarning($msg, self::CONSTANT_TO_MESSAGE_CATEGORY_MAP[$messageCategory]); + break; + + default: + return false; + } + return true; + } +} diff --git a/phpdotnet/phd/Package/Generic/BigXHTML.php b/phpdotnet/phd/Package/Generic/BigXHTML.php index 5bbaf627..f58447b4 100644 --- a/phpdotnet/phd/Package/Generic/BigXHTML.php +++ b/phpdotnet/phd/Package/Generic/BigXHTML.php @@ -2,8 +2,11 @@ namespace phpdotnet\phd; class Package_Generic_BigXHTML extends Package_Generic_XHTML { - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("Big-XHTML"); $this->setTitle("Index"); $this->setChunked(false); @@ -94,7 +97,7 @@ public function update($event, $value = null) { break; case Render::VERBOSE: - v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); + $this->outputHandler->v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); break; } } @@ -113,5 +116,3 @@ public function createLink($for, &$desc = null, $type = self::SDESC) { } } - - diff --git a/phpdotnet/phd/Package/Generic/ChunkedXHTML.php b/phpdotnet/phd/Package/Generic/ChunkedXHTML.php index a07fd12d..d0da3395 100644 --- a/phpdotnet/phd/Package/Generic/ChunkedXHTML.php +++ b/phpdotnet/phd/Package/Generic/ChunkedXHTML.php @@ -2,8 +2,11 @@ namespace phpdotnet\phd; class Package_Generic_ChunkedXHTML extends Package_Generic_XHTML { - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("Chunked-XHTML"); $this->setTitle("Index"); $this->setChunked(true); @@ -86,7 +89,7 @@ public function update($event, $value = null) { } break; case Render::VERBOSE: - v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); + $this->outputHandler->v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); break; } } @@ -207,5 +210,3 @@ protected function createNavBar($id) { } } - - diff --git a/phpdotnet/phd/Package/Generic/Manpage.php b/phpdotnet/phd/Package/Generic/Manpage.php index 04621192..be5c3d21 100644 --- a/phpdotnet/phd/Package/Generic/Manpage.php +++ b/phpdotnet/phd/Package/Generic/Manpage.php @@ -256,8 +256,11 @@ class Package_Generic_Manpage extends Format_Abstract_Manpage { "firstrefname" => true, ); - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("Generic Unix Manual Pages"); $this->setExt($this->config->ext() === null ? ".3.gz" : $this->config->ext()); @@ -321,7 +324,7 @@ public function update($event, $value = null) { } break; case Render::VERBOSE: - v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); + $this->outputHandler->v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); break; } } @@ -354,7 +357,7 @@ public function writeChunk($stream) { gzwrite($gzfile, $this->header($index)); gzwrite($gzfile, stream_get_contents($stream)); gzclose($gzfile); - v("Wrote %s", $this->getOutputDir() . $filename, VERBOSE_CHUNK_WRITING); + $this->outputHandler->v("Wrote %s", $this->getOutputDir() . $filename, VERBOSE_CHUNK_WRITING); /* methods/functions with the same name */ while(isset($this->cchunk["funcname"][++$index])) { @@ -370,7 +373,7 @@ public function writeChunk($stream) { gzwrite($gzfile, $content); gzclose($gzfile); - v("Wrote %s", $this->getOutputDir() . $filename, VERBOSE_CHUNK_WRITING); + $this->outputHandler->v("Wrote %s", $this->getOutputDir() . $filename, VERBOSE_CHUNK_WRITING); } } @@ -788,5 +791,3 @@ public function format_pubdate_text($value, $tag) { return false; } } - - diff --git a/phpdotnet/phd/Package/Generic/PDF.php b/phpdotnet/phd/Package/Generic/PDF.php index a829b104..bf58aa06 100644 --- a/phpdotnet/phd/Package/Generic/PDF.php +++ b/phpdotnet/phd/Package/Generic/PDF.php @@ -296,8 +296,11 @@ abstract class Package_Generic_PDF extends Format_Abstract_PDF { "callouts" => 0, ); - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->setExt($this->config->ext() === null ? ".pdf" : $this->config->ext()); $this->pdfDoc = new PdfWriter(); } @@ -1138,5 +1141,3 @@ public function format_imagedata($open, $name, $attrs, $props) { } } - - diff --git a/phpdotnet/phd/Package/Generic/TocFeed.php b/phpdotnet/phd/Package/Generic/TocFeed.php index c987672e..3165f934 100644 --- a/phpdotnet/phd/Package/Generic/TocFeed.php +++ b/phpdotnet/phd/Package/Generic/TocFeed.php @@ -131,9 +131,11 @@ abstract class Package_Generic_TocFeed extends Format /** * Creates a new instance. */ - public function __construct(Config $config) - { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName($this->formatName); $this->setTitle('Index'); $this->setChunked(true); @@ -232,7 +234,7 @@ public function update($event, $value = null) break; case Render::VERBOSE: - v( + $this->outputHandler->v( 'Starting %s rendering', $this->getFormatName(), VERBOSE_FORMAT_RENDERING ); @@ -524,5 +526,3 @@ public function createTargetLink($id) } } - - diff --git a/phpdotnet/phd/Package/Generic/XHTML.php b/phpdotnet/phd/Package/Generic/XHTML.php index 0cf6e97e..2268fecb 100644 --- a/phpdotnet/phd/Package/Generic/XHTML.php +++ b/phpdotnet/phd/Package/Generic/XHTML.php @@ -537,8 +537,11 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML { protected int $exampleCounter = 0; - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerPIHandlers($this->pihandlers); $this->setExt($this->config->ext() === null ? ".html" : $this->config->ext()); } @@ -1891,10 +1894,10 @@ public function format_imagedata($open, $name, $attrs) { // Generate warnings when only 1 dimension supplied or alt is not supplied. if (!$width xor !$height) { - v('Missing %s attribute for %s', (!$width ? 'width' : 'height'), $file, VERBOSE_MISSING_ATTRIBUTES); + $this->outputHandler->v('Missing %s attribute for %s', (!$width ? 'width' : 'height'), $file, VERBOSE_MISSING_ATTRIBUTES); } if (false === $this->cchunk["mediaobject"]["alt"]) { - v('Missing alt attribute for %s', $file, VERBOSE_MISSING_ATTRIBUTES); + $this->outputHandler->v('Missing alt attribute for %s', $file, VERBOSE_MISSING_ATTRIBUTES); } return ''; diff --git a/phpdotnet/phd/Package/IDE/Base.php b/phpdotnet/phd/Package/IDE/Base.php index 7a4ad17f..211eb893 100644 --- a/phpdotnet/phd/Package/IDE/Base.php +++ b/phpdotnet/phd/Package/IDE/Base.php @@ -76,8 +76,11 @@ abstract class Package_IDE_Base extends Format { 'seealso' => array(), ); - public function __construct(Config $config){ - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); } public function createLink($for, &$desc = null, $type = Format::SDESC) {} @@ -139,7 +142,7 @@ public function FINALIZE($value) { } public function VERBOSE($value) { - v('Starting %s rendering', $this->getFormatName(), VERBOSE_FORMAT_RENDERING); + $this->outputHandler->v('Starting %s rendering', $this->getFormatName(), VERBOSE_FORMAT_RENDERING); } public function update($event, $value = null) { @@ -199,7 +202,7 @@ public function versionInfo($funcname) { if(isset($this->versions[$funcname])) { return $this->versions[$funcname]; } - v('No version info for %s', $funcname, VERBOSE_NOVERSION); + $this->outputHandler->v('No version info for %s', $funcname, VERBOSE_NOVERSION); return false; } @@ -458,5 +461,3 @@ public function toValidName($functionName) { } } - - diff --git a/phpdotnet/phd/Package/IDE/Funclist.php b/phpdotnet/phd/Package/IDE/Funclist.php index f6f938f3..9022f821 100644 --- a/phpdotnet/phd/Package/IDE/Funclist.php +++ b/phpdotnet/phd/Package/IDE/Funclist.php @@ -14,8 +14,11 @@ class Package_IDE_Funclist extends Format { protected $isRefname = false; protected $buffer = ""; - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("IDE-Funclist"); $this->setExt($this->config->ext() === null ? ".txt" : $this->config->ext()); } @@ -43,7 +46,7 @@ public function update($event, $value = null) { file_put_contents($filename, $this->buffer); break; case Render::VERBOSE: - v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); + $this->outputHandler->v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); break; } } @@ -68,5 +71,3 @@ public function format_refname_text($value, $tag) { } } - - diff --git a/phpdotnet/phd/Package/IDE/JSON.php b/phpdotnet/phd/Package/IDE/JSON.php index 66c0d6e4..a01f9efb 100644 --- a/phpdotnet/phd/Package/IDE/JSON.php +++ b/phpdotnet/phd/Package/IDE/JSON.php @@ -3,8 +3,11 @@ class Package_IDE_JSON extends Package_IDE_Base { - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName('IDE-JSON'); $this->setExt($this->config->ext() === null ? ".json" : $this->config->ext()); } @@ -14,5 +17,3 @@ public function parseFunction() { } } - - diff --git a/phpdotnet/phd/Package/IDE/PHP.php b/phpdotnet/phd/Package/IDE/PHP.php index fbf86da9..c309956a 100644 --- a/phpdotnet/phd/Package/IDE/PHP.php +++ b/phpdotnet/phd/Package/IDE/PHP.php @@ -3,8 +3,11 @@ class Package_IDE_PHP extends Package_IDE_Base { - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName('IDE-PHP'); $this->setExt($this->config->ext() === null ? ".php" : $this->config->ext()); } @@ -17,5 +20,3 @@ public function parseFunction() { } } - - diff --git a/phpdotnet/phd/Package/IDE/PHPStub.php b/phpdotnet/phd/Package/IDE/PHPStub.php index 172e1a9c..14180613 100644 --- a/phpdotnet/phd/Package/IDE/PHPStub.php +++ b/phpdotnet/phd/Package/IDE/PHPStub.php @@ -1,9 +1,13 @@ registerFormatName('IDE-PHPStub'); $this->setExt($this->config->ext() === null ? ".php" : $this->config->ext()); } @@ -81,5 +85,3 @@ private function renderParamBody() { return implode(", ", $result); } } - - diff --git a/phpdotnet/phd/Package/IDE/SQLite.php b/phpdotnet/phd/Package/IDE/SQLite.php index 964f242f..3a4e6645 100644 --- a/phpdotnet/phd/Package/IDE/SQLite.php +++ b/phpdotnet/phd/Package/IDE/SQLite.php @@ -6,8 +6,11 @@ class Package_IDE_SQLite extends Package_IDE_Base { private $sql = array(); private $db = null; - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName('IDE-SQLite'); $this->setExt($this->config->ext() === null ? ".sqlite" : $this->config->ext()); } @@ -148,5 +151,3 @@ function_name TEXT, } } - - diff --git a/phpdotnet/phd/Package/IDE/XML.php b/phpdotnet/phd/Package/IDE/XML.php index 4801b565..badc04c7 100644 --- a/phpdotnet/phd/Package/IDE/XML.php +++ b/phpdotnet/phd/Package/IDE/XML.php @@ -3,8 +3,11 @@ class Package_IDE_XML extends Package_IDE_Base { - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName('IDE-XML'); $this->setExt($this->config->ext() === null ? ".xml" : $this->config->ext()); } @@ -86,5 +89,3 @@ protected function cdata_str($data) { } } - - diff --git a/phpdotnet/phd/Package/PEAR/BigXHTML.php b/phpdotnet/phd/Package/PEAR/BigXHTML.php index c5052d90..ed413497 100755 --- a/phpdotnet/phd/Package/PEAR/BigXHTML.php +++ b/phpdotnet/phd/Package/PEAR/BigXHTML.php @@ -2,8 +2,11 @@ namespace phpdotnet\phd; class Package_PEAR_BigXHTML extends Package_PEAR_XHTML { - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("PEAR-BigXHTML"); $this->setTitle("PEAR Manual"); $this->setExt($this->config->ext() === null ? ".html" : $this->config->ext()); @@ -102,7 +105,7 @@ public function update($event, $value = null) { break; case Render::VERBOSE: - v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); + $this->outputHandler->v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); break; } } @@ -120,6 +123,3 @@ public function createLink($for, &$desc = null, $type = self::SDESC) { return $retval; } } - - - diff --git a/phpdotnet/phd/Package/PEAR/CHM.php b/phpdotnet/phd/Package/PEAR/CHM.php index 489662d1..8a924f68 100755 --- a/phpdotnet/phd/Package/PEAR/CHM.php +++ b/phpdotnet/phd/Package/PEAR/CHM.php @@ -194,8 +194,11 @@ class Package_PEAR_CHM extends Package_PEAR_ChunkedXHTML { // Project files Output directory protected $chmdir; - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("PEAR-CHM"); } @@ -424,5 +427,3 @@ public function format_link($open, $name, $attrs, $props) { return $link; } } - - diff --git a/phpdotnet/phd/Package/PEAR/ChunkedXHTML.php b/phpdotnet/phd/Package/PEAR/ChunkedXHTML.php index 85774aa3..39a247a8 100755 --- a/phpdotnet/phd/Package/PEAR/ChunkedXHTML.php +++ b/phpdotnet/phd/Package/PEAR/ChunkedXHTML.php @@ -2,8 +2,11 @@ namespace phpdotnet\phd; class Package_PEAR_ChunkedXHTML extends Package_PEAR_XHTML { - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("PEAR-Chunked-XHTML"); $this->setTitle("PEAR Manual"); $this->setExt($this->config->ext() === null ? ".html" : $this->config->ext()); @@ -84,7 +87,7 @@ public function update($event, $value = null) { } break; case Render::VERBOSE: - v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); + $this->outputHandler->v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); break; } } @@ -200,5 +203,3 @@ public function footer($id) { } } - - diff --git a/phpdotnet/phd/Package/PEAR/TocFeed.php b/phpdotnet/phd/Package/PEAR/TocFeed.php index 34362d8c..9039e806 100644 --- a/phpdotnet/phd/Package/PEAR/TocFeed.php +++ b/phpdotnet/phd/Package/PEAR/TocFeed.php @@ -84,9 +84,11 @@ class Package_PEAR_TocFeed extends Package_Generic_TocFeed /** * Create new instance. */ - public function __construct(Config $config) - { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $language = $this->config->language(); $variables = array('targetBaseUri', 'feedBaseUri', 'idprefix'); diff --git a/phpdotnet/phd/Package/PEAR/Web.php b/phpdotnet/phd/Package/PEAR/Web.php index e8508891..b366c400 100755 --- a/phpdotnet/phd/Package/PEAR/Web.php +++ b/phpdotnet/phd/Package/PEAR/Web.php @@ -14,9 +14,11 @@ */ class Package_PEAR_Web extends Package_PEAR_ChunkedXHTML { - public function __construct(Config $config) - { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName('PEAR-Web'); $this->setExt($this->config->ext() === null ? '.php' : $this->config->ext()); } @@ -132,5 +134,3 @@ public function footer($id) } } - - diff --git a/phpdotnet/phd/Package/PEAR/XHTML.php b/phpdotnet/phd/Package/PEAR/XHTML.php index 5cdd5990..b7fd627b 100755 --- a/phpdotnet/phd/Package/PEAR/XHTML.php +++ b/phpdotnet/phd/Package/PEAR/XHTML.php @@ -405,8 +405,11 @@ abstract class Package_PEAR_XHTML extends Package_Generic_XHTML { /** * Constructor */ - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->myelementmap = array_merge(parent::getDefaultElementMap(), $this->getDefaultElementMap()); $this->mytextmap = array_merge(parent::getDefaultTextMap(), $this->getDefaultTextMap()); $this->dchunk = array_merge(parent::getDefaultChunkInfo(), $this->getDefaultChunkInfo()); @@ -1129,5 +1132,3 @@ public function format_div($open, $name, $attrs, $props) return ''; } } - - diff --git a/phpdotnet/phd/Package/PHP/BigPDF.php b/phpdotnet/phd/Package/PHP/BigPDF.php index 2b13be8e..4e7e0561 100644 --- a/phpdotnet/phd/Package/PHP/BigPDF.php +++ b/phpdotnet/phd/Package/PHP/BigPDF.php @@ -2,8 +2,11 @@ namespace phpdotnet\phd; class Package_PHP_BigPDF extends Package_PHP_PDF { - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("PHP-BigPDF"); } @@ -21,7 +24,7 @@ public function update($event, $value = null) { break; case Render::VERBOSE: - v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); + $this->outputHandler->v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); break; } } @@ -50,7 +53,7 @@ public function format_root_set($open, $name, $attrs, $props) { } else { $this->resolveLinks($this->cchunk["setname"]); $pdfDoc = parent::getPdfDoc(); - v("Writing Full PDF Manual (%s)", $this->cchunk["setname"], VERBOSE_TOC_WRITING); + $this->outputHandler->v("Writing Full PDF Manual (%s)", $this->cchunk["setname"], VERBOSE_TOC_WRITING); $filename = $this->getOutputDir(); if ($this->config->output_filename()) { @@ -73,5 +76,3 @@ public function format_book($open, $name, $attrs, $props) { return $this->format_tocnode_newpage($open, $name, $attrs, $props); } } - - diff --git a/phpdotnet/phd/Package/PHP/BigXHTML.php b/phpdotnet/phd/Package/PHP/BigXHTML.php index 7fe771b6..d0380b98 100644 --- a/phpdotnet/phd/Package/PHP/BigXHTML.php +++ b/phpdotnet/phd/Package/PHP/BigXHTML.php @@ -2,8 +2,11 @@ namespace phpdotnet\phd; class Package_PHP_BigXHTML extends Package_PHP_XHTML { - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("PHP-BigXHTML"); $this->setTitle("PHP Manual"); $this->setChunked(false); @@ -98,7 +101,7 @@ public function update($event, $value = null) { break; case Render::VERBOSE: - v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); + $this->outputHandler->v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); break; } } @@ -117,5 +120,3 @@ public function createLink($for, &$desc = null, $type = self::SDESC) { } } - - diff --git a/phpdotnet/phd/Package/PHP/CHM.php b/phpdotnet/phd/Package/PHP/CHM.php index ebe64ab2..5fbef332 100644 --- a/phpdotnet/phd/Package/PHP/CHM.php +++ b/phpdotnet/phd/Package/PHP/CHM.php @@ -202,8 +202,11 @@ class Package_PHP_CHM extends Package_PHP_ChunkedXHTML // Project files Output directory protected $chmdir; - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("PHP-CHM"); } @@ -446,5 +449,3 @@ public function format_link($open, $name, $attrs, $props) { return $link; } } - - diff --git a/phpdotnet/phd/Package/PHP/ChunkedXHTML.php b/phpdotnet/phd/Package/PHP/ChunkedXHTML.php index 5fecfea7..8e134363 100644 --- a/phpdotnet/phd/Package/PHP/ChunkedXHTML.php +++ b/phpdotnet/phd/Package/PHP/ChunkedXHTML.php @@ -2,8 +2,11 @@ namespace phpdotnet\phd; class Package_PHP_ChunkedXHTML extends Package_PHP_Web { - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("PHP-Chunked-XHTML"); $this->setExt($this->config->ext() === null ? ".html" : $this->config->ext()); } @@ -81,5 +84,3 @@ public function footer($id) return ''; } } - - diff --git a/phpdotnet/phd/Package/PHP/EnhancedCHM.php b/phpdotnet/phd/Package/PHP/EnhancedCHM.php index 3875d5d6..abc8fcb6 100644 --- a/phpdotnet/phd/Package/PHP/EnhancedCHM.php +++ b/phpdotnet/phd/Package/PHP/EnhancedCHM.php @@ -9,8 +9,11 @@ class Package_PHP_EnhancedCHM extends Package_PHP_CHM // Where are the usernotes? protected $userNotesBaseDir = null; - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("PHP-EnhancedCHM"); } @@ -37,7 +40,7 @@ public function update($event, $value = null) { $userNotesLastUpdatedLocal = file_exists($this->userNotesBaseDir . 'last-updated') ? intval(file_get_contents($this->userNotesBaseDir . 'last-updated')) : 0; // Get the remote last-updated value to see if we need to do anything with the usernotes we already have. - v('Checking usernotes.', VERBOSE_MESSAGES); + $this->outputHandler->v('Checking usernotes.', VERBOSE_MESSAGES); $userNotesLastUpdatedRemote = intval(file_get_contents('http://www.php.net/backend/notes/last-updated')); // Compare the remote and local last-updated values. @@ -68,7 +71,7 @@ public function update($event, $value = null) { $fpsfNotes = stream_filter_append($fpNotes, 'bzip2.decompress', STREAM_FILTER_READ, array('small' => true)); // Extract the usernotes and store them by page and date. - v('Preparing usernotes.', VERBOSE_MESSAGES); + $this->outputHandler->v('Preparing usernotes.', VERBOSE_MESSAGES); // Decompress the 'all' file into single files - one file per sectionid. while($fpNotes && !feof($fpNotes) && false !== ($userNote = fgetcsv($fpNotes, 0, '|'))) { @@ -97,9 +100,9 @@ public function update($event, $value = null) { file_put_contents($this->userNotesBaseDir . 'last-updated', $userNotesLastUpdatedRemote); $this->haveNotes = true; - v('Usernotes prepared.', VERBOSE_MESSAGES); + $this->outputHandler->v('Usernotes prepared.', VERBOSE_MESSAGES); } else { - v('Usernotes not updated.', VERBOSE_MESSAGES); + $this->outputHandler->v('Usernotes not updated.', VERBOSE_MESSAGES); } break; diff --git a/phpdotnet/phd/Package/PHP/Epub.php b/phpdotnet/phd/Package/PHP/Epub.php index ffe5918d..80a46e38 100644 --- a/phpdotnet/phd/Package/PHP/Epub.php +++ b/phpdotnet/phd/Package/PHP/Epub.php @@ -23,8 +23,11 @@ class Package_PHP_Epub extends Package_PHP_ChunkedXHTML 'epub_file' => '', ); - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->setExt('.xhtml'); $this->registerFormatName("PHP-Epub"); } @@ -323,5 +326,3 @@ public function format_link($open, $name, $attrs, $props) { return $link; } } - - diff --git a/phpdotnet/phd/Package/PHP/HowTo.php b/phpdotnet/phd/Package/PHP/HowTo.php index 18e9cf62..40530eb8 100644 --- a/phpdotnet/phd/Package/PHP/HowTo.php +++ b/phpdotnet/phd/Package/PHP/HowTo.php @@ -4,8 +4,11 @@ class Package_PHP_HowTo extends Package_PHP_Web { private $nav = ""; - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("PHP-HowTo"); } @@ -85,5 +88,3 @@ public function footer($id) { return "$nav\n"; } } - - diff --git a/phpdotnet/phd/Package/PHP/KDevelop.php b/phpdotnet/phd/Package/PHP/KDevelop.php index b51f68f8..3fa39e2d 100644 --- a/phpdotnet/phd/Package/PHP/KDevelop.php +++ b/phpdotnet/phd/Package/PHP/KDevelop.php @@ -65,8 +65,11 @@ class Package_PHP_KDevelop extends Format { // CHM Index Map protected $hhkStream; - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("PHP-KDevelop"); $this->setTitle("PHP Manual"); $this->setExt($this->config->ext() === null ? ".php" : $this->config->ext()); @@ -100,7 +103,7 @@ public function update($event, $value = null) { } break; case Render::VERBOSE: - v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); + $this->outputHandler->v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); break; } } @@ -166,5 +169,3 @@ public function format_refname_text($value, $tag) { } } - - diff --git a/phpdotnet/phd/Package/PHP/Manpage.php b/phpdotnet/phd/Package/PHP/Manpage.php index d67de9e9..019e6049 100644 --- a/phpdotnet/phd/Package/PHP/Manpage.php +++ b/phpdotnet/phd/Package/PHP/Manpage.php @@ -37,8 +37,11 @@ class Package_PHP_Manpage extends Package_Generic_Manpage { /* Default Chunk settings */ protected $dchunk = array(); - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("PHP-Functions"); $this->setTitle("PHP Manual"); @@ -98,5 +101,3 @@ public function close() { } } - - diff --git a/phpdotnet/phd/Package/PHP/PDF.php b/phpdotnet/phd/Package/PHP/PDF.php index de1dd489..74b52381 100644 --- a/phpdotnet/phd/Package/PHP/PDF.php +++ b/phpdotnet/phd/Package/PHP/PDF.php @@ -95,8 +95,11 @@ class Package_PHP_PDF extends Package_Generic_PDF { "root-outline" => null, ); - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("PHP-PDF"); $this->setTitle("PHP Manual"); } @@ -121,7 +124,7 @@ public function update($event, $value = null) { if(!file_exists($this->getOutputDir()) || is_file($this->getOutputDir())) mkdir($this->getOutputDir(), 0777, true) or die("Can't create the cache directory.\n"); break; case Render::VERBOSE: - v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); + $this->outputHandler->v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); break; } } @@ -162,7 +165,7 @@ public function format_book($open, $name, $attrs, $props) { } else { $this->resolveLinks($this->cchunk["bookname"]); $pdfDoc = parent::getPdfDoc(); - v("Writing PDF Manual (%s)", $this->cchunk["bookname"], VERBOSE_TOC_WRITING); + $this->outputHandler->v("Writing PDF Manual (%s)", $this->cchunk["bookname"], VERBOSE_TOC_WRITING); $pdfDoc->saveToFile($this->getOutputDir() . $this->toValidName($this->cchunk["bookname"]) . $this->getExt()); unset($pdfDoc); } @@ -237,7 +240,7 @@ protected function setIdToPage($id) { } protected function resolveLinks($name) { - v("Resolving Internal Links... (%s)", $name, VERBOSE_TOC_WRITING); + $this->outputHandler->v("Resolving Internal Links... (%s)", $name, VERBOSE_TOC_WRITING); $linksToResolve = parent::getChunkInfo("links-to-resolve"); foreach ($linksToResolve as $link => $targets) { if (isset($this->cchunk["id-to-page"][$link]) && $destPage = $this->cchunk["id-to-page"][$link]) { @@ -316,5 +319,3 @@ public function format_collect_id($open, $name, $attrs) { } } - - diff --git a/phpdotnet/phd/Package/PHP/TocFeed.php b/phpdotnet/phd/Package/PHP/TocFeed.php index 196a9efd..09767b76 100644 --- a/phpdotnet/phd/Package/PHP/TocFeed.php +++ b/phpdotnet/phd/Package/PHP/TocFeed.php @@ -132,9 +132,11 @@ public function update($event, $value = null) { /** * Create new instance. */ - public function __construct(Config $config) - { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $language = $this->config->language(); $variables = array('targetBaseUri', 'feedBaseUri', 'idprefix'); diff --git a/phpdotnet/phd/Package/PHP/Web.php b/phpdotnet/phd/Package/PHP/Web.php index 83792249..63063c37 100644 --- a/phpdotnet/phd/Package/PHP/Web.php +++ b/phpdotnet/phd/Package/PHP/Web.php @@ -8,8 +8,11 @@ class Package_PHP_Web extends Package_PHP_XHTML { /** $var array> */ protected array $history = []; - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->registerFormatName("PHP-Web"); $this->setTitle("PHP Manual"); $this->setChunked(true); @@ -104,7 +107,7 @@ public function update($event, $value = null) { } break; case Render::VERBOSE: - v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); + $this->outputHandler->v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); break; } } @@ -169,7 +172,7 @@ public function header($id) { file_put_contents($this->getOutputDir() . $filename, $content); - v("Wrote TOC (%s)", $this->getOutputDir() . $filename, VERBOSE_TOC_WRITING); + $this->outputHandler->v("Wrote TOC (%s)", $this->getOutputDir() . $filename, VERBOSE_TOC_WRITING); } $incl = 'include_once dirname(__FILE__) ."/toc/' .$parent. '.inc";'; @@ -233,7 +236,7 @@ public function footer($id) { } protected function writeJsonIndex() { - v("Writing search indexes..", VERBOSE_FORMAT_RENDERING); + $this->outputHandler->v("Writing search indexes..", VERBOSE_FORMAT_RENDERING); [$entries, $descriptions] = $this->processJsonIndex(); file_put_contents( $this->getOutputDir() . "search-index.json", @@ -243,7 +246,7 @@ protected function writeJsonIndex() { $this->getOutputDir() . "search-description.json", json_encode($descriptions) ); - v("Index written", VERBOSE_FORMAT_RENDERING); + $this->outputHandler->v("Index written", VERBOSE_FORMAT_RENDERING); } /** diff --git a/phpdotnet/phd/Package/PHP/XHTML.php b/phpdotnet/phd/Package/PHP/XHTML.php index 885a0935..9a734eb7 100644 --- a/phpdotnet/phd/Package/PHP/XHTML.php +++ b/phpdotnet/phd/Package/PHP/XHTML.php @@ -208,8 +208,11 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML { 'phpdoc' => 'PI_PHPDOCHandler', ); - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); $this->myelementmap = array_merge(parent::getDefaultElementMap(), $this->getDefaultElementMap()); $this->mytextmap = array_merge(parent::getDefaultTextMap(), $this->getDefaultTextMap()); $this->dchunk = array_merge(parent::getDefaultChunkInfo(), $this->getDefaultChunkInfo()); @@ -758,7 +761,7 @@ public function versionInfo($funcname) { if(isset($this->versions[$funcname])) { return $this->versions[$funcname]; } - v("No version info for %s", $funcname, VERBOSE_NOVERSION); + $this->outputHandler->v("No version info for %s", $funcname, VERBOSE_NOVERSION); return false; } @@ -852,7 +855,7 @@ public function format_function_text($value, $tag, $display_value = null) { return '' .$display_value. ''.$desc; } } elseif ($this->CURRENT_ID !== $filename) { - v("No link found for %s", $value, VERBOSE_BROKEN_LINKS); + $this->outputHandler->v("No link found for %s", $value, VERBOSE_BROKEN_LINKS); } return '' .$display_value. ''; diff --git a/phpdotnet/phd/Reader.php b/phpdotnet/phd/Reader.php index 69c54224..796a2d71 100644 --- a/phpdotnet/phd/Reader.php +++ b/phpdotnet/phd/Reader.php @@ -7,8 +7,11 @@ class Reader extends \XMLReader const XMLNS_XLINK = "http://www.w3.org/1999/xlink"; const XMLNS_PHD = "http://www.php.net/ns/phd"; const XMLNS_DOCBOOK = "http://docbook.org/ns/docbook"; + + protected OutputHandler $outputHandler; - public function __construct() { + public function __construct(OutputHandler $outputHandler) { + $this->outputHandler = $outputHandler; } /* Get the content of a named node, or the current node. */ @@ -24,7 +27,7 @@ public function readContent(?string $node = null): string { if (\LIBXML_VERSION >= 20620) { return self::readString(); } - v("You are using libxml2 v%d, but v20620 or newer is preferred", \LIBXML_VERSION, VERBOSE_OLD_LIBXML); + $this->outputHandler->v("You are using libxml2 v%d, but v20620 or newer is preferred", \LIBXML_VERSION, VERBOSE_OLD_LIBXML); $node = $this->name; } diff --git a/phpdotnet/phd/Reader/Partial.php b/phpdotnet/phd/Reader/Partial.php index 3cddbdd7..3a2d5a40 100644 --- a/phpdotnet/phd/Reader/Partial.php +++ b/phpdotnet/phd/Reader/Partial.php @@ -8,11 +8,12 @@ class Reader_Partial extends Reader protected $parents = array(); public function __construct( + OutputHandler $outputHandler, array $render_ids, ?array $skip_ids = [], ?array $parents = [], ) { - parent::__construct(); + parent::__construct($outputHandler); if ($render_ids === []) { throw new \Exception("Didn't get any IDs to seek"); @@ -35,13 +36,13 @@ public function read(): bool { $currentSkip = end($arraySkip); if (isset($this->partial[$id])) { if ($currentPartial == $id) { - v("%s done", $id, VERBOSE_PARTIAL_READING); + $this->outputHandler->v("%s done", $id, VERBOSE_PARTIAL_READING); unset($this->partial[$id]); $currently_reading = false; array_pop($arrayPartial); } else { - v("Starting %s...", $id, VERBOSE_PARTIAL_READING); + $this->outputHandler->v("Starting %s...", $id, VERBOSE_PARTIAL_READING); $currently_reading = $id; $arrayPartial[] = $id; @@ -49,29 +50,29 @@ public function read(): bool { return $ret; } elseif (isset($this->skip[$id])) { if ($currentSkip == $id) { - v("%s done", $id, VERBOSE_PARTIAL_READING); + $this->outputHandler->v("%s done", $id, VERBOSE_PARTIAL_READING); unset($this->skip[$id]); $currently_skipping = false; array_pop($arraySkip); } else { - v("Skipping %s...", $id, VERBOSE_PARTIAL_READING); + $this->outputHandler->v("Skipping %s...", $id, VERBOSE_PARTIAL_READING); $currently_skipping = $id; $arraySkip[] = $id; } } elseif ($currently_skipping && $this->skip[$currently_skipping]) { if ($currentSkip == $id) { - v("Skipping child of %s, %s", $currently_reading, $id, VERBOSE_PARTIAL_CHILD_READING); + $this->outputHandler->v("Skipping child of %s, %s", $currently_reading, $id, VERBOSE_PARTIAL_CHILD_READING); } else { - v("%s done", $id, VERBOSE_PARTIAL_CHILD_READING); + $this->outputHandler->v("%s done", $id, VERBOSE_PARTIAL_CHILD_READING); } } elseif ($currently_reading && $this->partial[$currently_reading]) { if ($currentPartial == $id) { - v("Rendering child of %s, %s", $currently_reading, $id, VERBOSE_PARTIAL_CHILD_READING); + $this->outputHandler->v("Rendering child of %s, %s", $currently_reading, $id, VERBOSE_PARTIAL_CHILD_READING); } else { - v("%s done", $id, VERBOSE_PARTIAL_CHILD_READING); + $this->outputHandler->v("%s done", $id, VERBOSE_PARTIAL_CHILD_READING); } return $ret; diff --git a/phpdotnet/phd/TestGenericChunkedXHTML.php b/phpdotnet/phd/TestGenericChunkedXHTML.php index a8d199a1..175c09cd 100644 --- a/phpdotnet/phd/TestGenericChunkedXHTML.php +++ b/phpdotnet/phd/TestGenericChunkedXHTML.php @@ -2,8 +2,11 @@ namespace phpdotnet\phd; class TestGenericChunkedXHTML extends Package_Generic_ChunkedXHTML { - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); } public function update($event, $value = null) { @@ -36,5 +39,3 @@ public function writeChunk($id, $fp) { echo "Content:" . $content . "\n"; } } - - diff --git a/phpdotnet/phd/TestPHPChunkedXHTML.php b/phpdotnet/phd/TestPHPChunkedXHTML.php index 6deeed4f..24acd3f5 100644 --- a/phpdotnet/phd/TestPHPChunkedXHTML.php +++ b/phpdotnet/phd/TestPHPChunkedXHTML.php @@ -2,8 +2,11 @@ namespace phpdotnet\phd; class TestPHPChunkedXHTML extends Package_PHP_ChunkedXHTML { - public function __construct(Config $config) { - parent::__construct($config); + public function __construct( + Config $config, + OutputHandler $outputHandler + ) { + parent::__construct($config, $outputHandler); } public function update($event, $value = null) { diff --git a/phpdotnet/phd/functions.php b/phpdotnet/phd/functions.php deleted file mode 100644 index d38ec86c..00000000 --- a/phpdotnet/phd/functions.php +++ /dev/null @@ -1,140 +0,0 @@ - 'E_DEPRECATED ', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR ', - E_STRICT => 'E_STRICT ', - E_WARNING => 'E_WARNING ', - E_NOTICE => 'E_NOTICE ', - - // User Triggered Errors - E_USER_ERROR => 'E_USER_ERROR ', - E_USER_WARNING => 'E_USER_WARNING ', - E_USER_NOTICE => 'E_USER_NOTICE ', - E_USER_DEPRECATED => 'E_USER_DEPRECATED ', - - // PhD informationals - VERBOSE_INDEXING => 'Indexing ', - VERBOSE_FORMAT_RENDERING => 'Rendering Format ', - VERBOSE_THEME_RENDERING => 'Rendering Theme ', - VERBOSE_RENDER_STYLE => 'Rendering Style ', - VERBOSE_PARTIAL_READING => 'Partial Reading ', - VERBOSE_PARTIAL_CHILD_READING => 'Partial Child Reading ', - VERBOSE_TOC_WRITING => 'Writing TOC ', - VERBOSE_CHUNK_WRITING => 'Writing Chunk ', - VERBOSE_MESSAGES => 'Heads up ', - - // PhD warnings - VERBOSE_NOVERSION => 'No version information', - VERBOSE_BROKEN_LINKS => 'Broken links ', - VERBOSE_OLD_LIBXML => 'Old libxml2 ', - VERBOSE_MISSING_ATTRIBUTES => 'Missing attributes ', - ); - static $recursive = false; - - // Respect the error_reporting setting - if (!(error_reporting() & $errno)) { - return false; - } - - // Recursive protection - if ($recursive) { - // Thats bad.. lets print a backtrace right away - debug_print_backtrace(); - // Fallback to the default errorhandler - return false; - } - $recursive = true; - - $time = date(Config::date_format()); - switch($errno) { - case VERBOSE_INDEXING: - case VERBOSE_FORMAT_RENDERING: - case VERBOSE_THEME_RENDERING: - case VERBOSE_RENDER_STYLE: - case VERBOSE_PARTIAL_READING: - case VERBOSE_PARTIAL_CHILD_READING: - case VERBOSE_TOC_WRITING: - case VERBOSE_CHUNK_WRITING: - case VERBOSE_MESSAGES: - $color = Config::phd_info_color(); - $output = Config::phd_info_output(); - $data = $msg; - break; - - case VERBOSE_NOVERSION: - case VERBOSE_BROKEN_LINKS: - case VERBOSE_MISSING_ATTRIBUTES: - $color = Config::phd_warning_color(); - $output = Config::phd_warning_output(); - $data = $msg; - break; - - // User triggered errors - case E_USER_ERROR: - case E_USER_WARNING: - case E_USER_NOTICE: - $color = Config::user_error_color(); - $output = Config::user_error_output(); - $data = sprintf("%s:%d\n\t%s", $file, $line, $msg); - break; - - // PHP triggered errors - case E_DEPRECATED: - case E_RECOVERABLE_ERROR: - case E_STRICT: - case E_WARNING: - case E_NOTICE: - $color = Config::php_error_color(); - $output = Config::php_error_output(); - $data = sprintf("%s:%d\n\t%s", $file, $line, $msg); - break; - - default: - $recursive = false; - return false; - } - - $timestamp = term_color(sprintf("[%s - %s]", $time, $err[$errno]), $color); - fprintf($output, "%s %s\n", $timestamp, $data); - - // Abort on fatal errors - if ($errno & (E_USER_ERROR|E_RECOVERABLE_ERROR)) { - exit(1); - } - - $recursive = false; - return true; -} -/* }}} */ -set_error_handler(__NAMESPACE__ . '\\errh'); -/* }}} */ diff --git a/render.php b/render.php index 50d88995..54860066 100644 --- a/render.php +++ b/render.php @@ -4,18 +4,24 @@ require_once __DIR__ . '/phpdotnet/phd/constants.php'; require_once __INSTALLDIR__ . '/phpdotnet/phd/Autoloader.php'; -require_once __INSTALLDIR__ . '/phpdotnet/phd/functions.php'; Autoloader::setPackageDirs([__INSTALLDIR__]); spl_autoload_register(array(__NAMESPACE__ . "\\Autoloader", "autoload")); $config = new Config; +$outputHandler = new OutputHandler($config); + +$errorHandler = new ErrorHandler($outputHandler); +$olderrrep = error_reporting(); +error_reporting($olderrrep | VERBOSE_DEFAULT); +set_error_handler($errorHandler->handleError(...)); + $conf = array(); if (file_exists("phd.config.php")) { $conf = include "phd.config.php"; $config->init($conf); - v("Loaded config from existing file", VERBOSE_MESSAGES); + $outputHandler->v("Loaded config from existing file", VERBOSE_MESSAGES); } else { // need to init regardless so we get package-dirs from the include-path $config->init(array()); @@ -28,7 +34,7 @@ } } $optionsParser = new Options_Parser( - new Options_Handler($config, new Package_Generic_Factory), + new Options_Handler($config, new Package_Generic_Factory, $outputHandler), ...$packageHandlers ); $commandLineOptions = $optionsParser->getopt(); @@ -44,11 +50,11 @@ trigger_error("No Docbook file given. Specify it on the command line with --docbook.", E_USER_ERROR); } if (!file_exists($config->output_dir())) { - v("Creating output directory..", VERBOSE_MESSAGES); + $outputHandler->v("Creating output directory..", VERBOSE_MESSAGES); if (!mkdir($config->output_dir(), 0777, True)) { trigger_error(vsprintf("Can't create output directory : %s", [$config->output_dir()]), E_USER_ERROR); } - v("Output directory created", VERBOSE_MESSAGES); + $outputHandler->v("Output directory created", VERBOSE_MESSAGES); } elseif (!is_dir($config->output_dir())) { trigger_error("Output directory is not a file?", E_USER_ERROR); } @@ -67,7 +73,7 @@ } if ($config->saveconfig()) { - v("Writing the config file", VERBOSE_MESSAGES); + $outputHandler->v("Writing the config file", VERBOSE_MESSAGES); file_put_contents("phd.config.php", "getAllFiltered(), 1) . ";"); } @@ -75,11 +81,11 @@ exit(0); } -function make_reader(Config $config) { +function make_reader(Config $config, OutputHandler $outputHandler) { //Partial Rendering $idlist = $config->render_ids() + $config->skip_ids(); if (!empty($idlist)) { - v("Running partial build", VERBOSE_RENDER_STYLE); + $outputHandler->v("Running partial build", VERBOSE_RENDER_STYLE); $parents = []; if ($config->indexcache()) { @@ -87,13 +93,14 @@ function make_reader(Config $config) { } $reader = new Reader_Partial( + $outputHandler, $config->render_ids(), $config->skip_ids(), - $parents + $parents, ); } else { - v("Running full build", VERBOSE_RENDER_STYLE); - $reader = new Reader(); + $outputHandler->v("Running full build", VERBOSE_RENDER_STYLE); + $reader = new Reader($outputHandler); } return $reader; } @@ -122,20 +129,21 @@ function make_reader(Config $config) { // Indexing if ($config->requiresIndexing()) { - v("Indexing...", VERBOSE_INDEXING); + $outputHandler->v("Indexing...", VERBOSE_INDEXING); // Create indexer - $format = new Index($config->indexcache(), $config); + $format = new Index($config->indexcache(), $config, $outputHandler); + $render->attach($format); - $reader = make_reader($config); + $reader = make_reader($config, $outputHandler); $reader->open($config->xml_file(), NULL, $readerOpts); $render->execute($reader); $render->detach($format); - v("Indexing done", VERBOSE_INDEXING); + $outputHandler->v("Indexing done", VERBOSE_INDEXING); } else { - v("Skipping indexing", VERBOSE_INDEXING); + $outputHandler->v("Skipping indexing", VERBOSE_INDEXING); } foreach((array)$config->package() as $package) { @@ -148,16 +156,16 @@ function make_reader(Config $config) { // Register the formats foreach ($config->output_format() as $format) { - $render->attach($factory->createFormat($format, $config)); + $render->attach($factory->createFormat($format, $config, $outputHandler)); } } // Render formats -$reader = make_reader($config); +$reader = make_reader($config, $outputHandler); $reader->open($config->xml_file(), NULL, $readerOpts); foreach($render as $format) { $format->notify(Render::VERBOSE, true); } $render->execute($reader); -v("Finished rendering", VERBOSE_FORMAT_RENDERING); +$outputHandler->v("Finished rendering", VERBOSE_FORMAT_RENDERING); diff --git a/tests/bug_GH-87.phpt b/tests/bug_GH-87.phpt index b5f6e1eb..eca6ba69 100644 --- a/tests/bug_GH-87.phpt +++ b/tests/bug_GH-87.phpt @@ -15,15 +15,15 @@ $indexRepository = new IndexRepository(new \SQLite3(":memory:")); $indexRepository->init(); $config->set_indexcache($indexRepository); -$index = new TestIndex($indexRepository, $config); +$index = new TestIndex($indexRepository, $config, $outputHandler); -$render = new TestRender(new Reader, $config, null, $index); +$render = new TestRender(new Reader($outputHandler), $config, null, $index); $render->run(); -$render = new TestRender(new Reader, $config); +$render = new TestRender(new Reader($outputHandler), $config); -$format = new TestGenericChunkedXHTML($config); +$format = new TestGenericChunkedXHTML($config, $outputHandler); $render->attach($format); diff --git a/tests/bug_doc-en_GH-3353.phpt b/tests/bug_doc-en_GH-3353.phpt index ef1bf9ea..e8a698ea 100644 --- a/tests/bug_doc-en_GH-3353.phpt +++ b/tests/bug_doc-en_GH-3353.phpt @@ -19,10 +19,10 @@ $config->set_indexcache($indexRepository); // Indexing -$index = new TestIndex($indexRepository, $config); +$index = new TestIndex($indexRepository, $config, $outputHandler); $render->attach($index); -$reader = new Reader; +$reader = new Reader($outputHandler); $reader->open($config->xml_file(), null, LIBXML_PARSEHUGE | LIBXML_XINCLUDE); $render->execute($reader); @@ -30,10 +30,10 @@ $render->detach($index); // Rendering -$format = new TestPHPChunkedXHTML($config); +$format = new TestPHPChunkedXHTML($config, $outputHandler); $render->attach($format); -$reader = new Reader; +$reader = new Reader($outputHandler); $reader->open($config->xml_file(), null, LIBXML_PARSEHUGE | LIBXML_XINCLUDE); $render->execute($reader); diff --git a/tests/bug_doc-en_GH-3428.phpt b/tests/bug_doc-en_GH-3428.phpt index b0746f42..2efdc0f5 100644 --- a/tests/bug_doc-en_GH-3428.phpt +++ b/tests/bug_doc-en_GH-3428.phpt @@ -15,9 +15,9 @@ $indexRepository = new IndexRepository(new \SQLite3(":memory:")); $indexRepository->init(); $config->set_indexcache($indexRepository); -$index = new TestIndex($indexRepository, $config); +$index = new TestIndex($indexRepository, $config, $outputHandler); -$render = new TestRender(new Reader, $config, null, $index); +$render = new TestRender(new Reader($outputHandler), $config, null, $index); $render->run(); @@ -27,11 +27,11 @@ echo "Indexes stored:\n"; var_dump($indexes); -$render = new TestRender(new Reader, $config); +$render = new TestRender(new Reader($outputHandler), $config); -$format1 = new TestGenericChunkedXHTML($config); -$format2 = new TestGenericChunkedXHTML($config); -$format3 = new TestGenericChunkedXHTML($config); +$format1 = new TestGenericChunkedXHTML($config, $outputHandler); +$format2 = new TestGenericChunkedXHTML($config, $outputHandler); +$format3 = new TestGenericChunkedXHTML($config, $outputHandler); $render->attach($format1); $render->attach($format2); diff --git a/tests/example_numbering_001.phpt b/tests/example_numbering_001.phpt index fd64ffe6..1cb729f3 100644 --- a/tests/example_numbering_001.phpt +++ b/tests/example_numbering_001.phpt @@ -15,9 +15,9 @@ $indexRepository = new IndexRepository(new \SQLite3(":memory:")); $indexRepository->init(); $config->set_indexcache($indexRepository); -$index = new TestIndex($indexRepository, $config); +$index = new TestIndex($indexRepository, $config, $outputHandler); -$render = new TestRender(new Reader, $config, null, $index); +$render = new TestRender(new Reader($outputHandler), $config, null, $index); $render->run(); @@ -27,9 +27,9 @@ echo "Indexes stored:\n"; var_dump($indexes); -$format = new TestGenericChunkedXHTML($config); +$format = new TestGenericChunkedXHTML($config, $outputHandler); -$render = new TestRender(new Reader, $config, $format); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); diff --git a/tests/index/bug_GH-98.phpt b/tests/index/bug_GH-98.phpt index af0f8c81..ff13cea9 100644 --- a/tests/index/bug_GH-98.phpt +++ b/tests/index/bug_GH-98.phpt @@ -14,8 +14,8 @@ $config->setXml_file($xml_file); $indexRepository = new IndexRepository(new \SQLite3(":memory:")); $indexRepository->init(); -$index = new TestIndex($indexRepository, $config); -$render = new TestRender(new Reader, $config, null, $index); +$index = new TestIndex($indexRepository, $config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, null, $index); $render->run(); diff --git a/tests/index/indexing_001.phpt b/tests/index/indexing_001.phpt index 7c4ac94f..c4921979 100644 --- a/tests/index/indexing_001.phpt +++ b/tests/index/indexing_001.phpt @@ -14,8 +14,8 @@ $config->setXml_file($xml_file); $indexRepository = new IndexRepository(new \SQLite3(":memory:")); $indexRepository->init(); -$index = new TestIndex($indexRepository, $config); -$render = new TestRender(new Reader, $config, null, $index); +$index = new TestIndex($indexRepository, $config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, null, $index); $render->run(); diff --git a/tests/options/default_handler_005.phpt b/tests/options/default_handler_005.phpt index 7bd54b4d..7fe5863f 100644 --- a/tests/options/default_handler_005.phpt +++ b/tests/options/default_handler_005.phpt @@ -16,9 +16,9 @@ require_once __DIR__ . "/../../render.php"; ?> --EXPECTF-- %sPhD Version: %s - %sGeneric%s: %s - %sIDE%s: %s - %sPEAR%s: %s - %sPHP%s: %s +%s Generic: %s +%s IDE: %s +%s PEAR: %s +%s PHP: %s %sPHP Version: %s %sCopyright(c) %d-%d The PHP Documentation Group%s diff --git a/tests/options/default_handler_006.phpt b/tests/options/default_handler_006.phpt index 7c80bfbc..6ca69c8a 100644 --- a/tests/options/default_handler_006.phpt +++ b/tests/options/default_handler_006.phpt @@ -16,9 +16,9 @@ require_once __DIR__ . "/../../render.php"; ?> --EXPECTF-- %sPhD Version: %s - %sGeneric%s: %s - %sIDE%s: %s - %sPEAR%s: %s - %sPHP%s: %s +%s Generic: %s +%s IDE: %s +%s PEAR: %s +%s PHP: %s %sPHP Version: %s %sCopyright(c) %d-%d The PHP Documentation Group%s diff --git a/tests/options/default_handler_009.phpt b/tests/options/default_handler_009.phpt index 786bf8b6..948df0b4 100644 --- a/tests/options/default_handler_009.phpt +++ b/tests/options/default_handler_009.phpt @@ -15,7 +15,11 @@ namespace phpdotnet\phd; require_once __DIR__ . "/../setup.php"; $optionsParser = new Options_Parser( - new Options_Handler($config, new Package_Generic_Factory) + new Options_Handler( + $config, + new Package_Generic_Factory, + new OutputHandler($config) + ) ); $commandLineOptions = $optionsParser->getopt(); diff --git a/tests/options/default_handler_010.phpt b/tests/options/default_handler_010.phpt index 70ce7f74..24aab92f 100644 --- a/tests/options/default_handler_010.phpt +++ b/tests/options/default_handler_010.phpt @@ -15,7 +15,11 @@ namespace phpdotnet\phd; require_once __DIR__ . "/../setup.php"; $optionsParser = new Options_Parser( - new Options_Handler($config, new Package_Generic_Factory) + new Options_Handler( + $config, + new Package_Generic_Factory, + new OutputHandler($config) + ) ); $commandLineOptions = $optionsParser->getopt(); diff --git a/tests/package/generic/001.phpt b/tests/package/generic/001.phpt index ed5a026c..95ab7a23 100644 --- a/tests/package/generic/001.phpt +++ b/tests/package/generic/001.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/001-1.xml"; $config->setXml_file($xml_file); -$format = new TestGenericChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestGenericChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/generic/002.phpt b/tests/package/generic/002.phpt index c49b239b..bd9aa51a 100644 --- a/tests/package/generic/002.phpt +++ b/tests/package/generic/002.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/002.xml"; $config->setXml_file($xml_file); -$format = new TestGenericChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestGenericChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/generic/003.phpt b/tests/package/generic/003.phpt index 892fd3bd..ffc7efd8 100644 --- a/tests/package/generic/003.phpt +++ b/tests/package/generic/003.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/003.xml"; $config->setXml_file($xml_file); -$format = new TestGenericChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestGenericChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/generic/attribute_formatting_001.phpt b/tests/package/generic/attribute_formatting_001.phpt index 2cefb6f0..994a64b9 100644 --- a/tests/package/generic/attribute_formatting_001.phpt +++ b/tests/package/generic/attribute_formatting_001.phpt @@ -10,7 +10,7 @@ $xml_file = __DIR__ . "/data/attribute_formatting_001.xml"; $config->setXml_file($xml_file); -$format = new TestGenericChunkedXHTML($config); +$format = new TestGenericChunkedXHTML($config, $outputHandler); $format->SQLiteIndex( null, // $context, @@ -26,7 +26,7 @@ $format->SQLiteIndex( 0, // $chunk ); -$render = new TestRender(new Reader, $config, $format); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/generic/attribute_formatting_002.phpt b/tests/package/generic/attribute_formatting_002.phpt index 5eb4cf36..4543bc87 100644 --- a/tests/package/generic/attribute_formatting_002.phpt +++ b/tests/package/generic/attribute_formatting_002.phpt @@ -10,7 +10,7 @@ $xml_file = __DIR__ . "/data/attribute_formatting_002.xml"; $config->setXml_file($xml_file); -$format = new TestGenericChunkedXHTML($config); +$format = new TestGenericChunkedXHTML($config, $outputHandler); $format->SQLiteIndex( null, // $context, @@ -39,7 +39,7 @@ $format->SQLiteIndex( 0, // $chunk ); -$render = new TestRender(new Reader, $config, $format); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/generic/attribute_formatting_003.phpt b/tests/package/generic/attribute_formatting_003.phpt index be630ccf..42bf69ae 100644 --- a/tests/package/generic/attribute_formatting_003.phpt +++ b/tests/package/generic/attribute_formatting_003.phpt @@ -12,7 +12,7 @@ $config = new Config; $config->setXml_file($xml_file); -$format = new TestGenericChunkedXHTML($config); +$format = new TestGenericChunkedXHTML($config, $outputHandler); $format->SQLiteIndex( null, // $context, @@ -41,7 +41,7 @@ $format->SQLiteIndex( 0, // $chunk ); -$render = new TestRender(new Reader, $config, $format); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/generic/caption_001.phpt b/tests/package/generic/caption_001.phpt index a281fc4a..6390bb36 100644 --- a/tests/package/generic/caption_001.phpt +++ b/tests/package/generic/caption_001.phpt @@ -10,9 +10,9 @@ $xml_file = __DIR__ . "/data/caption_001.xml"; $config->setXml_file($xml_file); -$format = new TestGenericChunkedXHTML($config); +$format = new TestGenericChunkedXHTML($config, $outputHandler); $format->postConstruct(); -$render = new TestRender(new Reader, $config, $format); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/generic/simplelist_001.phpt b/tests/package/generic/simplelist_001.phpt index be021beb..ad592da8 100644 --- a/tests/package/generic/simplelist_001.phpt +++ b/tests/package/generic/simplelist_001.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/simplelist.xml"; $config->setXml_file($xml_file); -$format = new TestGenericChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestGenericChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/generic/whitespace_formatting_001.phpt b/tests/package/generic/whitespace_formatting_001.phpt index 612f4042..cbe0384a 100644 --- a/tests/package/generic/whitespace_formatting_001.phpt +++ b/tests/package/generic/whitespace_formatting_001.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/whitespace_formatting_001.xml"; $config->setXml_file($xml_file); -$format = new TestGenericChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestGenericChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/php/bug49101-1.phpt b/tests/package/php/bug49101-1.phpt index c1cf95d9..1677b243 100644 --- a/tests/package/php/bug49101-1.phpt +++ b/tests/package/php/bug49101-1.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/bug49101-1.xml"; $config->setXml_file($xml_file); -$format = new TestPHPChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestPHPChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/php/bug49101-2.phpt b/tests/package/php/bug49101-2.phpt index 9c90ee8c..5cc8ddad 100644 --- a/tests/package/php/bug49101-2.phpt +++ b/tests/package/php/bug49101-2.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/bug49101-1.xml"; $config->setXml_file($xml_file); -$format = new TestPHPBigXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestPHPBigXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/php/bug49102-1.phpt b/tests/package/php/bug49102-1.phpt index cb0f50c4..d79cbc7e 100644 --- a/tests/package/php/bug49102-1.phpt +++ b/tests/package/php/bug49102-1.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/bug49102-1.xml"; $config->setXml_file($xml_file); -$format = new TestPHPChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestPHPChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/php/bug_doc-en_GH-3179.phpt b/tests/package/php/bug_doc-en_GH-3179.phpt index 0365aa39..c47acbf9 100644 --- a/tests/package/php/bug_doc-en_GH-3179.phpt +++ b/tests/package/php/bug_doc-en_GH-3179.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/bug_doc-en_GH-3197.xml"; $config->setXml_file($xml_file); -$format = new TestPHPChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestPHPChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/php/class_rendering_001.phpt b/tests/package/php/class_rendering_001.phpt index 0ae01472..fadf3d19 100644 --- a/tests/package/php/class_rendering_001.phpt +++ b/tests/package/php/class_rendering_001.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/class_rendering_001.xml"; $config->setXml_file($xml_file); -$format = new TestPHPChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestPHPChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/php/class_rendering_002.phpt b/tests/package/php/class_rendering_002.phpt index d8bddadb..dbe4fbe5 100644 --- a/tests/package/php/class_rendering_002.phpt +++ b/tests/package/php/class_rendering_002.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/class_rendering_002.xml"; $config->setXml_file($xml_file); -$format = new TestPHPChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestPHPChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/php/class_rendering_003.phpt b/tests/package/php/class_rendering_003.phpt index a43351b2..ab2e8475 100644 --- a/tests/package/php/class_rendering_003.phpt +++ b/tests/package/php/class_rendering_003.phpt @@ -10,8 +10,8 @@ $xml_filePhpdoc = __DIR__ . "/data/class_rendering_001.xml"; $config->setXml_file($xml_filePhpdoc); -$formatPhpdoc = new TestPHPChunkedXHTML($config); -$renderPhpdoc = new TestRender(new Reader, $config, $formatPhpdoc); +$formatPhpdoc = new TestPHPChunkedXHTML($config, $outputHandler); +$renderPhpdoc = new TestRender(new Reader($outputHandler), $config, $formatPhpdoc); ob_start(); $renderPhpdoc->run(); @@ -22,8 +22,8 @@ $xml_fileReferenceWithRole = __DIR__ . "/data/class_rendering_002.xml"; $config->setXml_file($xml_fileReferenceWithRole); -$formatReferenceWithRole = new TestPHPChunkedXHTML($config); -$renderReferenceWithRole = new TestRender(new Reader, $config, $formatReferenceWithRole); +$formatReferenceWithRole = new TestPHPChunkedXHTML($config, $outputHandler); +$renderReferenceWithRole = new TestRender(new Reader($outputHandler), $config, $formatReferenceWithRole); ob_start(); $renderReferenceWithRole->run(); diff --git a/tests/package/php/constant_links_001.phpt b/tests/package/php/constant_links_001.phpt index ee3e9280..01c6f3e7 100644 --- a/tests/package/php/constant_links_001.phpt +++ b/tests/package/php/constant_links_001.phpt @@ -33,7 +33,7 @@ $indices = [ ], ]; -$format = new TestPHPChunkedXHTML($config); +$format = new TestPHPChunkedXHTML($config, $outputHandler); foreach ($indices as $index) { $format->SQLiteIndex( @@ -51,7 +51,7 @@ foreach ($indices as $index) { ); } -$render = new TestRender(new Reader, $config, $format); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/php/exception_rendering_001.phpt b/tests/package/php/exception_rendering_001.phpt index 19bf3183..e6dba3ab 100644 --- a/tests/package/php/exception_rendering_001.phpt +++ b/tests/package/php/exception_rendering_001.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/exception_rendering_001.xml"; $config->setXml_file($xml_file); -$format = new TestPHPChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestPHPChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/php/exception_rendering_002.phpt b/tests/package/php/exception_rendering_002.phpt index 8b7ae200..69a997a0 100644 --- a/tests/package/php/exception_rendering_002.phpt +++ b/tests/package/php/exception_rendering_002.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/exception_rendering_002.xml"; $config->setXml_file($xml_file); -$format = new TestPHPChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestPHPChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/php/exception_rendering_003.phpt b/tests/package/php/exception_rendering_003.phpt index 0d0cfc94..e47903cc 100644 --- a/tests/package/php/exception_rendering_003.phpt +++ b/tests/package/php/exception_rendering_003.phpt @@ -10,8 +10,8 @@ $xml_filePhpdoc = __DIR__ . "/data/exception_rendering_001.xml"; $config->setXml_file($xml_filePhpdoc); -$formatPhpdoc = new TestPHPChunkedXHTML($config); -$renderPhpdoc = new TestRender(new Reader, $config, $formatPhpdoc); +$formatPhpdoc = new TestPHPChunkedXHTML($config, $outputHandler); +$renderPhpdoc = new TestRender(new Reader($outputHandler), $config, $formatPhpdoc); ob_start(); $renderPhpdoc->run(); @@ -22,8 +22,8 @@ $xml_fileReferenceWithRole = __DIR__ . "/data/exception_rendering_002.xml"; $config->setXml_file($xml_fileReferenceWithRole); -$formatReferenceWithRole = new TestPHPChunkedXHTML($config); -$renderReferenceWithRole = new TestRender(new Reader, $config, $formatReferenceWithRole); +$formatReferenceWithRole = new TestPHPChunkedXHTML($config, $outputHandler); +$renderReferenceWithRole = new TestRender(new Reader($outputHandler), $config, $formatReferenceWithRole); ob_start(); $renderReferenceWithRole->run(); diff --git a/tests/package/php/faq001.phpt b/tests/package/php/faq001.phpt index c8908875..84b1bafe 100644 --- a/tests/package/php/faq001.phpt +++ b/tests/package/php/faq001.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/faq001.xml"; $config->setXml_file($xml_file); -$format = new TestPHPChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestPHPChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/php/type_rendering_001.phpt b/tests/package/php/type_rendering_001.phpt index 2f9ebb84..4cb3d1f3 100644 --- a/tests/package/php/type_rendering_001.phpt +++ b/tests/package/php/type_rendering_001.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/type_rendering_methodsynopsis_return_types.xml"; $config->setXml_file($xml_file); -$format = new TestPHPChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestPHPChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/php/type_rendering_002.phpt b/tests/package/php/type_rendering_002.phpt index de15babc..d18d307e 100644 --- a/tests/package/php/type_rendering_002.phpt +++ b/tests/package/php/type_rendering_002.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/type_rendering_methodsynopsis_parameters.xml"; $config->setXml_file($xml_file); -$format = new TestPHPChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestPHPChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/php/type_rendering_003.phpt b/tests/package/php/type_rendering_003.phpt index 016f663e..0781ad86 100644 --- a/tests/package/php/type_rendering_003.phpt +++ b/tests/package/php/type_rendering_003.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/type_rendering_constructorsynopsis_parameters-and-r $config->setXml_file($xml_file); -$format = new TestPHPChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestPHPChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/package/php/variablelist_rendering_001.phpt b/tests/package/php/variablelist_rendering_001.phpt index 2928b1cc..db805c8c 100644 --- a/tests/package/php/variablelist_rendering_001.phpt +++ b/tests/package/php/variablelist_rendering_001.phpt @@ -10,8 +10,8 @@ $xml_file = __DIR__ . "/data/variablelist_rendering_001.xml"; $config->setXml_file($xml_file); -$format = new TestPHPChunkedXHTML($config); -$render = new TestRender(new Reader, $config, $format); +$format = new TestPHPChunkedXHTML($config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, $format); $render->run(); ?> diff --git a/tests/reader/partial_reader_001.phpt b/tests/reader/partial_reader_001.phpt index 81ec14aa..5779de4c 100644 --- a/tests/reader/partial_reader_001.phpt +++ b/tests/reader/partial_reader_001.phpt @@ -31,7 +31,7 @@ $xml = <<getMessage()); } @@ -48,7 +48,7 @@ $skipIds = [ ]; $parentIds = []; -$reader = new Reader_Partial($renderIds, $skipIds, $parentIds); +$reader = new Reader_Partial($outputHandler, $renderIds, $skipIds, $parentIds); $reader->XML($xml); while ($reader->read()) { diff --git a/tests/reader/reader_001.phpt b/tests/reader/reader_001.phpt index 1a6269c9..ea0db113 100644 --- a/tests/reader/reader_001.phpt +++ b/tests/reader/reader_001.phpt @@ -19,7 +19,7 @@ $xml = <<XML($xml); echo "Read current node contents\n"; diff --git a/tests/setup.php b/tests/setup.php index 663206f7..1cb7d59c 100644 --- a/tests/setup.php +++ b/tests/setup.php @@ -3,13 +3,19 @@ require_once dirname(__DIR__) . '/phpdotnet/phd/constants.php'; require_once __INSTALLDIR__ . DIRECTORY_SEPARATOR . "phpdotnet" . DIRECTORY_SEPARATOR . "phd" . DIRECTORY_SEPARATOR . "Autoloader.php"; + Autoloader::setPackageDirs([__INSTALLDIR__]); spl_autoload_register(["phpdotnet\\phd\\Autoloader", "autoload"]); -require_once __INSTALLDIR__ . DIRECTORY_SEPARATOR . "phpdotnet" . DIRECTORY_SEPARATOR . "phd" . DIRECTORY_SEPARATOR . "functions.php"; - $config = new Config; +$outputHandler = new OutputHandler($config); + +$errorHandler = new ErrorHandler($outputHandler); +$olderrrep = error_reporting(); +error_reporting($olderrrep | VERBOSE_DEFAULT); +set_error_handler($errorHandler->handleError(...)); + $config->init([]); $config->setLang_dir(__INSTALLDIR__ . DIRECTORY_SEPARATOR . "phpdotnet" . DIRECTORY_SEPARATOR . "phd" . DIRECTORY_SEPARATOR