Suggestion: Class to handle Strings |
A few times over the time I have worked with CodeIgniter on projects that involves East languages (chinese and japanese) ...
In most of the time there were no issues related to those languages but at a few cases where I had to make some "strange things", there were some problems related to using mb_ and not mb_ string functions at the framework. So for CI 4 instead of default using both mb_substr or substr I want to suggest making a class to do all the work. It can be 1class only (I think this is enough) or it can be Abstract class (with all required methods) + Childs (Multibyte / Normal / other..) where 1 of the childs will be autoloaded using the config. Best VPS Hosting : Digital Ocean
Simple CI will use it at all places where string methods are required.
Developers from their hands will be able to Switch between Normal Strings methods, multibytes or whatever they want . By this the Framework will be some steps more Open for the developers. If for some reasons dev's don't want to use mb_ or they want to use only mb_ , they will be able just to switch between does 2 .. If some one wants he can make even a mix where some of the methods are mb_ some are not mb_ and some are entirely custom written methods.. + Such library can be and extended to provide some extra methods to developers in 1 place. My believe is that 1 good Framework should provide options to devs, not to force them. P.S. This will remove PHP extension dependency of the framework (MB) and at the same time will support it. I don't know how will work exactly the autoloader and other things at CI 4, but such class can have both : static and none static method support. So $CI->string can be preloaded and at the same time clients can call it using its namespace/Class::method() Best VPS Hosting : Digital Ocean
I've got a class that supports at least UTF-8 compatible string methods, ported a long time ago from Kohana. Maybe sv3tli0 means something similar. https://github.com/ivantcholakov/codeigniter-utf8
Here is an example:
PHP Code: <?php (clear view at gist > https://gist.github.com/sv3tli0/76ea9e81ee73abcc271d ) At the end client will have the best way to work with strings. Best VPS Hosting : Digital Ocean
09-10-2015, 03:19 PM
(This post was last modified: 09-10-2015, 03:40 PM by ivantcholakov. Edit Reason: a typo )
@sv3tli0
It could be done with autodetection, the class could check for mb_string (faster, but less supported encoding), iconv (slower, more supported encodings), intl (I think, it has multibyte routines too, but they are likely not well documented). If none exists, then fallback PHP implementation (by method) could be done. For every method the best possible way can be picked up automatically. |
Welcome Guest, Not a member yet? Register Sign In |