Skip to content

Commit 04b2064

Browse files
committed
Convert autoloading to PSR-4 and use composer's autoload
This requires to bump to PHP 8.0 so that 'Abstract' can be used in a namespace This might give us better IDE support and better ways to setup testing...
1 parent bc10e61 commit 04b2064

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1296
-1152
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">=5.3.0",
21+
"php": ">=8.0",
2222
"ext-dom": "*",
2323
"ext-sqlite3": "*",
2424
"ext-xmlreader": "*"
@@ -27,8 +27,8 @@
2727
"easybook/geshi": "For using GeSHi as code highlighter"
2828
},
2929
"autoload": {
30-
"psr-0": {
31-
"phpdotnet\\": "."
30+
"psr-4": {
31+
"phpdotnet\\phd\\": "src/"
3232
}
3333
}
3434
}

phpdotnet/phd/Autoloader.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

phpdotnet/phd/Package/IDE/Factory.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

phpdotnet/phd/Package/PHP/Factory.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

render.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
// @php_dir@ gets replaced by pear with the install dir. use __DIR__ when
66
// running from SVN
7-
define("__INSTALLDIR__", '@php_dir@' == '@'.'php_dir@' ? __DIR__ : '@php_dir@');
8-
9-
require __INSTALLDIR__ . '/phpdotnet/phd/Autoloader.php';
10-
require __INSTALLDIR__ . '/phpdotnet/phd/functions.php';
7+
use phpdotnet\phd\Format\Factory;
8+
use phpdotnet\phd\Options\Parser;
9+
use phpdotnet\phd\Reader\Partial;
1110

12-
spl_autoload_register(array(__NAMESPACE__ . "\\Autoloader", "autoload"));
11+
define("__INSTALLDIR__", '@php_dir@' == '@'.'php_dir@' ? __DIR__ : '@php_dir@');
1312

13+
require_once __INSTALLDIR__ . '/vendor/autoload.php';
14+
require __INSTALLDIR__ . '/src/functions.php';
1415

1516
$conf = array();
1617
if (file_exists("phd.config.php")) {
@@ -22,7 +23,7 @@
2223
Config::init(array());
2324
}
2425

25-
Options_Parser::getopt();
26+
Parser::getopt();
2627

2728
/* If no docbook file was passed, die */
2829
if (!is_dir(Config::xml_root()) || !is_file(Config::xml_file())) {
@@ -62,7 +63,7 @@ function make_reader() {
6263
$idlist = Config::render_ids() + Config::skip_ids();
6364
if (!empty($idlist)) {
6465
v("Running partial build", VERBOSE_RENDER_STYLE);
65-
$reader = new Reader_Partial();
66+
$reader = new Partial();
6667
} else {
6768
v("Running full build", VERBOSE_RENDER_STYLE);
6869
$reader = new Reader();
@@ -97,7 +98,7 @@ function make_reader() {
9798
}
9899

99100
foreach((array)Config::package() as $package) {
100-
$factory = Format_Factory::createFactory($package);
101+
$factory = Factory::createFactory($package);
101102

102103
// Default to all output formats specified by the package
103104
if (count(Config::output_format()) == 0) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static function __callStatic($name, $params)
143143
public static function getSupportedPackages() {
144144
$packageList = array();
145145
foreach(Config::package_dirs() as $dir) {
146-
foreach (glob($dir . "/phpdotnet/phd/Package/*", GLOB_ONLYDIR) as $item) {
146+
foreach (glob($dir . "/src/Package/*", GLOB_ONLYDIR) as $item) {
147147
$baseitem = basename($item);
148148
if ($baseitem[0] != '.') {
149149
$packageList[] = $baseitem;
File renamed without changes.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
2-
namespace phpdotnet\phd;
2+
namespace phpdotnet\phd\Format\Abstract;
33

4-
abstract class Format_Abstract_Manpage extends Format {
4+
use phpdotnet\phd\Format;
5+
6+
abstract class Manpage extends Format {
57
public $role = false;
68

79
public function UNDEF($open, $name, $attrs, $props) {

src/Format/Abstract/PDF.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
namespace phpdotnet\phd\Format\Abstract;
3+
4+
use phpdotnet\phd\Format;
5+
6+
abstract class PDF extends Format {
7+
protected $pdfDoc;
8+
9+
public function getPdfDoc() {
10+
return $this->pdfDoc;
11+
}
12+
13+
public function setPdfDoc($pdfDoc) {
14+
$this->pdfDoc = $pdfDoc;
15+
}
16+
17+
public function UNDEF($open, $name, $attrs, $props) {
18+
if ($open) {
19+
trigger_error("No mapper found for '{$name}'", E_USER_WARNING);
20+
}
21+
$this->pdfDoc->setFont(PdfWriter::FONT_NORMAL, 14, array(1, 0, 0)); // Helvetica 14 red
22+
$this->pdfDoc->appendText(($open ? "<" : "</") . $name . ">");
23+
$this->pdfDoc->revertFont();
24+
return "";
25+
}
26+
27+
public function CDATA($str) {
28+
$this->pdfDoc->appendText(utf8_decode(trim($str)));
29+
return "";
30+
}
31+
32+
public function transformFromMap($open, $tag, $name, $attrs, $props) {
33+
return "";
34+
}
35+
36+
public function createLink($for, &$desc = null, $type = Format::SDESC){}
37+
38+
public function TEXT($str) {}
39+
40+
}

0 commit comments

Comments
 (0)