View Issue Details

IDProjectCategoryView StatusLast Update
0000186Adventure PHP FrameworkCode-Verbesserung // Code improvementpublic2015-10-12 12:19
Reporteruser15Assigned ToChristianAchatz 
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version2.0 
Target Version3.0Fixed in Version3.0 
Summary0000186: Save taglibs as associative array to allow the developer to overwrite core tags
DescriptionThe "Document" class currently holds all known taglibs inside an array with numeric keys, if one wants to override a core taglib (like core:importdesign) one has to do the following:

if ($key = array_search($taglibToDelete, $this->tagLibs)) {
    unset($this->tagLibs[$key]);
}


The statement above will remove an entry from the array and extractTagLibTags() will fail because there is an array key missing, therefore we need to correct the array key sequence via

$this->tagLibs = array_merge($this->tagLibs, []);


After this we successfully overwrote a core taglib.

It would be much easier, if the taglibs would be saved inside an associative array where the array keys hold the token (prefix:tagname) and the values represent the taglib object.

Overwriting a core taglib could then be done by simply writing

$this->tagLibs['core:importdesign'] = new TagLib( ... );


or better

$this->addTagLib('core', 'importdesign', 'my\own\import\tag');


Additionally we then could replace the while loop in extractTagLibTags() by a foreach statement like

foreach ($this->tagLibs as $token => $tagLib) {
    // ...
TagsNo tags attached.
Codereferenz: ([Datei]:[Zeile])vendor/APF/core/pagecontroller/pagecontroller.php:899
Namespacecore

Relationships

related to 0000185 closedChristianAchatz POC: switch registration of known tags from Document instance to static Document property 

Activities

ChristianAchatz

2014-05-04 10:53

administrator   ~0000321

Can be realized easily with the new APF 2.2 parser that queries known tags by this scheme rather than iterates over the array while parsing.

ChristianAchatz

2014-06-21 18:33

administrator   ~0000396

Implementation done with one of the last check-ins on the master-Branch. You can now:

1) Register tags globally within PHP code using e.g.

Document::addTagLib(new TagLib('APF\core\pagecontroller\AddTaglibTag', 'core', 'addtaglib'));

2) Register tags locally per instance (registration/overriding valid only for this specific instance) using e.g.

public function __construct() {
   $this->addInstanceTagLib(new TagLib('APF\core\pagecontroller\AddTaglibTag', 'core', 'addtaglib'));
}

3) Override core tags that are registered in APF's bootstrap.php using e.g.

Document::addTagLib(new TagLib('my\own\import\tag', 'core', 'importdesign'));

within your bootstrap file (e.g. index.php) of your project.

Besides, the internal storage structure has changed to register tags using their given prefix and name (as suggested) but is hidden for users by the following methods:

- Document::addTagLib() (static)
- Document::addTagLibs() (static)
- Document::addInstanceTagLib() (per instance)
- Document::addInstanceTagLibs() (per instance)

@astangl: can you please review changes whether or not they solve your project requirement? Thx! :)

ChristianAchatz

2014-06-21 18:35

administrator   ~0000397

Some details and advantages have been documented under http://wiki.adventure-php-framework.org/Migration_von_2.1_auf_2.2.

Consolidation of tag registration (e.g. <core:addtaglib /> and <template:addtaglib />) yet to come.

Issue History

Date Modified Username Field Change
2014-04-29 15:19 user15 New Issue
2014-05-04 10:53 ChristianAchatz Note Added: 0000321
2014-05-04 10:53 ChristianAchatz Assigned To => ChristianAchatz
2014-05-04 10:53 ChristianAchatz Status new => acknowledged
2014-05-04 10:53 ChristianAchatz Sticky Issue No => Yes
2014-05-04 10:53 ChristianAchatz Sticky Issue Yes => No
2014-05-04 10:54 ChristianAchatz Target Version => 3.0
2014-05-04 10:54 ChristianAchatz Status acknowledged => assigned
2014-05-04 10:55 ChristianAchatz Relationship added related to 0000185
2014-06-21 18:33 ChristianAchatz Note Added: 0000396
2014-06-21 18:35 ChristianAchatz Note Added: 0000397
2014-06-21 18:35 ChristianAchatz Status assigned => resolved
2014-06-21 18:35 ChristianAchatz Fixed in Version => 3.0
2014-06-21 18:35 ChristianAchatz Resolution open => fixed
2015-10-12 12:19 ChristianAchatz Status resolved => closed