From e325c204eb86fca93b223b79388708aa4e0d3824 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 18 Apr 2013 15:59:20 +0200 Subject: [PATCH] PSR-0 autoloading and manual bootup configuration is now required --- README.md | 16 +- bootup.utf8.php | 16 +- class/Patchwork/Utf8/Bootup.php | 292 +++++++++++++++++++++++++++++ class/Patchwork/Utf8/bootup.php | 319 -------------------------------- composer.json | 4 +- tests/bootstrap.php | 19 +- 6 files changed, 323 insertions(+), 343 deletions(-) create mode 100644 class/Patchwork/Utf8/Bootup.php delete mode 100644 class/Patchwork/Utf8/bootup.php diff --git a/README.md b/README.md index b8ebd33..b909a30 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Here is the set of portability-fallbacks that are currently implemented: grapheme_strlen, grapheme_strpos, grapheme_strripos, grapheme_strrpos, grapheme_strstr, grapheme_substr*. -`pcre` compiled with unicode support is currently required. +`pcre` compiled with unicode support is required. Patchwork\Utf8 -------------- @@ -61,6 +61,7 @@ trim, str_ireplace, str_pad, str_shuffle, str_split, str_word_count, strcmp, strnatcmp, strcasecmp, strnatcasecmp, strncasecmp, strncmp, strcspn, strpbrk, strrev, strspn, strtr, substr_compare, substr_count, substr_replace, ucfirst, lcfirst, ucwords, number_format, utf8_encode, utf8_decode*. + Missing are *printf*-family functions. Usage @@ -72,22 +73,21 @@ the `php composer.phar install` command to install it: { "require": { - "patchwork/utf8": "1.0.*" + "patchwork/utf8": "1.1.*" } } -Otherwise, including the `bootup.utf8.php` file is the easiest way to enable the -portability layer and configure PHP for an UTF-8 aware and portable application. - -Classes are named following PSR-0 autoloader interoperability recommandations, -so other loading scheme are easy to implement. +Then, early in your bootstrap sequence, you have to configure your environment. +The easiest way to do so is by taking inspiration from or just including the +`bootup.utf8.php` file. This will enable the portability layer and configure PHP +for an UTF-8 aware and portable application. The `Patchwork\Utf8` class exposes its features through static methods. Just add a `use Patchwork\Utf8 as u;` at the beginning of your files, then when UTF-8 awareness is required, prefix the string function by `u::`: `echo strlen("déjà");` may become `echo u::strlen("déjà");` eg. -Just run `phpunit` in the `tests/` directory to see the code in action. +Run `phpunit` in the `tests/` directory to see the code in action. Make sure that you are confident about using UTF-8 by reading [Character Sets / Character Encoding Issues](http://www.phpwact.org/php/i18n/charsets) diff --git a/bootup.utf8.php b/bootup.utf8.php index dedff60..dfe918c 100644 --- a/bootup.utf8.php +++ b/bootup.utf8.php @@ -8,12 +8,14 @@ * GNU General Public License v2.0 (http://gnu.org/licenses/gpl-2.0.txt). */ -use Patchwork\Utf8 as u; +use Patchwork\Utf8\Bootup as b; -if (function_exists('Patchwork\Utf8\initAll')) return; +b::initUtf8Encode(); +b::initMbstring(); +b::initIconv(); +b::initExif(); +b::initIntl(); +b::initLocale(); -require __DIR__ . '/class/Patchwork/Utf8/bootup.php'; - -u\initAll(); -u\filterRequestUri(); -u\filterRequestInputs(); +b::filterRequestUri(); +b::filterRequestInputs(); diff --git a/class/Patchwork/Utf8/Bootup.php b/class/Patchwork/Utf8/Bootup.php new file mode 100644 index 0000000..db1b296 --- /dev/null +++ b/class/Patchwork/Utf8/Bootup.php @@ -0,0 +1,292 @@ +=5.3.0" }, "autoload": { - "files": ["bootup.utf8.php"] + "psr-0": { + "Patchwork": "class/" + } } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 7e52a0d..d92e7d5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,12 +1,15 @@