Skip to content

Commit

Permalink
Invoke Config instance methods instead of static methods from Format …
Browse files Browse the repository at this point in the history
…and its subclasses (#144)

Co-authored-by: haszi <[email protected]>
  • Loading branch information
haszi and haszi authored Jul 26, 2024
1 parent 8ca0905 commit 86c5a1b
Show file tree
Hide file tree
Showing 33 changed files with 98 additions and 98 deletions.
28 changes: 14 additions & 14 deletions phpdotnet/phd/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class Format extends ObjectStorage
protected $classes = array();
protected $examples = array();

private static $autogen = array();
private $autogen = array();

private static $highlighters = array();

Expand All @@ -66,8 +66,8 @@ abstract class Format extends ObjectStorage

public function __construct(Config $config) {
$this->config = $config;
if (Config::indexcache()) {
$this->indexRepository = Config::indexcache();
if ($this->config->indexcache()) {
$this->indexRepository = $this->config->indexcache();
if (!($this instanceof Index)) {
$this->sortIDs();
}
Expand Down Expand Up @@ -328,28 +328,28 @@ final public function parse($xml) {
return $parsed;
}

final public static function autogen($text, $lang = null) {
final public function autogen($text, $lang = null) {
if ($lang == NULL) {
$lang = Config::language();
$lang = $this->config->language();
}
if (isset(self::$autogen[$lang])) {
if (isset(self::$autogen[$lang][$text])) {
return self::$autogen[$lang][$text];
if (isset($this->autogen[$lang])) {
if (isset($this->autogen[$lang][$text])) {
return $this->autogen[$lang][$text];
}
if ($lang == Config::fallback_language()) {
if ($lang == $this->config->fallback_language()) {
throw new \InvalidArgumentException("Cannot autogenerate text for '$text'");
}
return self::autogen($text, Config::fallback_language());
return $this->autogen($text, $this->config->fallback_language());
}

$filename = Config::lang_dir() . $lang . ".ini";
$filename = $this->config->lang_dir() . $lang . ".ini";

if (!file_exists($filename) && strncmp(basename($filename), 'doc-', 4) === 0) {
$filename = dirname($filename) . DIRECTORY_SEPARATOR . substr(basename($filename), 4);
}

self::$autogen[$lang] = parse_ini_file($filename);
return self::autogen($text, $lang);
$this->autogen[$lang] = parse_ini_file($filename);
return $this->autogen($text, $lang);
}

/* {{{ TOC helper functions */
Expand Down Expand Up @@ -516,7 +516,7 @@ public function rowspan($attrs) {
public function highlight($text, $role = 'php', $format = 'xhtml')
{
if (!isset(self::$highlighters[$format])) {
$class = Config::highlighter();
$class = $this->config->highlighter();
self::$highlighters[$format] = $class::factory($format);
}

Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Format/Abstract/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public function CDATA($str) {
* @return void
*/
public function postConstruct() {
$this->mediamanager = new MediaManager(Config::xml_root());
$this->mediamanager = new MediaManager($this->config->xml_root());
$outputdir = $this->getOutputDir();
if (isset($outputdir) && $outputdir) {
$this->mediamanager->output_dir = $outputdir;
} else {
$this->mediamanager->output_dir = Config::output_dir() . '/' . strtolower($this->getFormatName()) . '-data/';
$this->mediamanager->output_dir = $this->config->output_dir() . '/' . strtolower($this->getFormatName()) . '-data/';
$this->mediamanager->relative_ref_path = basename($this->mediamanager->output_dir) . '/';
}
}
Expand Down
8 changes: 4 additions & 4 deletions phpdotnet/phd/Package/Generic/BigXHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ public function update($event, $val = null) {
case Render::INIT:
if ($val) {
if (!is_resource($this->getFileStream())) {
$filename = Config::output_dir();
if (Config::output_filename()) {
$filename .= Config::output_filename();
$filename = $this->config->output_dir();
if ($this->config->output_filename()) {
$filename .= $this->config->output_filename();
} else {
$filename .= strtolower($this->getFormatName()) . $this->getExt();
}

$this->postConstruct();
if (Config::css()) {
if ($this->config->css()) {
$this->fetchStylesheet();
}
$this->setFileStream(fopen($filename, "w+"));
Expand Down
6 changes: 3 additions & 3 deletions phpdotnet/phd/Package/Generic/ChunkedXHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function update($event, $val = null) {
return; //Don't create output dir when rendering to buffer
}

$this->setOutputDir(Config::output_dir() . strtolower($this->getFormatName()) . '/');
$this->setOutputDir($this->config->output_dir() . strtolower($this->getFormatName()) . '/');
$this->postConstruct();
if (file_exists($this->getOutputDir())) {
if (!is_dir($this->getOutputDir())) {
Expand All @@ -81,7 +81,7 @@ public function update($event, $val = null) {
v("Can't create output directory", E_USER_ERROR);
}
}
if (Config::css()) {
if ($this->config->css()) {
$this->fetchStylesheet();
}
break;
Expand All @@ -93,7 +93,7 @@ public function update($event, $val = null) {

public function header($id) {
$title = $this->getLongDescription($id);
$lang = Config::language();
$lang = $this->config->language();
$root = Format::getRootIndex();
static $cssLinks = null;
if ($cssLinks === null) {
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/Generic/Manpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function __construct(Config $config) {
parent::__construct($config);

$this->registerFormatName("Generic Unix Manual Pages");
$this->setExt(Config::ext() === null ? ".3.gz" : Config::ext());
$this->setExt($this->config->ext() === null ? ".3.gz" : $this->config->ext());
$this->setChunked(true);
$this->cchunk = $this->dchunk;
}
Expand Down Expand Up @@ -309,7 +309,7 @@ public function update($event, $val = null) {
break;

case Render::INIT:
$this->setOutputDir(Config::output_dir() . strtolower($this->toValidName($this->getFormatName())) . '/');
$this->setOutputDir($this->config->output_dir() . strtolower($this->toValidName($this->getFormatName())) . '/');
if (file_exists($this->getOutputDir())) {
if (!is_dir($this->getOutputDir())) {
v("Output directory is a file?", E_USER_ERROR);
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/Generic/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ abstract class Package_Generic_PDF extends Format_Abstract_PDF {

public function __construct(Config $config) {
parent::__construct($config);
$this->setExt(Config::ext() === null ? ".pdf" : Config::ext());
$this->setExt($this->config->ext() === null ? ".pdf" : $this->config->ext());
$this->pdfDoc = new PdfWriter();
}

Expand Down Expand Up @@ -1131,7 +1131,7 @@ public function format_indice($open, $name, $attrs) {
public function format_imagedata($open, $name, $attrs, $props) {
if ($props["empty"] && isset($this->cchunk["xml-base"]) && ($base = $this->cchunk["xml-base"]) &&
isset($attrs[Reader::XMLNS_DOCBOOK]["fileref"]) && ($fileref = $attrs[Reader::XMLNS_DOCBOOK]["fileref"])) {
$imagePath = Config::xml_root() . DIRECTORY_SEPARATOR . $base . $fileref;
$imagePath = $this->config->xml_root() . DIRECTORY_SEPARATOR . $base . $fileref;
if (file_exists($imagePath))
$this->pdfDoc->add(PdfWriter::IMAGE, $imagePath);

Expand Down
6 changes: 3 additions & 3 deletions phpdotnet/phd/Package/Generic/TocFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function __construct(Config $config)
$this->registerFormatName($this->formatName);
$this->setTitle('Index');
$this->setChunked(true);
$this->setExt(Config::ext() === null ? ".atom" : Config::ext());
$this->setExt($this->config->ext() === null ? ".atom" : $this->config->ext());
$this->date = date('c');
if ($this->feedBaseUri === null) {
$this->feedBaseUri = $this->targetBaseUri;
Expand Down Expand Up @@ -216,7 +216,7 @@ public function update($event, $val = null)

case Render::INIT:
$this->setOutputDir(
Config::output_dir()
$this->config->output_dir()
. strtolower($this->getFormatName()) . '/'
);
$dir = $this->getOutputDir();
Expand Down Expand Up @@ -395,7 +395,7 @@ public function header($id)
{
$title = htmlspecialchars($this->getLongDescription($id));
$date = $this->date;
$lang = Config::language();
$lang = $this->config->language();
$selflink = $this->createLink($id);
$htmllink = $this->createTargetLink($id);
$author = htmlspecialchars($this->author);
Expand Down
8 changes: 4 additions & 4 deletions phpdotnet/phd/Package/Generic/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML {
public function __construct(Config $config) {
parent::__construct($config);
$this->registerPIHandlers($this->pihandlers);
$this->setExt(Config::ext() === null ? ".html" : Config::ext());
$this->setExt($this->config->ext() === null ? ".html" : $this->config->ext());
}

public function getDefaultElementMap() {
Expand Down Expand Up @@ -631,7 +631,7 @@ protected function createCSSLinks() {

protected function fetchStylesheet($name = null) {
if (!$this->isChunked()) {
foreach ((array)Config::css() as $css) {
foreach ((array)$this->config->css() as $css) {
if ($style = file_get_contents($css)) {
$this->stylesheets[] = $style;
} else {
Expand All @@ -642,7 +642,7 @@ protected function fetchStylesheet($name = null) {
}
$stylesDir = $this->getOutputDir();
if (!$stylesDir) {
$stylesDir = Config::output_dir();
$stylesDir = $this->config->output_dir();
}
$stylesDir .= 'styles/';
if (file_exists($stylesDir)) {
Expand All @@ -654,7 +654,7 @@ protected function fetchStylesheet($name = null) {
v("Can't create the styles/ directory.", E_USER_ERROR);
}
}
foreach ((array)Config::css() as $css) {
foreach ((array)$this->config->css() as $css) {
$basename = basename($css);
$dest = md5(substr($css, 0, -strlen($basename))) . '-' . $basename;
if (@copy($css, $stylesDir . $dest)) {
Expand Down
6 changes: 3 additions & 3 deletions phpdotnet/phd/Package/IDE/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ public function versionInfo($funcname) {
}

public function loadVersionInfo() {
if (file_exists(Config::phpweb_version_filename())) {
$this->versions = self::generateVersionInfo(Config::phpweb_version_filename());
if (file_exists($this->config->phpweb_version_filename())) {
$this->versions = self::generateVersionInfo($this->config->phpweb_version_filename());
} else {
trigger_error("Can't load the versions file", E_USER_ERROR);
}
}

public function createOutputDirectory() {
$this->setOutputDir(Config::output_dir() . strtolower($this->getFormatName()) . '/');
$this->setOutputDir($this->config->output_dir() . strtolower($this->getFormatName()) . '/');
if (file_exists($this->getOutputDir())) {
if (!is_dir($this->getOutputDir())) {
v('Output directory is a file?', E_USER_ERROR);
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/IDE/Funclist.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Package_IDE_Funclist extends Format {
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("IDE-Funclist");
$this->setExt(Config::ext() === null ? ".txt" : Config::ext());
$this->setExt($this->config->ext() === null ? ".txt" : $this->config->ext());
}

public function createLink($for, &$desc = null, $type = Format::SDESC) {}
Expand All @@ -39,7 +39,7 @@ public function update($event, $value = null) {
$this->registerTextMap($this->textmap);
break;
case Render::FINALIZE:
$filename = Config::output_dir() . strtolower($this->getFormatName()) . $this->getExt();
$filename = $this->config->output_dir() . strtolower($this->getFormatName()) . $this->getExt();
file_put_contents($filename, $this->buffer);
break;
case Render::VERBOSE:
Expand Down
2 changes: 1 addition & 1 deletion phpdotnet/phd/Package/IDE/JSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Package_IDE_JSON extends Package_IDE_Base {
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName('IDE-JSON');
$this->setExt(Config::ext() === null ? ".json" : Config::ext());
$this->setExt($this->config->ext() === null ? ".json" : $this->config->ext());
}

public function parseFunction() {
Expand Down
2 changes: 1 addition & 1 deletion phpdotnet/phd/Package/IDE/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Package_IDE_PHP extends Package_IDE_Base {
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName('IDE-PHP');
$this->setExt(Config::ext() === null ? ".php" : Config::ext());
$this->setExt($this->config->ext() === null ? ".php" : $this->config->ext());
}

public function parseFunction() {
Expand Down
2 changes: 1 addition & 1 deletion phpdotnet/phd/Package/IDE/PHPStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Package_IDE_PHPStub extends Package_IDE_Base {
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName('IDE-PHPStub');
$this->setExt(Config::ext() === null ? ".php" : Config::ext());
$this->setExt($this->config->ext() === null ? ".php" : $this->config->ext());
}

public function parseFunction() {
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/IDE/SQLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Package_IDE_SQLite extends Package_IDE_Base {
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName('IDE-SQLite');
$this->setExt(Config::ext() === null ? ".sqlite" : Config::ext());
$this->setExt($this->config->ext() === null ? ".sqlite" : $this->config->ext());
}

public function INIT($value) {
Expand Down Expand Up @@ -90,7 +90,7 @@ public function parseFunction() {
}

public function createDatabase() {
$db = new \SQLite3(Config::output_dir() . strtolower($this->getFormatName()) . $this->getExt());
$db = new \SQLite3($this->config->output_dir() . strtolower($this->getFormatName()) . $this->getExt());
$db->exec('DROP TABLE IF EXISTS functions');
$db->exec('DROP TABLE IF EXISTS params');
$db->exec('DROP TABLE IF EXISTS notes');
Expand Down
2 changes: 1 addition & 1 deletion phpdotnet/phd/Package/IDE/XML.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Package_IDE_XML extends Package_IDE_Base {
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName('IDE-XML');
$this->setExt(Config::ext() === null ? ".xml" : Config::ext());
$this->setExt($this->config->ext() === null ? ".xml" : $this->config->ext());
}

public function parseFunction() {
Expand Down
10 changes: 5 additions & 5 deletions phpdotnet/phd/Package/PEAR/BigXHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("PEAR-BigXHTML");
$this->setTitle("PEAR Manual");
$this->setExt(Config::ext() === null ? ".html" : Config::ext());
$this->setExt($this->config->ext() === null ? ".html" : $this->config->ext());
$this->setChunked(false);
}

Expand Down Expand Up @@ -42,9 +42,9 @@ public function close() {
}

public function createFileName() {
$filename = Config::output_dir();
if (Config::output_filename()) {
$filename .= Config::output_filename();
$filename = $this->config->output_dir();
if ($this->config->output_filename()) {
$filename .= $this->config->output_filename();
} else {
$filename .= strtolower($this->getFormatName()) . $this->getExt();
}
Expand Down Expand Up @@ -94,7 +94,7 @@ public function update($event, $val = null) {
case Render::INIT:
if ($val) {
$this->postConstruct();
if (Config::css()) {
if ($this->config->css()) {
$this->fetchStylesheet();
}
$this->createOutputFile();
Expand Down
8 changes: 4 additions & 4 deletions phpdotnet/phd/Package/PEAR/CHM.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,16 @@ public function update($event, $val = null) {
parent::update($event, $val);
break;
case Render::INIT:
$this->chmdir = Config::output_dir() . strtolower($this->getFormatName()) . DIRECTORY_SEPARATOR;
$this->chmdir = $this->config->output_dir() . strtolower($this->getFormatName()) . DIRECTORY_SEPARATOR;
if(!file_exists($this->chmdir) || is_file($this->chmdir)) {
mkdir($this->chmdir, 0777, true) or die("Can't create the CHM project directory");
}
$this->outputdir = Config::output_dir() . strtolower($this->getFormatName()) . DIRECTORY_SEPARATOR . "res" . DIRECTORY_SEPARATOR;
$this->outputdir = $this->config->output_dir() . strtolower($this->getFormatName()) . DIRECTORY_SEPARATOR . "res" . DIRECTORY_SEPARATOR;
$this->postConstruct();
if(!file_exists($this->outputdir) || is_file($this->outputdir)) {
mkdir($this->outputdir, 0777, true) or die("Can't create the cache directory");
}
$lang = Config::language();
$lang = $this->config->language();
$this->hhpStream = fopen($this->chmdir . "pear_manual_{$lang}.hhp", "w");
$this->hhcStream = fopen($this->chmdir . "pear_manual_{$lang}.hhc", "w");
$this->hhkStream = fopen($this->chmdir . "pear_manual_{$lang}.hhk", "w");
Expand Down Expand Up @@ -283,7 +283,7 @@ protected static function cleanIndexName($value)
}

protected function headerChm() {
$lang = Config::language();
$lang = $this->config->language();
fwrite($this->hhpStream, '[OPTIONS]
Binary TOC=Yes
Compatibility=1.1 or later
Expand Down
Loading

0 comments on commit 86c5a1b

Please sign in to comment.