Skip to content

Commit

Permalink
* Fixed/enhanced migration script for tag registration statements.
Browse files Browse the repository at this point in the history
* Added script tp update to expression tag place holder syntax.
  • Loading branch information
Christian Achatz committed Jun 27, 2014
1 parent fd8c59c commit 70f9b98
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 77 deletions.
6 changes: 6 additions & 0 deletions migration/migrate-code.sh
Expand Up @@ -25,6 +25,12 @@ $PHP_BINARY $SCRIPT_DIR/migrate_taglib_registration.php
echo "* Consolidate tag usage ..."
$PHP_BINARY $SCRIPT_DIR/migrate_consolidate_tag_usage.php

echo "* Remove redundant tag lib registration ..."
$PHP_BINARY $SCRIPT_DIR/migrate_extract_add_tag_statements.php

echo "* Switch to new place holder logic ..."
$PHP_BINARY $SCRIPT_DIR/migrate_update_place_holders_to_expression_notation.php

echo
echo "#############################################"
echo
Expand Down
52 changes: 52 additions & 0 deletions migration/migrate_extract_add_tag_statements.php
@@ -0,0 +1,52 @@
<?php
// Collect all <*:addtaglib /> tags, remove them from the templates, and suggest index.php
// statements to add for custom tags.

use APF\core\pagecontroller\TagLib;
use APF\core\pagecontroller\XmlParser;

include(dirname(__FILE__) . '/migrate_base.php');
include(dirname(dirname(__FILE__)) . '/core/pagecontroller/XmlParser.php');
include(dirname(dirname(__FILE__)) . '/core/pagecontroller/TagLib.php');
include(dirname(dirname(__FILE__)) . '/core/bootstrap.php');

\APF\core\exceptionhandler\GlobalExceptionHandler::disable();
\APF\core\errorhandler\GlobalErrorHandler::disable();

$files = find('.', '*.html');

$search = '#<([A-Za-z\-_]+):addtaglib([ |\n|\r\n|\r]+)(.*)/>#smU';

$class = new ReflectionClass('APF\core\pagecontroller\Document');
$property = $class->getProperty('knownTags');
$property->setAccessible(true);

$registeredTags = $property->getValue();

function isRegistered(array $registeredTags, $class, $prefix, $name) {
/* @var $tag TagLib */
foreach ($registeredTags as $tag) {
if ($tag->getClass() === $class && $tag->getPrefix() === $prefix && $tag->getName() === $name) {
return true;
}
}

return false;
}

foreach ($files as $file) {
$content = file_get_contents($file);

preg_match_all($search, $content, $matches, PREG_SET_ORDER);

foreach ($matches as $match) {
$attributes = XmlParser::getAttributesFromString(trim($match[3]));

if (isRegistered($registeredTags, $attributes['class'], $attributes['prefix'], $attributes['name'])) {
$content = str_replace($match[0], '', $content);
}

}

file_put_contents($file, $content);
}
15 changes: 15 additions & 0 deletions migration/migrate_update_place_holders_to_expression_notation.php
@@ -0,0 +1,15 @@
<?php
include(dirname(__FILE__) . '/migrate_base.php');

$files = find('.', '*.html');

// <html:placeholder name="..."/>
$search = '#<html:placeholder([ |\n|\r\n|\r]+)name ?= ?"(.+)"([ |\n|\r\n|\r]*)/>#mU';

foreach ($files as $file) {
$content = file_get_contents($file);

$content = preg_replace($search, '${\\2}', $content);

file_put_contents($file, $content);
}
77 changes: 0 additions & 77 deletions migration/migration_extract_add_tag_statements.php

This file was deleted.

0 comments on commit 70f9b98

Please sign in to comment.