Skip to content

Commit c2efd7f

Browse files
committed
Initial upload
0 parents  commit c2efd7f

File tree

9 files changed

+1039
-0
lines changed

9 files changed

+1039
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor
2+
.*.cache
3+
composer.lock

.php_cs

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
$finder = PhpCsFixer\Finder::create()
3+
->files()
4+
->in(__DIR__ . '/src')
5+
->in(__DIR__ . '/tests')
6+
->name('*.php');
7+
8+
9+
$header = <<<'EOF'
10+
This file is part of Utf8.
11+
(c) Fabrice de Stefanis / https://github.com/fab2s/Utf8
12+
This source file is licensed under the MIT license which you will
13+
find in the LICENSE file or at https://opensource.org/licenses/MIT
14+
EOF;
15+
16+
return PhpCsFixer\Config::create()
17+
->setRiskyAllowed(true)
18+
->setRules([
19+
'@PSR2' => true,
20+
'strict_param' => true,
21+
'array_syntax' => array('syntax' => 'short'),
22+
'binary_operator_spaces' => [
23+
'align_double_arrow' => true,
24+
'align_equals' => true
25+
],
26+
'blank_line_after_namespace' => true,
27+
'blank_line_after_opening_tag' => true,
28+
'blank_line_before_return' => true,
29+
'braces' => true,
30+
'cast_spaces' => true,
31+
'class_definition' => array('singleLine' => true),
32+
'class_keyword_remove' => false,
33+
'combine_consecutive_unsets' => true,
34+
'concat_space' => ['spacing' => 'one'],
35+
'declare_equal_normalize' => true,
36+
//'declare_strict_types' => true,
37+
'elseif' => true,
38+
'encoding' => true,
39+
'full_opening_tag' => true,
40+
'function_declaration' => true,
41+
'function_typehint_space' => true,
42+
'hash_to_slash_comment' => true,
43+
'header_comment' => array('header' => $header),
44+
'include' => true,
45+
'indentation_type' => true,
46+
'line_ending' => true,
47+
'linebreak_after_opening_tag' => true,
48+
'lowercase_cast' => true,
49+
'lowercase_constants' => true,
50+
'lowercase_keywords' => true,
51+
'method_argument_space' => true,
52+
'method_separation' => true,
53+
'native_function_casing' => true,
54+
'new_with_braces' => false,
55+
'no_blank_lines_after_class_opening' => true,
56+
'no_blank_lines_after_phpdoc' => true,
57+
'no_closing_tag' => true,
58+
'no_empty_comment' => true,
59+
'no_empty_phpdoc' => true,
60+
'no_empty_statement' => true,
61+
'no_extra_consecutive_blank_lines' => [
62+
'break',
63+
'continue',
64+
'extra',
65+
'return',
66+
'throw',
67+
'use',
68+
'parenthesis_brace_block',
69+
'square_brace_block',
70+
'curly_brace_block'
71+
],
72+
'no_leading_import_slash' => true,
73+
'no_leading_namespace_whitespace' => true,
74+
'no_mixed_echo_print' => array('use' => 'echo'),
75+
'no_multiline_whitespace_around_double_arrow' => true,
76+
'no_multiline_whitespace_before_semicolons' => true,
77+
'no_short_bool_cast' => true,
78+
'no_singleline_whitespace_before_semicolons' => true,
79+
'no_spaces_after_function_name' => true,
80+
'no_spaces_around_offset' => true,
81+
'no_spaces_inside_parenthesis' => true,
82+
'no_trailing_comma_in_list_call' => true,
83+
'no_trailing_comma_in_singleline_array' => true,
84+
'no_trailing_whitespace' => true,
85+
'no_trailing_whitespace_in_comment' => true,
86+
'no_unneeded_control_parentheses' => true,
87+
'no_unused_imports' => true,
88+
'no_useless_else' => true,
89+
'no_useless_return' => true,
90+
'no_whitespace_before_comma_in_array' => true,
91+
'no_whitespace_in_blank_line' => true,
92+
'normalize_index_brace' => true,
93+
'object_operator_without_whitespace' => true,
94+
'ordered_class_elements' => true,
95+
'ordered_imports' => true,
96+
'php_unit_fqcn_annotation' => true,
97+
'phpdoc_add_missing_param_annotation' => true,
98+
'phpdoc_align' => true,
99+
'phpdoc_annotation_without_dot' => true,
100+
'phpdoc_indent' => true,
101+
'phpdoc_inline_tag' => true,
102+
'phpdoc_no_access' => true,
103+
'phpdoc_no_alias_tag' => true,
104+
'phpdoc_no_empty_return' => true,
105+
'phpdoc_no_package' => true,
106+
'phpdoc_no_useless_inheritdoc' => true,
107+
'phpdoc_order' => true,
108+
'phpdoc_return_self_reference' => true,
109+
'phpdoc_scalar' => true,
110+
'phpdoc_separation' => true,
111+
'phpdoc_single_line_var_spacing' => true,
112+
'phpdoc_summary' => false,
113+
'phpdoc_to_comment' => true,
114+
'phpdoc_trim' => true,
115+
'phpdoc_types' => true,
116+
'phpdoc_var_without_name' => true,
117+
'pre_increment' => true,
118+
'psr4' => true,
119+
'return_type_declaration' => true,
120+
'self_accessor' => true,
121+
'semicolon_after_instruction' => true,
122+
'short_scalar_cast' => true,
123+
'single_blank_line_at_eof' => true,
124+
'single_blank_line_before_namespace' => true,
125+
'single_class_element_per_statement' => true,
126+
'single_import_per_statement' => true,
127+
'single_line_after_imports' => true,
128+
'single_quote' => true,
129+
'space_after_semicolon' => true,
130+
'standardize_not_equals' => true,
131+
'switch_case_semicolon_to_colon' => true,
132+
'switch_case_space' => true,
133+
'ternary_operator_spaces' => true,
134+
'trailing_comma_in_multiline_array' => true,
135+
'trim_array_spaces' => true,
136+
'unary_operator_spaces' => true,
137+
'visibility_required' => true,
138+
'whitespace_after_comma_in_array' => true,
139+
140+
])
141+
->setFinder($finder);

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: php
2+
3+
php:
4+
- 7.1
5+
- 7.2
6+
- 7.3
7+
8+
before_script:
9+
- composer self-update
10+
- composer install --no-interaction
11+
12+
script:
13+
- vendor/bin/phpunit

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 fab2s
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Utf8
2+
3+
[![Build Status](https://travis-ci.org/fab2s/Utf8.svg?branch=master)](https://travis-ci.org/fab2s/Utf8) [![Latest Stable Version](https://poser.pugx.org/fab2s/utf8/v/stable)](https://packagist.org/packages/fab2s/utf8) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/fab2s/Utf8/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/fab2s/Utf8/?branch=master) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](http://makeapullrequest.com) [![License](https://poser.pugx.org/fab2s/utf8/license)](https://packagist.org/packages/fab2s/utf8)
4+
5+
A purely static UTF-8 Helper based on [mb_string](https://php.net/mb_string) and [ext-intl](https://php.net/intl)
6+
7+
> For sure this is not new, and there is better out there, but this is small and does the job without a lot of noise
8+
9+
## Installation
10+
11+
`Utf8` can be installed using composer:
12+
13+
```
14+
composer require "fab2s/utf8"
15+
```
16+
17+
`Utf8` is also included in [OpinHelper](https://github.com/fab2s/OpinHelpers) which packages several bellow "Swiss Army Knife" level Helpers covering some of the most annoying aspects of php programing, such as UTF8 string manipulation, high precision Mathematics or properly locking a file
18+
19+
## Prerequisites
20+
21+
`Utf8` requires [mb_string](https://php.net/mb_string), [ext-intl](https://php.net/intl) is auto detected and used when available for UTF8 Normalization
22+
23+
## In practice
24+
25+
`Utf8` offers replacement for most native string functions with support for UTF-8:
26+
27+
- `Utf8::strrpos(string string $str, string $needle, int $offset = null):int|false`
28+
29+
UTF-8 aware [strrpos()](https://php.net/strrpos) replacement
30+
31+
- `Utf8::strpos(string $str, string $needle, int $offset = 0):int|false`
32+
33+
UTF-8 aware [strpos()](https://php.net/strpos) replacement
34+
35+
- `Utf8::strtolower(string $str):string`
36+
37+
UTF-8 aware [strtolower()](https://php.net/strtolower) replacement
38+
39+
- `Utf8::strtoupper(string $str):string`
40+
41+
UTF-8 aware [strtoupper()](https://php.net/strtoupper) replacement
42+
43+
- `Utf8::substr(string $str, int $offset, int $length = null):string`
44+
45+
UTF-8 aware [substr()](https://php.net/substr) replacement
46+
47+
- `Utf8::strlen(string $str):int`
48+
49+
UTF-8 aware [strlen()](https://php.net/strlen) replacement
50+
51+
- `Utf8::ucfirst(string $str):string`
52+
53+
UTF-8 aware [ucfirst()](https://php.net/ucfirst) replacement
54+
55+
- `Utf8::ucwords(string $str):string`
56+
57+
UTF-8 aware [ucwords()](https://php.net/ucwords) replacement
58+
59+
- `Utf8::ord(string $chr):int|false`
60+
61+
UTF-8 aware [ord()](https://php.net/ord) replacement
62+
63+
- `Utf8::chr(int $num):string|false`
64+
65+
UTF-8 aware [chr()](https://php.net/chr) replacement
66+
67+
And some simple utility methods:
68+
69+
- `Utf8::normalize(string $string, int $canonicalForm = self::NORMALIZE_NFC):string`
70+
71+
UTF-8 [ext-intl](https://php.net/intl) [Normalizer](https://php.net/normalizer.normalize)
72+
> **WARNING**: This method will do nothing in case `ext-intl` is not installed on the host
73+
> This means it is up to you to make sure about it using `Utf8::normalizerSupport`
74+
> or by adding `ext-intl` as a requirement to your project's `composer.json` file
75+
76+
- `Utf8::hasUtf8(string $string):bool`
77+
78+
Tells if the input string contains some UTF-8
79+
80+
- `Utf8::isUtf8(string $string):bool`
81+
82+
Tells if the input string is valid UTF-8
83+
84+
- `Utf8::replaceMb4(string $string, string $replace = ''):string`
85+
86+
Replaces all [Utf8Mb4](https://stackoverflow.com/a/30074553/7630496) characters (aka mostly [emoji](https://en.wikipedia.org/wiki/Emoji))
87+
88+
- `Utf8::normalizerSupport(bool $disable = false):bool`
89+
90+
Tells if [Normalizer](https://php.net/normalizer.normalize) is available or disable Normalizer support
91+
92+
## Requirements
93+
94+
`Utf8` is tested against php 7.1, 7.2 and 7.3.
95+
96+
## Contributing
97+
98+
Contributions are welcome, do not hesitate to open issues and submit pull requests.
99+
100+
## License
101+
102+
Each of `Utf8` components are open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT)

composer.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name" : "fab2s/utf8",
3+
"description" : "A purely static UTF8 Helper based on mb_string and ext-intl",
4+
"type" : "library",
5+
"authors" : [{
6+
"name" : "Fabrice de Stefanis"
7+
}],
8+
"keywords" : [
9+
"PHP",
10+
"Simple",
11+
"Helper",
12+
"Utf8",
13+
"utf-8",
14+
"mb_string",
15+
"nfc",
16+
"nfd",
17+
"normalize",
18+
"intl"
19+
],
20+
"license" : [
21+
"MIT"
22+
],
23+
"require" : {
24+
"php": ">=7.1",
25+
"ext-mbstring": "*"
26+
},
27+
"require-dev": {
28+
"phpunit/phpunit": "~7.0|~8.0"
29+
},
30+
"autoload": {
31+
"classmap": [
32+
"src"
33+
]
34+
},
35+
"autoload-dev": {
36+
"psr-4": {
37+
"fab2s\\Tests\\": "tests/"
38+
}
39+
},
40+
"suggest": {
41+
"ext-intl": "To use Utf8 Normalization"
42+
}
43+
}

phpunit.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
verbose="true">
12+
<testsuites>
13+
<testsuite name="Application Test Suite">
14+
<directory>./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
<php>
18+
<env name="APP_ENV" value="testing"/>
19+
<env name="CACHE_DRIVER" value="array"/>
20+
<env name="SESSION_DRIVER" value="array"/>
21+
<env name="QUEUE_DRIVER" value="sync"/>
22+
<ini name="display_errors" value="On"/>
23+
<ini name="display_startup_errors" value="On"/>
24+
</php>
25+
</phpunit>

0 commit comments

Comments
 (0)