diff options
Diffstat (limited to 'phpBB/develop')
-rw-r--r-- | phpBB/develop/compile_template.php | 24 | ||||
-rw-r--r-- | phpBB/develop/create_schema_files.php | 2 | ||||
-rw-r--r-- | phpBB/develop/mysql_upgrader.php | 2 | ||||
-rw-r--r-- | phpBB/develop/namespacify.php | 189 | ||||
-rw-r--r-- | phpBB/develop/rename_interfaces.php | 51 |
5 files changed, 242 insertions, 26 deletions
diff --git a/phpBB/develop/compile_template.php b/phpBB/develop/compile_template.php deleted file mode 100644 index 32d1d321f1..0000000000 --- a/phpBB/develop/compile_template.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php -// ------------------------------------------------------------- -// -// $Id$ -// -// FILENAME : compile_template.php -// STARTED : Sun Apr 24, 2011 -// COPYRIGHT : © 2011 phpBB Group -// WWW : http://www.phpbb.com/ -// LICENCE : GPL vs2.0 [ see /docs/COPYING ] -// -// ------------------------------------------------------------- - -define('IN_PHPBB', 1); -define('ANONYMOUS', 1); -$phpEx = substr(strrchr(__FILE__, '.'), 1); -$phpbb_root_path = './../'; - -include($phpbb_root_path . 'includes/template_compile.'.$phpEx); - -$file = $argv[1]; - -$compile = new phpbb_template_compile(false); -echo $compile->compile_file($file); diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 9ffc8d229f..5ef278d493 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -23,7 +23,7 @@ define('IN_PHPBB', true); require(dirname(__FILE__) . '/../includes/db/schema_data.php'); require(dirname(__FILE__) . '/../phpbb/db/tools.php'); -$dbms_type_map = phpbb_db_tools::get_dbms_type_map(); +$dbms_type_map = phpbb\db\tools::get_dbms_type_map(); // A list of types being unsigned for better reference in some db's $unsigned_types = array('UINT', 'UINT:', 'USINT', 'BOOL', 'TIMESTAMP'); diff --git a/phpBB/develop/mysql_upgrader.php b/phpBB/develop/mysql_upgrader.php index 3decee306a..eb34034826 100644 --- a/phpBB/develop/mysql_upgrader.php +++ b/phpBB/develop/mysql_upgrader.php @@ -59,7 +59,7 @@ echo "USE $dbname;$newline$newline"; require($phpbb_root_path . 'includes/db/schema_data.' . $phpEx); require($phpbb_root_path . 'phpbb/db/tools.' . $phpEx); -$dbms_type_map = phpbb_db_tools::get_dbms_type_map(); +$dbms_type_map = phpbb\db\tools::get_dbms_type_map(); foreach ($schema_data as $table_name => $table_data) { diff --git a/phpBB/develop/namespacify.php b/phpBB/develop/namespacify.php new file mode 100644 index 0000000000..4e460eead8 --- /dev/null +++ b/phpBB/develop/namespacify.php @@ -0,0 +1,189 @@ +<?php +/** +* +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +// +// Security message: +// +// This script is potentially dangerous. +// Remove or comment the next line (die(".... ) to enable this script. +// Do NOT FORGET to either remove this script or disable it after you have used it. +// +die("Please read the first lines of this script for instructions on how to enable it"); + +$namespace_dir = realpath(__DIR__ . '/../phpbb/'); +$code_dir = realpath(__DIR__ . '/../'); +$test_dir = realpath(__DIR__ . '/../../tests/'); +$config_dir = realpath(__DIR__ . '/../config/'); + +function map_class_name($old_class_name, $code_dir) +{ + $parts = explode('_', $old_class_name); + $cur_dir = array(); + $cur_name = array(); + $in_name = false; + foreach ($parts as $i => $part) + { + if (empty($part)) + { + return null; + } + + if (!$in_name) + { + $new_dir = array_merge($cur_dir, array($part)); + $path = $code_dir . '/' . implode('/', $new_dir); + + if (file_exists($path) && is_dir($path)) + { + $cur_dir = $new_dir; + } + else + { + $in_name = true; + $cur_name[] = $part; + } + } + else + { + $cur_name[] = $part; + } + } + + if (empty($cur_name) && !empty($cur_dir)) + { + $cur_name[] = $cur_dir[count($cur_dir) - 1]; + } + + if (file_exists($code_dir . '/' . implode('/', $cur_dir) . '/' . implode('_', $cur_name) . '.php')) + { + return implode('\\', $cur_dir) . '\\' . implode('_', $cur_name); + } + + return null; +} + +$iterator = new \AppendIterator(); +$iterator->append(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($code_dir))); +$iterator->append(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($test_dir))); +$iterator->append(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($config_dir))); + +foreach ($iterator as $file) +{ + if (substr($file->getPath(), 0, 6) === 'vendor') + { + continue; + } + + if ($file->getExtension() == 'php') + { + $code = file_get_contents($file->getPathname()); + $namespaced_file = false; + + if (preg_match('#^' . preg_quote($namespace_dir, '#') . '#', $file->getPath())) + { + if (preg_match('#^(?:interface|(?:abstract )?class) (phpbb_[a-z0-9_]+)#m', $code, $matches)) + { + $old_class_name = $matches[1]; + $dirs = explode(DIRECTORY_SEPARATOR, preg_replace('#^' . preg_quote(dirname($namespace_dir) . DIRECTORY_SEPARATOR, '#') . '#', '', $file->getPath())); + + $namespace = implode('\\', $dirs); + + if ($dirs[count($dirs) - 1] == substr($file->getFilename(), 0, -4)) + { + $class_name = preg_replace('#^' . preg_quote(implode('_', $dirs), '#') . '#', $dirs[count($dirs) - 1], $old_class_name); + } + else + { + $class_name = preg_replace('#^' . preg_quote(implode('_', $dirs), '#') . '_#', '', $old_class_name); + } + + $code = preg_replace("#^\*/$#m", "*/\n\nnamespace $namespace;", $code, 1, $count); + if ($count != 1) + { + die("Incorrect replacement count for namespace of $old_class_name"); + } + $code = preg_replace("#^(interface|(?:abstract )?class) $old_class_name#m", "\\1 $class_name", $code, -1, $count); + if ($count != 1) + { + die("Incorrect replacement count for $old_class_name"); + } + + $namespaced_file = true; + } + } + + if (preg_match_all('#[^a-z0-9_$](phpbb_[a-z0-9_]+)#', $code, $matches)) + { + foreach ($matches[1] as $old_class_name) + { + $class_name = map_class_name($old_class_name, $code_dir); + if ($class_name) + { + $code = preg_replace("#([^a-z0-9_\$>])$old_class_name([^a-z0-9_])#", '\\1\\\\' . $class_name . '\\2', $code); + } + } + } + + if ($namespaced_file) + { + $code = preg_replace('#new ([a-zA-Z0-9_][a-zA-Z0-9_\\\\]+)#', 'new \\\\\\1', $code); + $code = preg_replace('#([^a-zA-Z0-9_\\\\$])([a-zA-Z0-9_][a-zA-Z0-9_\\\\]+)::#', '\\1\\\\\\2::', $code); + $code = preg_replace('#catch \(([a-zA-Z0-9_][a-zA-Z0-9_\\\\]+)#', 'catch (\\\\\\1', $code); + $code = preg_replace('#(\(|, )([a-zA-Z0-9_][a-zA-Z0-9_\\\\]+)(\s\$)#', '\\1\\\\\\2\\3', $code); + $code = preg_replace('#(implements |extends )([a-zA-Z0-9_][a-zA-Z0-9_\\\\]+)(?=\s*(?:,|\n))#', '\\1\\\\\\2', $code); + $abs_classes = array( + 'Countable', + 'IteratorAggregate', + 'ArrayAccess', + ); + $code = preg_replace('#(\s+)(' . implode('|', $abs_classes) . ')#', '\\1\\\\\\2', $code); + $rel_classes = array( + 'ContainerBuilder', + 'YamlFileLoader', + 'FileLocator', + 'Extension', + 'CompilerPassInterface', + 'EventSubscriberInterface', + 'EventDispatcherInterface', + 'ContainerAwareEventDispatcher', + 'ContainerInterface', + 'KernelEvents', + 'RouteCollection', + 'ControllerResolverInterface', + 'Request', + 'include', + 'array', + 'parent', + 'self', + ); + $code = preg_replace('#([^a-zA-Z0-9_])\\\\((?:' . implode('|', $rel_classes) . ')(?:\s|\(|::|;))#', '\\1\\2', $code); + } + + file_put_contents($file->getPathname(), $code); + } + + if ($file->getExtension() == 'yml') + { + $code = file_get_contents($file->getPathname()); + + if (preg_match_all('#\s*class:\s*(phpbb_[a-z0-9_]+)\s+#', $code, $matches)) + { + foreach ($matches[1] as $old_class_name) + { + $class_name = map_class_name($old_class_name, $code_dir); + if ($class_name) + { + $code = preg_replace("#(\s*class:\s*)$old_class_name(\s+)#", "\\1$class_name\\2", $code); + } + } + } + + file_put_contents($file->getPathname(), $code); + } +} + diff --git a/phpBB/develop/rename_interfaces.php b/phpBB/develop/rename_interfaces.php new file mode 100644 index 0000000000..11989350bb --- /dev/null +++ b/phpBB/develop/rename_interfaces.php @@ -0,0 +1,51 @@ +<?php +/** +* +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +// +// Security message: +// +// This script is potentially dangerous. +// Remove or comment the next line (die(".... ) to enable this script. +// Do NOT FORGET to either remove this script or disable it after you have used it. +// +die("Please read the first lines of this script for instructions on how to enable it"); + +$code_dir = realpath(__DIR__ . '/../'); +$test_dir = realpath(__DIR__ . '/../../tests/'); +$iterator = new \AppendIterator(); +$iterator->append(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($code_dir))); +$iterator->append(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($test_dir))); + +$map = array( + 'phpbb\request\request_interface' => 'phpbb\request\request_interface', + 'phpbb\auth\provider\provider_interface' => 'phpbb\auth\provider\provider_interface', + 'phpbb\avatar\driver\driver_interface' => 'phpbb\avatar\driver\driver_interface', + 'phpbb\cache\driver\driver_interface' => 'phpbb\cache\driver\driver_interface', + 'phpbb\db\migration\tool\tool_interface' => 'phpbb\db\migration\tool\tool_interface', + 'phpbb\extension\extension_interface' => 'phpbb\extension\extension_interface', + 'phpbb\groupposition\groupposition_interface' => 'phpbb\groupposition\groupposition_interface', + 'phpbb\log\log_interface' => 'phpbb\log\log_interface', + 'phpbb\notification\method\method_interface' => 'phpbb\notification\method\method_interface', + 'phpbb\notification\type\type_interface' => 'phpbb\notification\type\type_interface', + 'phpbb\request\request_interface' => 'phpbb\request\request_interface', + 'phpbb\tree\tree_interface' => 'phpbb\tree\tree_interface', +); + +foreach ($iterator as $file) +{ + if ($file->getExtension() == 'php') + { + $code = file_get_contents($file->getPathname()); + + foreach ($map as $orig => $new) + { + $code = preg_replace("#([^a-z0-9_\$])$orig([^a-z0-9_])#i", '\\1' . $new . '\\2', $code); + } + file_put_contents($file->getPathname(), $code); + } +} |