From 80107cda73f88322c80a7bef214c726f4d4f0105 Mon Sep 17 00:00:00 2001 From: Christian Achatz Date: Fri, 27 Jun 2014 08:06:10 +0200 Subject: [PATCH] Added further migration steps. --- migration/migrate-code.sh | 3 + migration/migrate_consolidate_tag_usage.php | 61 +++++++++++++++ .../migration_extract_add_tag_statements.php | 77 +++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 migration/migrate_consolidate_tag_usage.php create mode 100644 migration/migration_extract_add_tag_statements.php diff --git a/migration/migrate-code.sh b/migration/migrate-code.sh index a9835a9ee..a2cf98472 100644 --- a/migration/migrate-code.sh +++ b/migration/migrate-code.sh @@ -22,6 +22,9 @@ echo "Starting migration ..." echo "* Migrate taglib declaration statements ..." $PHP_BINARY $SCRIPT_DIR/migrate_taglib_registration.php +echo "* Consolidate tag usage ..." +$PHP_BINARY $SCRIPT_DIR/migrate_consolidate_tag_usage.php + echo echo "#############################################" echo diff --git a/migration/migrate_consolidate_tag_usage.php b/migration/migrate_consolidate_tag_usage.php new file mode 100644 index 000000000..6094d349d --- /dev/null +++ b/migration/migrate_consolidate_tag_usage.php @@ -0,0 +1,61 @@ + ... + foreach ($redundantAddTagLibTagPrefixes as $prefix) { + $content = str_replace('<' . $prefix . ':addtaglib', ' ... + foreach ($redundantGetStringPrefixes as $prefix) { + $content = str_replace('<' . $prefix . ':getstring', ' ... + foreach ($redundantPlaceHolderPrefixes as $prefix) { + $content = str_replace('<' . $prefix . ':placeholder', ' tags, remove them from the templates, and suggest index.php statements to add + +// examples: +/* + + +*/ + +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'); + +// ([ |\n|\r\n]*) +$search = '#<([A-Za-z\-_]+):addtaglib([ |\n|\r\n]*)(.+)/>#mU'; + +//=([ |\n|\r\n]*)new TagLib\(\'([A-Za-z0-9\\\-_]+)\',([ |\n|\r\n]*)\'([A-Za-z0-9\-_]+)\',([ |\n|\r\n]*)\'([A-Za-z0-9\-_]+)\'([ |\n|\r\n]*)\)#m'; + +$tags = array(); + +$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'])) { + echo '- Removing registration of tag <' . $attributes['prefix'] . ':' . $attributes['name'] . ' /> from ' . $file . '.' . PHP_EOL; + } else { + // register with prefix and name to unique selection + $tags[$attributes['prefix'] . ':' . $attributes['name']] = $attributes; + } + + } + +} + +echo PHP_EOL . PHP_EOL . '************************************************************' . PHP_EOL; +echo 'Recommended to add the following tags within your bootstrap filed (e.g. index.php):' . PHP_EOL; + +foreach ($tags as $tag) { + echo 'Document::addTagLib(new TagLib(\'' . $tag['class'] . '\', \'' . $tag['prefix'] . '\', \'' . $tag['name'] . '\'));' . PHP_EOL; +} + +// remove tags that have been statically registered (fetch tags from Document) and suggest other tags can be registered...