symfony1.4でDeprecated: preg_replace()
ツイート
7 10月
PHPのバージョンを上げると、preg_replace関数でe修飾子を使っていることが非推奨!と怒られます。
symfony1.4ではいくつかe修飾子を使っている部分があり、検索するとPHP5.5系でも使い続けられるよう、lib/vendorのいくつかのファイルを修正する方法が見つかります。
でも、見つかった記事に間違いがあるのか(なんかドメインがczだったのでチェコスロバキア語?ちょっと読めないページで見つけた)、たとえばuser_idというカラムを持ったモデルをdoctrine:build-modelすると、baseクラスがgetUser_idみたいなメソッドを生成するのが気持ち悪いです。getUserIdにしてほしい!
なので、修正したコードを掲載します。多分あっていると思うんですけど。。どうもこの、一番最後に追加したsfToolKitのcamelizeメソッドにミスがあるみたいなんですね。間違ってたら教えて下さい。
パッチファイル:pregFix_for_sf14
lib/vendor/symfony/lib/command/sfCommandManager.class.php
@@ -108,7 +108,9 @@ class sfCommandManager else if (!is_array($arguments)) { // hack to split arguments with spaces : --test="with some spaces" - $arguments = preg_replace('/(\'|")(.+?)\\1/e', "str_replace(' ', '=PLACEHOLDER=', '\\2')", $arguments); + $arguments = preg_replace_callback('/(\'|")(.+?)\\1/', function($matches) { + return str_replace(' ', '=PLACEHOLDER=', $matches[2]); + }, $arguments); $arguments = preg_split('/\s+/', $arguments); $arguments = str_replace('=PLACEHOLDER=', ' ', $arguments); }
lib/vendor/symfony/lib/form/addon/sfFormObject.class.php
@@ -278,6 +278,6 @@ abstract class sfFormObject extends BaseForm protected function camelize($text) { - return preg_replace(array('#/(.?)#e', '/(^|_|-)+(.)/e'), array("'::'.strtoupper('\\1')", "strtoupper('\\2')"), $text); + return sfToolkit::camelize($text); }
lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/form/sfFormFilterDoctrine.class.php
@@ -323,7 +323,7 @@ abstract class sfFormFilterDoctrine extends sfFormFilter protected function camelize($text) { - return sfToolkit::pregtr($text, array('#/(.?)#e' => "'::'.strtoupper('\\1')", '/(^|_|-)+(.)/e' => "strtoupper('\\2')")); + return sfToolkit::camelize($text); }
lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/form/sfFormFilterPropel.class.php
@@ -263,6 +263,6 @@ abstract class sfFormFilterPropel extends sfFormFilter protected function camelize($text) { - return sfToolkit::pregtr($text, array('#/(.?)#e' => "'::'.strtoupper('\\1')", '/(^|_|-)+(.)/e' => "strtoupper('\\2')")); + return sfToolkit::camelize($text); }
lib/vendor/symfony/lib/util/sfInflector.class.php
@@ -28,10 +28,7 @@ class sfInflector public static function camelize($lower_case_and_underscored_word) { $tmp = $lower_case_and_underscored_word; - $tmp = sfToolkit::pregtr($tmp, array('#/(.?)#e' => "'::'.strtoupper('\\1')", - '/(^|_|-)+(.)/e' => "strtoupper('\\2')")); - - return $tmp; + return sfToolkit::camelize($tmp); }
lib/vendor/symfony/lib/util/sfToolkit.class.php
@@ -608,4 +608,18 @@ class sfToolkit return set_include_path(join(PATH_SEPARATOR, $paths)); } + + public static function camelize($text) + { + if (preg_match('#/(.?)#', $text, $matches)) { + $text = str_replace($matches[0], '::'.strtoupper($matches[1]), $text); + } + if (preg_match('/(^|_|-)+(.)/', $text, $matches)) { + $text = preg_replace_callback('/(^|_|-)+(.)/', + function ($m){ + return strtoupper($m[2]); + }, $text); + } + return $text; + } }
No comments yet