Skip to content

Commit

Permalink
Add config as a dependency of format (#142)
Browse files Browse the repository at this point in the history
* Add Config as a dependency to Format and all it subclasses

* Inject Config into every Format subclass at instantiation

---------

Co-authored-by: haszi <haszika80@gmail.com>
  • Loading branch information
haszi and haszi authored Jul 7, 2024
1 parent 319ec94 commit e948f10
Show file tree
Hide file tree
Showing 71 changed files with 132 additions and 103 deletions.
5 changes: 4 additions & 1 deletion phpdotnet/phd/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ abstract class Format extends ObjectStorage
*/
const LDESC = 2;

protected Config $config;

private $elementmap = array();
private $textmap = array();
private $formatname = "UNKNOWN";
Expand Down Expand Up @@ -62,7 +64,8 @@ abstract class Format extends ObjectStorage
*/
protected $CURRENT_ID = "";

public function __construct() {
public function __construct(Config $config) {
$this->config = $config;
if (Config::indexcache()) {
$this->indexRepository = Config::indexcache();
if (!($this instanceof Index)) {
Expand Down
4 changes: 4 additions & 0 deletions phpdotnet/phd/Format/Abstract/Manpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
abstract class Format_Abstract_Manpage extends Format {
public $role = false;

public function __construct(Config $config) {
parent::__construct($config);
}

public function UNDEF($open, $name, $attrs, $props) {
if ($open) {
trigger_error("No mapper found for '{$name}'", E_USER_WARNING);
Expand Down
3 changes: 2 additions & 1 deletion phpdotnet/phd/Format/Abstract/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ class PdfWriter {
// To temporarily store $current(s)
private $old = array();

function __construct($pageWidth = 210, $pageHeight = 297) {
function __construct($pageWidth = 210, $pageHeight = 297, Config $config) {
parent::__construct($config);
// Initialization of properties
$this->haruDoc = new \HaruDoc;
$this->haruDoc->addPageLabel(1, \HaruPage::NUM_STYLE_DECIMAL, 1, "Page ");
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 @@ -14,8 +14,8 @@ abstract class Format_Abstract_XHTML extends Format {
protected $mediamanager = null;
protected $lang = 'en';

public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
}

public function transformFromMap($open, $tag, $name, $attrs, $props) {
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Format/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public final function getPackageName() {
return $this->packageName;
}

public final function createFormat($format) {
public final function createFormat($format, ...$formatParams) {
if (isset($this->formats[$format]) && $this->formats[$format]) {
$classname = __NAMESPACE__ . "\\" . $this->formats[$format];

$obj = new $classname();
$obj = new $classname(...$formatParams);
if (!($obj instanceof Format)) {
throw new \Exception("All Formats must inherit Format");
}
Expand Down
7 changes: 5 additions & 2 deletions phpdotnet/phd/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ class Index extends Format
private $POST_REPLACEMENT_VALUES = array();
private int $exampleCounter = 0;

public function __construct(IndexRepository $indexRepository) {
public function __construct(
IndexRepository $indexRepository,
Config $config
) {
$this->indexRepository = $indexRepository;
parent::__construct();
parent::__construct($config);
}

public function transformFromMap($open, $tag, $name, $attrs, $props) {
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/Generic/BigXHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
namespace phpdotnet\phd;

class Package_Generic_BigXHTML extends Package_Generic_XHTML {
public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("Big-XHTML");
$this->setTitle("Index");
$this->setChunked(false);
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/Generic/ChunkedXHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
namespace phpdotnet\phd;

class Package_Generic_ChunkedXHTML extends Package_Generic_XHTML {
public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("Chunked-XHTML");
$this->setTitle("Index");
$this->setChunked(true);
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 @@ -256,8 +256,8 @@ class Package_Generic_Manpage extends Format_Abstract_Manpage {
"firstrefname" => true,
);

public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);

$this->registerFormatName("Generic Unix Manual Pages");
$this->setExt(Config::ext() === null ? ".3.gz" : Config::ext());
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 @@ -296,8 +296,8 @@ abstract class Package_Generic_PDF extends Format_Abstract_PDF {
"callouts" => 0,
);

public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->setExt(Config::ext() === null ? ".pdf" : Config::ext());
$this->pdfDoc = new PdfWriter();
}
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/Generic/TocFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ abstract class Package_Generic_TocFeed extends Format
/**
* Creates a new instance.
*/
public function __construct()
public function __construct(Config $config)
{
parent::__construct();
parent::__construct($config);
$this->registerFormatName($this->formatName);
$this->setTitle('Index');
$this->setChunked(true);
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/Generic/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML {

protected int $exampleCounter = 0;

public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->registerPIHandlers($this->pihandlers);
$this->setExt(Config::ext() === null ? ".html" : Config::ext());
}
Expand Down
4 changes: 4 additions & 0 deletions phpdotnet/phd/Package/IDE/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ abstract class Package_IDE_Base extends Format {
'seealso' => array(),
);

public function __construct(Config $config){
parent::__construct($config);
}

public function createLink($for, &$desc = null, $type = Format::SDESC) {}
public function UNDEF($open, $name, $attrs, $props) {}
public function TEXT($value) {}
Expand Down
3 changes: 2 additions & 1 deletion phpdotnet/phd/Package/IDE/Funclist.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Package_IDE_Funclist extends Format {
protected $isRefname = false;
protected $buffer = "";

public function __construct() {
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("IDE-Funclist");
$this->setExt(Config::ext() === null ? ".txt" : Config::ext());
}
Expand Down
3 changes: 2 additions & 1 deletion phpdotnet/phd/Package/IDE/JSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

class Package_IDE_JSON extends Package_IDE_Base {

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

class Package_IDE_PHP extends Package_IDE_Base {

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

public function __construct() {
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName('IDE-PHPStub');
$this->setExt(Config::ext() === null ? ".php" : Config::ext());
}
Expand Down
3 changes: 2 additions & 1 deletion phpdotnet/phd/Package/IDE/SQLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class Package_IDE_SQLite extends Package_IDE_Base {
private $sql = array();
private $db = null;

public function __construct() {
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName('IDE-SQLite');
$this->setExt(Config::ext() === null ? ".sqlite" : Config::ext());
}
Expand Down
3 changes: 2 additions & 1 deletion phpdotnet/phd/Package/IDE/XML.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

class Package_IDE_XML extends Package_IDE_Base {

public function __construct() {
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName('IDE-XML');
$this->setExt(Config::ext() === null ? ".xml" : Config::ext());
}
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PEAR/BigXHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
namespace phpdotnet\phd;

class Package_PEAR_BigXHTML extends Package_PEAR_XHTML {
public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("PEAR-BigXHTML");
$this->setTitle("PEAR Manual");
$this->setExt(Config::ext() === null ? ".html" : Config::ext());
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PEAR/CHM.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ class Package_PEAR_CHM extends Package_PEAR_ChunkedXHTML {
// Project files Output directory
protected $chmdir;

public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("PEAR-CHM");
}

Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PEAR/ChunkedXHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
namespace phpdotnet\phd;

class Package_PEAR_ChunkedXHTML extends Package_PEAR_XHTML {
public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("PEAR-Chunked-XHTML");
$this->setTitle("PEAR Manual");
$this->setExt(Config::ext() === null ? ".html" : Config::ext());
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PEAR/TocFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ class Package_PEAR_TocFeed extends Package_Generic_TocFeed
/**
* Create new instance.
*/
public function __construct()
public function __construct(Config $config)
{
parent::__construct();
parent::__construct($config);

$language = Config::language();
$variables = array('targetBaseUri', 'feedBaseUri', 'idprefix');
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PEAR/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*/
class Package_PEAR_Web extends Package_PEAR_ChunkedXHTML
{
public function __construct()
public function __construct(Config $config)
{
parent::__construct();
parent::__construct($config);
$this->registerFormatName('PEAR-Web');
$this->setExt(Config::ext() === null ? '.php' : Config::ext());
}
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PEAR/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ abstract class Package_PEAR_XHTML extends Package_Generic_XHTML {
/**
* Constructor
*/
public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->myelementmap = array_merge(parent::getDefaultElementMap(), static::getDefaultElementMap());
$this->mytextmap = array_merge(parent::getDefaultTextMap(), static::getDefaultTextMap());
$this->dchunk = array_merge(parent::getDefaultChunkInfo(), static::getDefaultChunkInfo());
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PHP/BigPDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
namespace phpdotnet\phd;

class Package_PHP_BigPDF extends Package_PHP_PDF {
public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("PHP-BigPDF");
}

Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PHP/BigXHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
namespace phpdotnet\phd;

class Package_PHP_BigXHTML extends Package_PHP_XHTML {
public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("PHP-BigXHTML");
$this->setTitle("PHP Manual");
$this->setChunked(false);
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PHP/CHM.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ class Package_PHP_CHM extends Package_PHP_ChunkedXHTML
// Project files Output directory
protected $chmdir;

public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("PHP-CHM");
}

Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PHP/ChunkedXHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
class Package_PHP_ChunkedXHTML extends Package_PHP_Web {
private $nav = "";

public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("PHP-Chunked-XHTML");
$this->setExt(Config::ext() === null ? ".html" : Config::ext());
}
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PHP/EnhancedCHM.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Package_PHP_EnhancedCHM extends Package_PHP_CHM
// Where are the usernotes?
protected $userNotesBaseDir = null;

public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("PHP-EnhancedCHM");
}

Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PHP/Epub.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Package_PHP_Epub extends Package_PHP_ChunkedXHTML
'epub_file' => '',
);

public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->setExt('.xhtml');
$this->registerFormatName("PHP-Epub");
}
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PHP/HowTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
class Package_PHP_HowTo extends Package_PHP_Web {
private $nav = "";

public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("PHP-HowTo");
}

Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PHP/KDevelop.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class Package_PHP_KDevelop extends Format {
// CHM Index Map
protected $hhkStream;

public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("PHP-KDevelop");
$this->setTitle("PHP Manual");
$this->setExt(Config::ext() === null ? ".php" : Config::ext());
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PHP/Manpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class Package_PHP_Manpage extends Package_Generic_Manpage {
/* Default Chunk settings */
protected $dchunk = array();

public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);

$this->registerFormatName("PHP-Functions");
$this->setTitle("PHP Manual");
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PHP/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class Package_PHP_PDF extends Package_Generic_PDF {
"root-outline" => null,
);

public function __construct() {
parent::__construct();
public function __construct(Config $config) {
parent::__construct($config);
$this->registerFormatName("PHP-PDF");
$this->setTitle("PHP Manual");
}
Expand Down
Loading

0 comments on commit e948f10

Please sign in to comment.