From e55c8c95fbbcbc32c03801b4afcc417da7311089 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sat, 1 Sep 2018 13:36:42 +0700 Subject: [PATCH 1/3] Improvements for PHP v7.1. --- .travis.yml | 4 +- composer.json | 11 +- composer.lock | 746 +++++++++++++++++++------------ phpunit.xml | 1 - src/ArrayHelper.php | 4 +- src/BcMathHelper.php | 20 +- src/DateTimeHelper.php | 11 +- src/FileSizeHelper.php | 26 +- src/PathHelper.php | 4 +- src/StringHelper.php | 24 +- src/UrlHelper.php | 4 +- tests/src/ArrayHelperTest.php | 3 +- tests/src/BcMathHelperTest.php | 23 +- tests/src/DateTimeHelperTest.php | 3 +- tests/src/FileSizeHelperTest.php | 10 +- tests/src/PathHelperTest.php | 3 +- tests/src/StringHelperTest.php | 3 +- tests/src/UrlHelperTest.php | 3 +- 18 files changed, 549 insertions(+), 354 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5a3666d..02693a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,6 @@ cache: - $HOME/.composer/cache php: -- 5.6 -- 7.0 - 7.1 - 7.2 @@ -20,7 +18,7 @@ install: - composer install script: -- vendor/bin/phpunit --coverage-clover=coverage.xml +- vendor/bin/phpunit --configuration=phpunit.xml --coverage-clover=coverage.xml after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/composer.json b/composer.json index ec3365c..08e0221 100644 --- a/composer.json +++ b/composer.json @@ -37,21 +37,16 @@ } }, "require": { - "php": ">=5.6.0", + "php": ">=7.1.0", "ext-mbstring": "*", "ext-bcmath": "*" }, "require-dev": { - "phpunit/phpunit": "~5.7", - "symfony/yaml": "~3.4", - "doctrine/instantiator": "1.0.*", - "phpunit/php-token-stream": "~1.0", - "phpdocumentor/reflection-docblock": "~2.0", - "myclabs/deep-copy": "~1.7.0" + "phpunit/phpunit": "~7.0" }, "extra": { "platform": { - "php": "5.6.*" + "php": "7.1.*" } } } diff --git a/composer.lock b/composer.lock index cda60e3..9cff633 100644 --- a/composer.lock +++ b/composer.lock @@ -4,37 +4,37 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d9940764edb5ce689b6e01c4a00dafbc", + "content-hash": "847fe2c8bca9cfff1e9693192642353a", "packages": [], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.0.5", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", + "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", "shasum": "" }, "require": { - "php": ">=5.3,<8.0-DEV" + "php": "^7.1" }, "require-dev": { "athletic/athletic": "~0.1.8", "ext-pdo": "*", "ext-phar": "*", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "~2.0" + "phpunit/phpunit": "^6.2.3", + "squizlabs/php_codesniffer": "^3.0.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.2.x-dev" } }, "autoload": { @@ -59,29 +59,32 @@ "constructor", "instantiate" ], - "time": "2015-06-14T21:17:01+00:00" + "time": "2017-07-22T11:58:36+00:00" }, { "name": "myclabs/deep-copy", - "version": "1.7.0", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e" + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" }, "require-dev": { "doctrine/collections": "^1.0", "doctrine/common": "^2.6", - "phpunit/phpunit": "^4.1" + "phpunit/phpunit": "^7.1" }, "type": "library", "autoload": { @@ -104,41 +107,246 @@ "object", "object graph" ], - "time": "2017-10-19T19:58:43+00:00" + "time": "2018-06-11T23:09:50+00:00" + }, + { + "name": "phar-io/manifest", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-phar": "*", + "phar-io/version": "^2.0", + "php": "^5.6 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "time": "2018-07-08T19:23:20+00:00" + }, + { + "name": "phar-io/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "time": "2018-07-08T19:19:57+00:00" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2017-09-11T18:02:19+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "2.0.5", + "version": "4.3.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "e6a969a640b00d8daa3c66518b0405fb41ae0c4b" + "reference": "94fd0001232e47129dd3504189fa1c7225010d08" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/e6a969a640b00d8daa3c66518b0405fb41ae0c4b", - "reference": "e6a969a640b00d8daa3c66518b0405fb41ae0c4b", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.0", + "phpdocumentor/reflection-common": "^1.0.0", + "phpdocumentor/type-resolver": "^0.4.0", + "webmozart/assert": "^1.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" }, - "suggest": { - "dflydev/markdown": "~1.0", - "erusev/parsedown": "~1.0" + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2017-11-30T07:14:17+00:00" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.4.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "shasum": "" + }, + "require": { + "php": "^5.5 || ^7.0", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { - "psr-0": { - "phpDocumentor": [ + "psr-4": { + "phpDocumentor\\Reflection\\": [ "src/" ] } @@ -150,10 +358,10 @@ "authors": [ { "name": "Mike van Riel", - "email": "mike.vanriel@naenius.com" + "email": "me@mikevanriel.com" } ], - "time": "2016-01-25T08:17:30+00:00" + "time": "2017-07-14T14:27:02+00:00" }, { "name": "phpspec/prophecy", @@ -220,40 +428,40 @@ }, { "name": "phpunit/php-code-coverage", - "version": "4.0.8", + "version": "6.0.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d" + "reference": "865662550c384bc1db7e51d29aeda1c2c161d69a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef7b2f56815df854e66ceaee8ebe9393ae36a40d", - "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/865662550c384bc1db7e51d29aeda1c2c161d69a", + "reference": "865662550c384bc1db7e51d29aeda1c2c161d69a", "shasum": "" }, "require": { "ext-dom": "*", "ext-xmlwriter": "*", - "php": "^5.6 || ^7.0", - "phpunit/php-file-iterator": "^1.3", - "phpunit/php-text-template": "^1.2", - "phpunit/php-token-stream": "^1.4.2 || ^2.0", - "sebastian/code-unit-reverse-lookup": "^1.0", - "sebastian/environment": "^1.3.2 || ^2.0", - "sebastian/version": "^1.0 || ^2.0" + "php": "^7.1", + "phpunit/php-file-iterator": "^2.0", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-token-stream": "^3.0", + "sebastian/code-unit-reverse-lookup": "^1.0.1", + "sebastian/environment": "^3.1", + "sebastian/version": "^2.0.1", + "theseer/tokenizer": "^1.1" }, "require-dev": { - "ext-xdebug": "^2.1.4", - "phpunit/phpunit": "^5.7" + "phpunit/phpunit": "^7.0" }, "suggest": { - "ext-xdebug": "^2.5.1" + "ext-xdebug": "^2.6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0.x-dev" + "dev-master": "6.0-dev" } }, "autoload": { @@ -268,7 +476,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -279,29 +487,29 @@ "testing", "xunit" ], - "time": "2017-04-02T07:44:40+00:00" + "time": "2018-06-01T07:51:50+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.4.5", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" + "reference": "cecbc684605bb0cc288828eb5d65d93d5c676d3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", - "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cecbc684605bb0cc288828eb5d65d93d5c676d3c", + "reference": "cecbc684605bb0cc288828eb5d65d93d5c676d3c", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -316,7 +524,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -326,7 +534,7 @@ "filesystem", "iterator" ], - "time": "2017-11-27T13:52:08+00:00" + "time": "2018-06-11T11:44:00+00:00" }, { "name": "phpunit/php-text-template", @@ -371,28 +579,28 @@ }, { "name": "phpunit/php-timer", - "version": "1.0.9", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + "reference": "8b8454ea6958c3dee38453d3bd571e023108c91f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b8454ea6958c3dee38453d3bd571e023108c91f", + "reference": "8b8454ea6958c3dee38453d3bd571e023108c91f", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -407,7 +615,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -416,33 +624,33 @@ "keywords": [ "timer" ], - "time": "2017-02-26T11:10:40+00:00" + "time": "2018-02-01T13:07:23+00:00" }, { "name": "phpunit/php-token-stream", - "version": "1.4.12", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16" + "reference": "21ad88bbba7c3d93530d93994e0a33cd45f02ace" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1ce90ba27c42e4e44e6d8458241466380b51fa16", - "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/21ad88bbba7c3d93530d93994e0a33cd45f02ace", + "reference": "21ad88bbba7c3d93530d93994e0a33cd45f02ace", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": ">=5.3.3" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -465,55 +673,57 @@ "keywords": [ "tokenizer" ], - "time": "2017-12-04T08:55:13+00:00" + "time": "2018-02-01T13:16:43+00:00" }, { "name": "phpunit/phpunit", - "version": "5.7.27", + "version": "7.3.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c" + "reference": "34705f81bddc3f505b9599a2ef96e2b4315ba9b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", - "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/34705f81bddc3f505b9599a2ef96e2b4315ba9b8", + "reference": "34705f81bddc3f505b9599a2ef96e2b4315ba9b8", "shasum": "" }, "require": { + "doctrine/instantiator": "^1.1", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", - "myclabs/deep-copy": "~1.3", - "php": "^5.6 || ^7.0", - "phpspec/prophecy": "^1.6.2", - "phpunit/php-code-coverage": "^4.0.4", - "phpunit/php-file-iterator": "~1.4", - "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": "^1.0.6", - "phpunit/phpunit-mock-objects": "^3.2", - "sebastian/comparator": "^1.2.4", - "sebastian/diff": "^1.4.3", - "sebastian/environment": "^1.3.4 || ^2.0", - "sebastian/exporter": "~2.0", - "sebastian/global-state": "^1.1", - "sebastian/object-enumerator": "~2.0", - "sebastian/resource-operations": "~1.0", - "sebastian/version": "^1.0.6|^2.0.1", - "symfony/yaml": "~2.1|~3.0|~4.0" + "myclabs/deep-copy": "^1.7", + "phar-io/manifest": "^1.0.2", + "phar-io/version": "^2.0", + "php": "^7.1", + "phpspec/prophecy": "^1.7", + "phpunit/php-code-coverage": "^6.0.7", + "phpunit/php-file-iterator": "^2.0.1", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-timer": "^2.0", + "sebastian/comparator": "^3.0", + "sebastian/diff": "^3.0", + "sebastian/environment": "^3.1", + "sebastian/exporter": "^3.1", + "sebastian/global-state": "^2.0", + "sebastian/object-enumerator": "^3.0.3", + "sebastian/resource-operations": "^1.0", + "sebastian/version": "^2.0.1" }, "conflict": { - "phpdocumentor/reflection-docblock": "3.0.2" + "phpunit/phpunit-mock-objects": "*" }, "require-dev": { "ext-pdo": "*" }, "suggest": { + "ext-soap": "*", "ext-xdebug": "*", - "phpunit/php-invoker": "~1.1" + "phpunit/php-invoker": "^2.0" }, "bin": [ "phpunit" @@ -521,7 +731,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.7.x-dev" + "dev-master": "7.3-dev" } }, "autoload": { @@ -547,66 +757,7 @@ "testing", "xunit" ], - "time": "2018-02-01T05:50:59+00:00" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "3.4.4", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "a23b761686d50a560cc56233b9ecf49597cc9118" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/a23b761686d50a560cc56233b9ecf49597cc9118", - "reference": "a23b761686d50a560cc56233b9ecf49597cc9118", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.2", - "php": "^5.6 || ^7.0", - "phpunit/php-text-template": "^1.2", - "sebastian/exporter": "^1.2 || ^2.0" - }, - "conflict": { - "phpunit/phpunit": "<5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "^5.4" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "time": "2017-06-30T09:13:00+00:00" + "time": "2018-08-22T06:39:21+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -655,30 +806,30 @@ }, { "name": "sebastian/comparator", - "version": "1.2.4", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", - "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", "shasum": "" }, "require": { - "php": ">=5.3.3", - "sebastian/diff": "~1.2", - "sebastian/exporter": "~1.2 || ~2.0" + "php": "^7.1", + "sebastian/diff": "^3.0", + "sebastian/exporter": "^3.1" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -709,38 +860,39 @@ } ], "description": "Provides the functionality to compare PHP values for equality", - "homepage": "http://www.github.com/sebastianbergmann/comparator", + "homepage": "https://github.com/sebastianbergmann/comparator", "keywords": [ "comparator", "compare", "equality" ], - "time": "2017-01-29T09:50:25+00:00" + "time": "2018-07-12T15:12:46+00:00" }, { "name": "sebastian/diff", - "version": "1.4.3", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4" + "reference": "366541b989927187c4ca70490a35615d3fef2dce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4", - "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/366541b989927187c4ca70490a35615d3fef2dce", + "reference": "366541b989927187c4ca70490a35615d3fef2dce", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + "phpunit/phpunit": "^7.0", + "symfony/process": "^2 || ^3.3 || ^4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -765,34 +917,37 @@ "description": "Diff implementation", "homepage": "https://github.com/sebastianbergmann/diff", "keywords": [ - "diff" + "diff", + "udiff", + "unidiff", + "unified diff" ], - "time": "2017-05-22T07:24:03+00:00" + "time": "2018-06-10T07:54:39+00:00" }, { "name": "sebastian/environment", - "version": "2.0.0", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" + "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", - "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/cd0871b3975fb7fc44d11314fd1ee20925fce4f5", + "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "^5.0" + "phpunit/phpunit": "^6.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.1.x-dev" } }, "autoload": { @@ -817,34 +972,34 @@ "environment", "hhvm" ], - "time": "2016-11-26T07:53:53+00:00" + "time": "2017-07-01T08:51:00+00:00" }, { "name": "sebastian/exporter", - "version": "2.0.0", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4" + "reference": "234199f4528de6d12aaa58b612e98f7d36adb937" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", - "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/234199f4528de6d12aaa58b612e98f7d36adb937", + "reference": "234199f4528de6d12aaa58b612e98f7d36adb937", "shasum": "" }, "require": { - "php": ">=5.3.3", - "sebastian/recursion-context": "~2.0" + "php": "^7.0", + "sebastian/recursion-context": "^3.0" }, "require-dev": { "ext-mbstring": "*", - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.1.x-dev" } }, "autoload": { @@ -884,27 +1039,27 @@ "export", "exporter" ], - "time": "2016-11-19T08:54:04+00:00" + "time": "2017-04-03T13:19:02+00:00" }, { "name": "sebastian/global-state", - "version": "1.1.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", - "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "^6.0" }, "suggest": { "ext-uopz": "*" @@ -912,7 +1067,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -935,33 +1090,34 @@ "keywords": [ "global state" ], - "time": "2015-10-12T03:26:01+00:00" + "time": "2017-04-27T15:39:26+00:00" }, { "name": "sebastian/object-enumerator", - "version": "2.0.1", + "version": "3.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7" + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/1311872ac850040a79c3c058bea3e22d0f09cbb7", - "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", "shasum": "" }, "require": { - "php": ">=5.6", - "sebastian/recursion-context": "~2.0" + "php": "^7.0", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" }, "require-dev": { - "phpunit/phpunit": "~5" + "phpunit/phpunit": "^6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0.x-dev" } }, "autoload": { @@ -981,32 +1137,77 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2017-02-18T15:18:39+00:00" + "time": "2017-08-03T12:35:26+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "773f97c67f28de00d397be301821b06708fca0be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", + "reference": "773f97c67f28de00d397be301821b06708fca0be", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "time": "2017-03-29T09:07:27+00:00" }, { "name": "sebastian/recursion-context", - "version": "2.0.0", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a" + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/2c3ba150cbec723aa057506e73a8d33bdb286c9a", - "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0.x-dev" } }, "autoload": { @@ -1034,7 +1235,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2016-11-19T07:33:16+00:00" + "time": "2017-03-03T06:23:57+00:00" }, { "name": "sebastian/resource-operations", @@ -1122,103 +1323,76 @@ "time": "2016-10-03T07:35:21+00:00" }, { - "name": "symfony/polyfill-ctype", - "version": "v1.9.0", + "name": "theseer/tokenizer", + "version": "1.1.0", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" + "url": "https://github.com/theseer/tokenizer.git", + "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b", "shasum": "" }, "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-ctype": "For best performance" + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.9-dev" - } - }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" + "classmap": [ + "src/" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], "authors": [ { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - }, - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" } ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "time": "2018-08-06T14:22:27+00:00" + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "time": "2017-04-07T12:08:54+00:00" }, { - "name": "symfony/yaml", - "version": "v3.4.15", + "name": "webmozart/assert", + "version": "1.3.0", "source": { "type": "git", - "url": "https://github.com/symfony/yaml.git", - "reference": "c2f4812ead9f847cb69e90917ca7502e6892d6b8" + "url": "https://github.com/webmozart/assert.git", + "reference": "0df1908962e7a3071564e857d86874dad1ef204a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/c2f4812ead9f847cb69e90917ca7502e6892d6b8", - "reference": "c2f4812ead9f847cb69e90917ca7502e6892d6b8", + "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", + "reference": "0df1908962e7a3071564e857d86874dad1ef204a", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8", - "symfony/polyfill-ctype": "~1.8" - }, - "conflict": { - "symfony/console": "<3.4" + "php": "^5.3.3 || ^7.0" }, "require-dev": { - "symfony/console": "~3.4|~4.0" - }, - "suggest": { - "symfony/console": "For validating YAML files using the lint command" + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.4-dev" + "dev-master": "1.3-dev" } }, "autoload": { "psr-4": { - "Symfony\\Component\\Yaml\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] + "Webmozart\\Assert\\": "src/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1226,17 +1400,17 @@ ], "authors": [ { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" } ], - "description": "Symfony Yaml Component", - "homepage": "https://symfony.com", - "time": "2018-08-10T07:34:36+00:00" + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2018-01-29T19:49:41+00:00" } ], "aliases": [], @@ -1245,7 +1419,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.6.0", + "php": ">=7.1.0", "ext-mbstring": "*", "ext-bcmath": "*" }, diff --git a/phpunit.xml b/phpunit.xml index 71f4aea..69d7049 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="./tests/bootstrap.php" > diff --git a/src/ArrayHelper.php b/src/ArrayHelper.php index b6f8fa0..ae79ca5 100644 --- a/src/ArrayHelper.php +++ b/src/ArrayHelper.php @@ -1,5 +1,7 @@ $size) { $sizes_power[$size] = pow(1024, $index); } - $bytes = (float)$size_string; + $bytes = (float)$sizeString; $pattern = implode('|', $sizes); if ( - preg_match('#(' . $pattern . ')$#si', $size_string, $matches) && + preg_match('#(' . $pattern . ')$#si', $sizeString, $matches) && $matches[1] && isset($sizes_power[$matches[1]]) ) { diff --git a/src/PathHelper.php b/src/PathHelper.php index a6c1866..d883dff 100644 --- a/src/PathHelper.php +++ b/src/PathHelper.php @@ -1,5 +1,7 @@ Date: Sat, 1 Sep 2018 15:09:34 +0700 Subject: [PATCH 2/3] Transliterate method now use Intl extension. --- README.md | 6 +- composer.json | 3 +- composer.lock | 5 +- src/BcMathHelper.php | 74 ++++++------ src/FileSizeHelper.php | 8 +- src/PathHelper.php | 8 +- src/StringHelper.php | 215 +++------------------------------ src/UrlHelper.php | 8 +- tests/src/StringHelperTest.php | 12 +- 9 files changed, 78 insertions(+), 261 deletions(-) diff --git a/README.md b/README.md index 8bbd1a6..c8b0682 100644 --- a/README.md +++ b/README.md @@ -104,9 +104,9 @@ var_dump(StringHelper::contains('example', 'xampl')); // Prints true echo StringHelper::cut('example', 6); // Prints 'exampl...', '...' is default suffix echo StringHelper::cutWords('simple example', 1); // Prints 'example...', '...' is default suffix -echo StringHelper::transliterate('очень простой пример'); // Prints transliterated 'ochen prostoj primer' -echo StringHelper::standardize('очень простой Пример'); // Prints standardizated 'ochen_prostoj_primer', '_' is default words separator -echo StringHelper::standardize('очень простой Пример', '-'); // Prints 'ochen-prostoj-primer', use '-' for slugify string +echo StringHelper::transliterate('очень простой пример', 'Russian-Latin/BGN'); // Prints transliterated 'ochen prostoj primer' +echo StringHelper::standardize('очень простой Пример', 'Russian-Latin/BGN'); // Prints standardizated 'ochen_prostoj_primer', '_' is default words separator +echo StringHelper::standardize('очень простой Пример', 'Russian-Latin/BGN', '-'); // Prints 'ochen-prostoj-primer', use '-' for slugify string var_dump(StringHelper::toArray('1,2,3,')); // Prints Array ['1', '2', '3'], ',' is default separator ``` diff --git a/composer.json b/composer.json index 08e0221..778a5c0 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,8 @@ "require": { "php": ">=7.1.0", "ext-mbstring": "*", - "ext-bcmath": "*" + "ext-bcmath": "*", + "ext-intl": "*" }, "require-dev": { "phpunit/phpunit": "~7.0" diff --git a/composer.lock b/composer.lock index 9cff633..8bf505a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "847fe2c8bca9cfff1e9693192642353a", + "content-hash": "6b71d635c239492072c7c2f1d26be197", "packages": [], "packages-dev": [ { @@ -1421,7 +1421,8 @@ "platform": { "php": ">=7.1.0", "ext-mbstring": "*", - "ext-bcmath": "*" + "ext-bcmath": "*", + "ext-intl": "*" }, "platform-dev": [] } diff --git a/src/BcMathHelper.php b/src/BcMathHelper.php index c082aa6..604177b 100644 --- a/src/BcMathHelper.php +++ b/src/BcMathHelper.php @@ -21,19 +21,19 @@ class BcMathHelper { /** - * @param mixed $left_operand - * @param mixed $right_operand + * @param mixed $leftOperand + * @param mixed $rightOperand * * @return array */ - protected static function normalizeArgs($left_operand, $right_operand): array + protected static function normalizeArgs($leftOperand, $rightOperand): array { - $left_operand = self::normalizeNumber($left_operand); - $right_operand = self::normalizeNumber($right_operand); + $leftOperand = self::normalizeNumber($leftOperand); + $rightOperand = self::normalizeNumber($rightOperand); return [ - $left_operand, - $right_operand, + $leftOperand, + $rightOperand, ]; } @@ -57,92 +57,92 @@ public static function normalizeNumber($number): string } /** - * @param mixed $left_operand - * @param mixed $right_operand + * @param mixed $leftOperand + * @param mixed $rightOperand * @param int|null $scale * * @return float */ - public static function add($left_operand, $right_operand, ?int $scale = null): float + public static function add($leftOperand, $rightOperand, ?int $scale = null): float { - list($left_operand, $right_operand) = self::normalizeArgs($left_operand, $right_operand); + list($leftOperand, $rightOperand) = self::normalizeArgs($leftOperand, $rightOperand); if (null === $scale) { - return (float)bcadd($left_operand, $right_operand); + return (float)bcadd($leftOperand, $rightOperand); } - return (float)bcadd($left_operand, $right_operand, $scale); + return (float)bcadd($leftOperand, $rightOperand, $scale); } /** - * @param mixed $left_operand - * @param mixed $right_operand + * @param mixed $leftOperand + * @param mixed $rightOperand * @param int|null $scale * * @return float */ - public static function sub($left_operand, $right_operand, ?int $scale = null): float + public static function sub($leftOperand, $rightOperand, ?int $scale = null): float { - list($left_operand, $right_operand) = self::normalizeArgs($left_operand, $right_operand); + list($leftOperand, $rightOperand) = self::normalizeArgs($leftOperand, $rightOperand); if (null === $scale) { - return (float)bcsub($left_operand, $right_operand); + return (float)bcsub($leftOperand, $rightOperand); } - return (float)bcsub($left_operand, $right_operand, $scale); + return (float)bcsub($leftOperand, $rightOperand, $scale); } /** - * @param mixed $left_operand - * @param mixed $right_operand + * @param mixed $leftOperand + * @param mixed $rightOperand * @param int|null $scale * * @return float */ - public static function mul($left_operand, $right_operand, ?int $scale = null): float + public static function mul($leftOperand, $rightOperand, ?int $scale = null): float { - list($left_operand, $right_operand) = self::normalizeArgs($left_operand, $right_operand); + list($leftOperand, $rightOperand) = self::normalizeArgs($leftOperand, $rightOperand); if (null === $scale) { - return (float)bcmul($left_operand, $right_operand); + return (float)bcmul($leftOperand, $rightOperand); } - return (float)bcmul($left_operand, $right_operand, $scale); + return (float)bcmul($leftOperand, $rightOperand, $scale); } /** - * @param mixed $left_operand - * @param mixed $right_operand + * @param mixed $leftOperand + * @param mixed $rightOperand * @param int|null $scale * * @return float */ - public static function div($left_operand, $right_operand, ?int $scale = null): float + public static function div($leftOperand, $rightOperand, ?int $scale = null): float { - list($left_operand, $right_operand) = self::normalizeArgs($left_operand, $right_operand); + list($leftOperand, $rightOperand) = self::normalizeArgs($leftOperand, $rightOperand); if (null === $scale) { - return (float)bcdiv($left_operand, $right_operand); + return (float)bcdiv($leftOperand, $rightOperand); } - return (float)bcdiv($left_operand, $right_operand, $scale); + return (float)bcdiv($leftOperand, $rightOperand, $scale); } /** - * @param mixed $left_operand - * @param mixed $right_operand + * @param mixed $leftOperand + * @param mixed $rightOperand * @param int|null $scale * * @return int */ - public static function comp($left_operand, $right_operand, ?int $scale = null): int + public static function comp($leftOperand, $rightOperand, ?int $scale = null): int { - list($left_operand, $right_operand) = self::normalizeArgs($left_operand, $right_operand); + list($leftOperand, $rightOperand) = self::normalizeArgs($leftOperand, $rightOperand); if (null === $scale) { - return (int)bccomp($left_operand, $right_operand); + return (int)bccomp($leftOperand, $rightOperand); } - return (int)bccomp($left_operand, $right_operand, $scale); + return (int)bccomp($leftOperand, $rightOperand, $scale); } } diff --git a/src/FileSizeHelper.php b/src/FileSizeHelper.php index 0abba49..8304c11 100644 --- a/src/FileSizeHelper.php +++ b/src/FileSizeHelper.php @@ -63,9 +63,9 @@ public static function unhumanize( { $sizeString = trim($sizeString); - $sizes_power = []; + $sizesPower = []; foreach ($sizes as $index => $size) { - $sizes_power[$size] = pow(1024, $index); + $sizesPower[$size] = pow(1024, $index); } $bytes = (float)$sizeString; @@ -74,9 +74,9 @@ public static function unhumanize( if ( preg_match('#(' . $pattern . ')$#si', $sizeString, $matches) && $matches[1] && - isset($sizes_power[$matches[1]]) + isset($sizesPower[$matches[1]]) ) { - $bytes *= $sizes_power[$matches[1]]; + $bytes *= $sizesPower[$matches[1]]; } return (integer)round($bytes); diff --git a/src/PathHelper.php b/src/PathHelper.php index d883dff..0ba9a0b 100644 --- a/src/PathHelper.php +++ b/src/PathHelper.php @@ -22,15 +22,15 @@ class PathHelper { /** * @param string $path - * @param string $public_path + * @param string $publicPath * * @return string */ - public static function toURL(string $path, string $public_path): string + public static function toURL(string $path, string $publicPath): string { - $unix_public = rtrim(str_replace('\\', '/', $public_path), '\\/') . '/'; + $unixPublic = rtrim(str_replace('\\', '/', $publicPath), '\\/') . '/'; $path = str_replace('\\', '/', $path); - return str_replace([$unix_public], '/', $path); + return str_replace([$unixPublic], '/', $path); } } diff --git a/src/StringHelper.php b/src/StringHelper.php index 45a7155..cf9ab82 100644 --- a/src/StringHelper.php +++ b/src/StringHelper.php @@ -20,6 +20,8 @@ */ class StringHelper { + const RUSSIAN_RULES = 'Russian-Latin/BGN'; + /** * @param string $haystack * @param string $needle @@ -87,215 +89,28 @@ public static function cutWords(string $string, int $limit = 25, string $append } /** + * @see http://demo.icu-project.org/icu-bin/translit + * * @param string $string + * @param string $rules * * @return string */ - public static function transliterate(string $string): string + public static function transliterate(string $string, string $rules): string { - $transliterate_table = [ - // Lower accents - 'à' => 'a', 'ô' => 'o', 'ď' => 'd', 'ḟ' => 'f', 'ë' => 'e', 'š' => 's', 'ơ' => 'o', 'ß' => 'ss', 'ă' => 'a', - 'ř' => 'r', 'ț' => 't', 'ň' => 'n', 'ā' => 'a', 'ķ' => 'k', 'ŝ' => 's', 'ỳ' => 'y', 'ņ' => 'n', 'ĺ' => 'l', - 'ħ' => 'h', 'ṗ' => 'p', 'ó' => 'o', 'ú' => 'u', 'ě' => 'e', 'é' => 'e', 'ç' => 'c', 'ẁ' => 'w', 'ċ' => 'c', - 'õ' => 'o', 'ṡ' => 's', 'ø' => 'o', 'ģ' => 'g', 'ŧ' => 't', 'ș' => 's', 'ė' => 'e', 'ĉ' => 'c', 'ś' => 's', - 'î' => 'i', 'ű' => 'u', 'ć' => 'c', 'ę' => 'e', 'ŵ' => 'w', 'ṫ' => 't', 'ū' => 'u', 'č' => 'c', 'ö' => 'oe', - 'è' => 'e', 'ŷ' => 'y', 'ą' => 'a', 'ł' => 'l', 'ų' => 'u', 'ů' => 'u', 'ş' => 's', 'ğ' => 'g', 'ļ' => 'l', - 'ƒ' => 'f', 'ž' => 'z', 'ẃ' => 'w', 'ḃ' => 'b', 'å' => 'a', 'ì' => 'i', 'ï' => 'i', 'ḋ' => 'd', 'ť' => 't', - 'ŗ' => 'r', 'ä' => 'ae', 'í' => 'i', 'ŕ' => 'r', 'ê' => 'e', 'ü' => 'ue', 'ò' => 'o', 'ē' => 'e', - 'ñ' => 'n', 'ń' => 'n', 'ĥ' => 'h', 'ĝ' => 'g', 'đ' => 'd', 'ĵ' => 'j', 'ÿ' => 'y', 'ũ' => 'u', 'ŭ' => 'u', - 'ư' => 'u', 'ţ' => 't', 'ý' => 'y', 'ő' => 'o', 'â' => 'a', 'ľ' => 'l', 'ẅ' => 'w', 'ż' => 'z', 'ī' => 'i', - 'ã' => 'a', 'ġ' => 'g', 'ṁ' => 'm', 'ō' => 'o', 'ĩ' => 'i', 'ù' => 'u', 'į' => 'i', 'ź' => 'z', 'á' => 'a', - 'û' => 'u', 'þ' => 'th', 'ð' => 'dh', 'æ' => 'ae', 'µ' => 'u', 'ĕ' => 'e', - - // Upper accents - 'À' => 'A', 'Ô' => 'O', 'Ď' => 'D', 'Ḟ' => 'F', 'Ë' => 'E', 'Š' => 'S', 'Ơ' => 'O', 'Ă' => 'A', 'Ř' => 'R', - 'Ț' => 'T', 'Ň' => 'N', 'Ā' => 'A', 'Ķ' => 'K', 'Ŝ' => 'S', 'Ỳ' => 'Y', 'Ņ' => 'N', 'Ĺ' => 'L', 'Ħ' => 'H', - 'Ṗ' => 'P', 'Ó' => 'O', 'Ú' => 'U', 'Ě' => 'E', 'É' => 'E', 'Ç' => 'C', 'Ẁ' => 'W', 'Ċ' => 'C', 'Õ' => 'O', - 'Ṡ' => 'S', 'Ø' => 'O', 'Ģ' => 'G', 'Ŧ' => 'T', 'Ș' => 'S', 'Ė' => 'E', 'Ĉ' => 'C', 'Ś' => 'S', 'Î' => 'I', - 'Ű' => 'U', 'Ć' => 'C', 'Ę' => 'E', 'Ŵ' => 'W', 'Ṫ' => 'T', 'Ū' => 'U', 'Č' => 'C', 'Ö' => 'Oe', 'È' => 'E', - 'Ŷ' => 'Y', 'Ą' => 'A', 'Ł' => 'L', 'Ų' => 'U', 'Ů' => 'U', 'Ş' => 'S', 'Ğ' => 'G', 'Ļ' => 'L', 'Ƒ' => 'F', - 'Ž' => 'Z', 'Ẃ' => 'W', 'Ḃ' => 'B', 'Å' => 'A', 'Ì' => 'I', 'Ï' => 'I', 'Ḋ' => 'D', 'Ť' => 'T', 'Ŗ' => 'R', - 'Ä' => 'Ae', 'Í' => 'I', 'Ŕ' => 'R', 'Ê' => 'E', 'Ü' => 'Ue', 'Ò' => 'O', 'Ē' => 'E', 'Ñ' => 'N', - 'Ń' => 'N', 'Ĥ' => 'H', 'Ĝ' => 'G', 'Đ' => 'D', 'Ĵ' => 'J', 'Ÿ' => 'Y', 'Ũ' => 'U', 'Ŭ' => 'U', 'Ư' => 'U', - 'Ţ' => 'T', 'Ý' => 'Y', 'Ő' => 'O', 'Â' => 'A', 'Ľ' => 'L', 'Ẅ' => 'W', 'Ż' => 'Z', 'Ī' => 'I', 'Ã' => 'A', - 'Ġ' => 'G', 'Ṁ' => 'M', 'Ō' => 'O', 'Ĩ' => 'I', 'Ù' => 'U', 'Į' => 'I', 'Ź' => 'Z', 'Á' => 'A', 'Û' => 'U', - 'Þ' => 'Th', 'Ð' => 'Dh', 'Æ' => 'Ae', 'Ĕ' => 'E', - - // Russian cyrillic - 'а' => 'a', 'А' => 'A', 'б' => 'b', 'Б' => 'B', 'в' => 'v', 'В' => 'V', 'г' => 'g', 'Г' => 'G', 'д' => 'd', - 'Д' => 'D', 'е' => 'e', 'Е' => 'E', 'ё' => 'jo', 'Ё' => 'Jo', 'ж' => 'zh', 'Ж' => 'Zh', 'з' => 'z', - 'З' => 'Z', 'и' => 'i', 'И' => 'I', 'й' => 'j', 'Й' => 'J', 'к' => 'k', 'К' => 'K', 'л' => 'l', 'Л' => 'L', - 'м' => 'm', 'М' => 'M', 'н' => 'n', 'Н' => 'N', 'о' => 'o', 'О' => 'O', 'п' => 'p', 'П' => 'P', 'р' => 'r', - 'Р' => 'R', 'с' => 's', 'С' => 'S', 'т' => 't', 'Т' => 'T', 'у' => 'u', 'У' => 'U', 'ф' => 'f', 'Ф' => 'F', - 'х' => 'x', 'Х' => 'X', 'ц' => 'c', 'Ц' => 'C', 'ч' => 'ch', 'Ч' => 'Ch', 'ш' => 'sh', 'Ш' => 'Sh', - 'щ' => 'sch', 'Щ' => 'Sch', 'ъ' => '', 'Ъ' => '', 'ы' => 'y', 'Ы' => 'Y', 'ь' => '', 'Ь' => '', 'э' => 'eh', - 'Э' => 'Eh', 'ю' => 'ju', 'Ю' => 'Ju', 'я' => 'ja', 'Я' => 'Ja', - - // Ukrainian cyrillic - 'Ґ' => 'Gh', 'ґ' => 'gh', 'Є' => 'Je', 'є' => 'je', 'І' => 'I', 'і' => 'i', 'Ї' => 'Ji', 'ї' => 'ji', - - // Georgian - 'ა' => 'a', 'ბ' => 'b', 'გ' => 'g', 'დ' => 'd', 'ე' => 'e', 'ვ' => 'v', 'ზ' => 'z', 'თ' => 'th', 'ი' => 'i', - 'კ' => 'p', 'ლ' => 'l', 'მ' => 'm', 'ნ' => 'n', 'ო' => 'o', 'პ' => 'p', 'ჟ' => 'zh', 'რ' => 'r', 'ს' => 's', - 'ტ' => 't', 'უ' => 'u', 'ფ' => 'ph', 'ქ' => 'kh', 'ღ' => 'gh', 'ყ' => 'q', 'შ' => 'sh', 'ჩ' => 'ch', - 'ც' => 'c', 'ძ' => 'dh', 'წ' => 'w', 'ჭ' => 'j', 'ხ' => 'x', 'ჯ' => 'jh', 'ჰ' => 'xh', - - // Sanskrit - 'अ' => 'a', 'आ' => 'ah', 'इ' => 'i', 'ई' => 'ih', 'उ' => 'u', 'ऊ' => 'uh', 'ऋ' => 'ry', 'ॠ' => 'ryh', - 'ऌ' => 'ly', 'ॡ' => 'lyh', 'ए' => 'e', 'ऐ' => 'ay', 'ओ' => 'o', 'औ' => 'aw', 'अं' => 'amh', 'अः' => 'aq', - 'क' => 'k', 'ख' => 'kh', 'ग' => 'g', 'घ' => 'gh', 'ङ' => 'nh', 'च' => 'c', 'छ' => 'ch', 'ज' => 'j', - 'झ' => 'jh', 'ञ' => 'ny', 'ट' => 'tq', 'ठ' => 'tqh', 'ड' => 'dq', 'ढ' => 'dqh', 'ण' => 'nq', 'त' => 't', - 'थ' => 'th', 'द' => 'd', 'ध' => 'dh', 'न' => 'n', 'प' => 'p', 'फ' => 'ph', 'ब' => 'b', 'भ' => 'bh', - 'म' => 'm', 'य' => 'z', 'र' => 'r', 'ल' => 'l', 'व' => 'v', 'श' => 'sh', 'ष' => 'sqh', 'स' => 's', - 'ह' => 'x', - - // Hebrew - 'א' => 'a', 'ב' => 'b', 'ג' => 'g', 'ד' => 'd', 'ה' => 'h', 'ו' => 'v', 'ז' => 'z', 'ח' => 'kh', - 'ט' => 'th', 'י' => 'y', 'ך' => 'h', 'כ' => 'k', 'ל' => 'l', 'ם' => 'm', 'מ' => 'm', 'ן' => 'n', 'נ' => 'n', - 'ס' => 's', 'ע' => 'ah', 'ף' => 'f', 'פ' => 'p', 'ץ' => 'c', 'צ' => 'c', 'ק' => 'q', 'ר' => 'r', - 'ש' => 'sh', 'ת' => 't', - - // Arabic - 'ا' => 'a', 'ب' => 'b', 'ت' => 't', 'ث' => 'th', 'ج' => 'g', 'ح' => 'xh', 'خ' => 'x', 'د' => 'd', - 'ذ' => 'dh', 'ر' => 'r', 'ز' => 'z', 'س' => 's', 'ش' => 'sh', 'ص' => 's\'', 'ض' => 'd\'', 'ط' => 't\'', - 'ظ' => 'z\'', 'ع' => 'y', 'غ' => 'gh', 'ف' => 'f', 'ق' => 'q', 'ك' => 'k', 'ل' => 'l', 'م' => 'm', - 'ن' => 'n', 'ه' => 'x\'', 'و' => 'u', 'ي' => 'i', - - // Persian - 'ک' => 'k', 'گ' => 'g', 'پ' => 'p', 'ژ' => 'zh', 'ی' => 'i', 'چ' => 'ch', - - // Japanese hiragana - 'あ' => 'a', 'え' => 'e', 'い' => 'i', 'お' => 'o', 'う' => 'u', 'ば' => 'ba', 'べ' => 'be', 'び' => 'bi', - 'ぼ' => 'bo', 'ぶ' => 'bu', 'し' => 'ci', 'だ' => 'da', 'で' => 'de', 'ぢ' => 'di', 'ど' => 'do', 'づ' => 'du', - 'ふぁ' => 'fa', 'ふぇ' => 'fe', 'ふぃ' => 'fi', 'ふぉ' => 'fo', 'ふ' => 'fu', 'が' => 'ga', 'げ' => 'ge', - 'ぎ' => 'gi', 'ご' => 'go', 'ぐ' => 'gu', 'は' => 'ha', 'へ' => 'he', 'ひ' => 'hi', 'ほ' => 'ho', 'ふ' => 'hu', - 'じゃ' => 'ja', 'じぇ' => 'je', 'じ' => 'ji', 'じょ' => 'jo', 'じゅ' => 'ju', 'か' => 'ka', 'け' => 'ke', - 'き' => 'ki', 'こ' => 'ko', 'く' => 'ku', 'ら' => 'la', 'れ' => 'le', 'り' => 'li', 'ろ' => 'lo', 'る' => 'lu', - 'ま' => 'ma', 'め' => 'me', 'み' => 'mi', 'も' => 'mo', 'む' => 'mu', 'な' => 'na', 'ね' => 'ne', 'に' => 'ni', - 'の' => 'no', 'ぬ' => 'nu', 'ぱ' => 'pa', 'ぺ' => 'pe', 'ぴ' => 'pi', 'ぽ' => 'po', 'ぷ' => 'pu', 'ら' => 'ra', - 'れ' => 're', 'り' => 'ri', 'ろ' => 'ro', 'る' => 'ru', 'さ' => 'sa', 'せ' => 'se', 'し' => 'si', 'そ' => 'so', - 'す' => 'su', 'た' => 'ta', 'て' => 'te', 'ち' => 'ti', 'と' => 'to', 'つ' => 'tu', 'ヴぁ' => 'va', - 'ヴぇ' => 've', 'ヴぃ' => 'vi', 'ヴぉ' => 'vo', 'ヴ' => 'vu', 'わ' => 'wa', 'うぇ' => 'we', 'うぃ' => 'wi', - 'を' => 'wo', 'や' => 'ya', 'いぇ' => 'ye', 'い' => 'yi', 'よ' => 'yo', 'ゆ' => 'yu', 'ざ' => 'za', - 'ぜ' => 'ze', 'じ' => 'zi', 'ぞ' => 'zo', 'ず' => 'zu', 'びゃ' => 'bya', 'びぇ' => 'bye', 'びぃ' => 'byi', - 'びょ' => 'byo', 'びゅ' => 'byu', 'ちゃ' => 'cha', 'ちぇ' => 'che', 'ち' => 'chi', 'ちょ' => 'cho', - 'ちゅ' => 'chu', 'ちゃ' => 'cya', 'ちぇ' => 'cye', 'ちぃ' => 'cyi', 'ちょ' => 'cyo', 'ちゅ' => 'cyu', - 'でゃ' => 'dha', 'でぇ' => 'dhe', 'でぃ' => 'dhi', 'でょ' => 'dho', 'でゅ' => 'dhu', 'どぁ' => 'dwa', - 'どぇ' => 'dwe', 'どぃ' => 'dwi', 'どぉ' => 'dwo', 'どぅ' => 'dwu', 'ぢゃ' => 'dya', 'ぢぇ' => 'dye', - 'ぢぃ' => 'dyi', 'ぢょ' => 'dyo', 'ぢゅ' => 'dyu', 'ぢ' => 'dzi', 'ふぁ' => 'fwa', 'ふぇ' => 'fwe', - 'ふぃ' => 'fwi', 'ふぉ' => 'fwo', 'ふぅ' => 'fwu', 'ふゃ' => 'fya', 'ふぇ' => 'fye', 'ふぃ' => 'fyi', - 'ふょ' => 'fyo', 'ふゅ' => 'fyu', 'ぎゃ' => 'gya', 'ぎぇ' => 'gye', 'ぎぃ' => 'gyi', 'ぎょ' => 'gyo', - 'ぎゅ' => 'gyu', 'ひゃ' => 'hya', 'ひぇ' => 'hye', 'ひぃ' => 'hyi', 'ひょ' => 'hyo', 'ひゅ' => 'hyu', - 'じゃ' => 'jya', 'じぇ' => 'jye', 'じぃ' => 'jyi', 'じょ' => 'jyo', 'じゅ' => 'jyu', 'きゃ' => 'kya', - 'きぇ' => 'kye', 'きぃ' => 'kyi', 'きょ' => 'kyo', 'きゅ' => 'kyu', 'りゃ' => 'lya', 'りぇ' => 'lye', - 'りぃ' => 'lyi', 'りょ' => 'lyo', 'りゅ' => 'lyu', 'みゃ' => 'mya', 'みぇ' => 'mye', 'みぃ' => 'myi', - 'みょ' => 'myo', 'みゅ' => 'myu', 'ん' => 'n', 'にゃ' => 'nya', 'にぇ' => 'nye', 'にぃ' => 'nyi', - 'にょ' => 'nyo', 'にゅ' => 'nyu', 'ぴゃ' => 'pya', 'ぴぇ' => 'pye', 'ぴぃ' => 'pyi', 'ぴょ' => 'pyo', - 'ぴゅ' => 'pyu', 'りゃ' => 'rya', 'りぇ' => 'rye', 'りぃ' => 'ryi', 'りょ' => 'ryo', 'りゅ' => 'ryu', - 'しゃ' => 'sha', 'しぇ' => 'she', 'し' => 'shi', 'しょ' => 'sho', 'しゅ' => 'shu', 'すぁ' => 'swa', - 'すぇ' => 'swe', 'すぃ' => 'swi', 'すぉ' => 'swo', 'すぅ' => 'swu', 'しゃ' => 'sya', 'しぇ' => 'sye', - 'しぃ' => 'syi', 'しょ' => 'syo', 'しゅ' => 'syu', 'てゃ' => 'tha', 'てぇ' => 'the', 'てぃ' => 'thi', - 'てょ' => 'tho', 'てゅ' => 'thu', 'つゃ' => 'tsa', 'つぇ' => 'tse', 'つぃ' => 'tsi', 'つょ' => 'tso', - 'つ' => 'tsu', 'とぁ' => 'twa', 'とぇ' => 'twe', 'とぃ' => 'twi', 'とぉ' => 'two', 'とぅ' => 'twu', - 'ちゃ' => 'tya', 'ちぇ' => 'tye', 'ちぃ' => 'tyi', 'ちょ' => 'tyo', 'ちゅ' => 'tyu', 'ヴゃ' => 'vya', - 'ヴぇ' => 'vye', 'ヴぃ' => 'vyi', 'ヴょ' => 'vyo', 'ヴゅ' => 'vyu', 'うぁ' => 'wha', 'うぇ' => 'whe', - 'うぃ' => 'whi', 'うぉ' => 'who', 'うぅ' => 'whu', 'ゑ' => 'wye', 'ゐ' => 'wyi', 'じゃ' => 'zha', - 'じぇ' => 'zhe', 'じぃ' => 'zhi', 'じょ' => 'zho', 'じゅ' => 'zhu', 'じゃ' => 'zya', 'じぇ' => 'zye', - 'じぃ' => 'zyi', 'じょ' => 'zyo', 'じゅ' => 'zyu', - - // Japanese katakana - 'ア' => 'a', 'エ' => 'e', 'イ' => 'i', 'オ' => 'o', 'ウ' => 'u', 'バ' => 'ba', 'ベ' => 'be', 'ビ' => 'bi', - 'ボ' => 'bo', 'ブ' => 'bu', 'シ' => 'ci', 'ダ' => 'da', 'デ' => 'de', 'ヂ' => 'di', 'ド' => 'do', 'ヅ' => 'du', - 'ファ' => 'fa', 'フェ' => 'fe', 'フィ' => 'fi', 'フォ' => 'fo', 'フ' => 'fu', 'ガ' => 'ga', 'ゲ' => 'ge', - 'ギ' => 'gi', 'ゴ' => 'go', 'グ' => 'gu', 'ハ' => 'ha', 'ヘ' => 'he', 'ヒ' => 'hi', 'ホ' => 'ho', 'フ' => 'hu', - 'ジャ' => 'ja', 'ジェ' => 'je', 'ジ' => 'ji', 'ジョ' => 'jo', 'ジュ' => 'ju', 'カ' => 'ka', 'ケ' => 'ke', - 'キ' => 'ki', 'コ' => 'ko', 'ク' => 'ku', 'ラ' => 'la', 'レ' => 'le', 'リ' => 'li', 'ロ' => 'lo', 'ル' => 'lu', - 'マ' => 'ma', 'メ' => 'me', 'ミ' => 'mi', 'モ' => 'mo', 'ム' => 'mu', 'ナ' => 'na', 'ネ' => 'ne', 'ニ' => 'ni', - 'ノ' => 'no', 'ヌ' => 'nu', 'パ' => 'pa', 'ペ' => 'pe', 'ピ' => 'pi', 'ポ' => 'po', 'プ' => 'pu', 'ラ' => 'ra', - 'レ' => 're', 'リ' => 'ri', 'ロ' => 'ro', 'ル' => 'ru', 'サ' => 'sa', 'セ' => 'se', 'シ' => 'si', 'ソ' => 'so', - 'ス' => 'su', 'タ' => 'ta', 'テ' => 'te', 'チ' => 'ti', 'ト' => 'to', 'ツ' => 'tu', 'ヴァ' => 'va', - 'ヴェ' => 've', 'ヴィ' => 'vi', 'ヴォ' => 'vo', 'ヴ' => 'vu', 'ワ' => 'wa', 'ウェ' => 'we', 'ウィ' => 'wi', - 'ヲ' => 'wo', 'ヤ' => 'ya', 'イェ' => 'ye', 'イ' => 'yi', 'ヨ' => 'yo', 'ユ' => 'yu', 'ザ' => 'za', - 'ゼ' => 'ze', 'ジ' => 'zi', 'ゾ' => 'zo', 'ズ' => 'zu', 'ビャ' => 'bya', 'ビェ' => 'bye', 'ビィ' => 'byi', - 'ビョ' => 'byo', 'ビュ' => 'byu', 'チャ' => 'cha', 'チェ' => 'che', 'チ' => 'chi', 'チョ' => 'cho', - 'チュ' => 'chu', 'チャ' => 'cya', 'チェ' => 'cye', 'チィ' => 'cyi', 'チョ' => 'cyo', 'チュ' => 'cyu', - 'デャ' => 'dha', 'デェ' => 'dhe', 'ディ' => 'dhi', 'デョ' => 'dho', 'デュ' => 'dhu', 'ドァ' => 'dwa', - 'ドェ' => 'dwe', 'ドィ' => 'dwi', 'ドォ' => 'dwo', 'ドゥ' => 'dwu', 'ヂャ' => 'dya', 'ヂェ' => 'dye', - 'ヂィ' => 'dyi', 'ヂョ' => 'dyo', 'ヂュ' => 'dyu', 'ヂ' => 'dzi', 'ファ' => 'fwa', 'フェ' => 'fwe', - 'フィ' => 'fwi', 'フォ' => 'fwo', 'フゥ' => 'fwu', 'フャ' => 'fya', 'フェ' => 'fye', 'フィ' => 'fyi', - 'フョ' => 'fyo', 'フュ' => 'fyu', 'ギャ' => 'gya', 'ギェ' => 'gye', 'ギィ' => 'gyi', 'ギョ' => 'gyo', - 'ギュ' => 'gyu', 'ヒャ' => 'hya', 'ヒェ' => 'hye', 'ヒィ' => 'hyi', 'ヒョ' => 'hyo', 'ヒュ' => 'hyu', - 'ジャ' => 'jya', 'ジェ' => 'jye', 'ジィ' => 'jyi', 'ジョ' => 'jyo', 'ジュ' => 'jyu', 'キャ' => 'kya', - 'キェ' => 'kye', 'キィ' => 'kyi', 'キョ' => 'kyo', 'キュ' => 'kyu', 'リャ' => 'lya', 'リェ' => 'lye', - 'リィ' => 'lyi', 'リョ' => 'lyo', 'リュ' => 'lyu', 'ミャ' => 'mya', 'ミェ' => 'mye', 'ミィ' => 'myi', - 'ミョ' => 'myo', 'ミュ' => 'myu', 'ン' => 'n', 'ニャ' => 'nya', 'ニェ' => 'nye', 'ニィ' => 'nyi', - 'ニョ' => 'nyo', 'ニュ' => 'nyu', 'ピャ' => 'pya', 'ピェ' => 'pye', 'ピィ' => 'pyi', 'ピョ' => 'pyo', - 'ピュ' => 'pyu', 'リャ' => 'rya', 'リェ' => 'rye', 'リィ' => 'ryi', 'リョ' => 'ryo', 'リュ' => 'ryu', - 'シャ' => 'sha', 'シェ' => 'she', 'シ' => 'shi', 'ショ' => 'sho', 'シュ' => 'shu', 'スァ' => 'swa', - 'スェ' => 'swe', 'スィ' => 'swi', 'スォ' => 'swo', 'スゥ' => 'swu', 'シャ' => 'sya', 'シェ' => 'sye', - 'シィ' => 'syi', 'ショ' => 'syo', 'シュ' => 'syu', 'テャ' => 'tha', 'テェ' => 'the', 'ティ' => 'thi', - 'テョ' => 'tho', 'テュ' => 'thu', 'ツャ' => 'tsa', 'ツェ' => 'tse', 'ツィ' => 'tsi', 'ツョ' => 'tso', - 'ツ' => 'tsu', 'トァ' => 'twa', 'トェ' => 'twe', 'トィ' => 'twi', 'トォ' => 'two', 'トゥ' => 'twu', - 'チャ' => 'tya', 'チェ' => 'tye', 'チィ' => 'tyi', 'チョ' => 'tyo', 'チュ' => 'tyu', 'ヴャ' => 'vya', - 'ヴェ' => 'vye', 'ヴィ' => 'vyi', 'ヴョ' => 'vyo', 'ヴュ' => 'vyu', 'ウァ' => 'wha', 'ウェ' => 'whe', - 'ウィ' => 'whi', 'ウォ' => 'who', 'ウゥ' => 'whu', 'ヱ' => 'wye', 'ヰ' => 'wyi', 'ジャ' => 'zha', - 'ジェ' => 'zhe', 'ジィ' => 'zhi', 'ジョ' => 'zho', 'ジュ' => 'zhu', 'ジャ' => 'zya', 'ジェ' => 'zye', - 'ジィ' => 'zyi', 'ジョ' => 'zyo', 'ジュ' => 'zyu', - - // Greek - 'Γ' => 'G', 'Δ' => 'E', 'Θ' => 'Th', 'Λ' => 'L', 'Ξ' => 'X', 'Π' => 'P', 'Σ' => 'S', 'Φ' => 'F', - 'Ψ' => 'Ps', 'γ' => 'g', 'δ' => 'e', 'θ' => 'th', 'λ' => 'l', 'ξ' => 'x', 'π' => 'p', 'σ' => 's', - 'φ' => 'f', 'ψ' => 'ps', - - // Thai - 'ก' => 'k', 'ข' => 'kh', 'ฃ' => 'kh', 'ค' => 'kh', 'ฅ' => 'kh', 'ฆ' => 'kh', 'ง' => 'ng', 'จ' => 'ch', - 'ฉ' => 'ch', 'ช' => 'ch', 'ซ' => 's', 'ฌ' => 'ch', 'ญ' => 'y', 'ฎ' => 'd', 'ฏ' => 't', 'ฐ' => 'th', - 'ฑ' => 'd', 'ฒ' => 'th', 'ณ' => 'n', 'ด' => 'd', 'ต' => 't', 'ถ' => 'th', 'ท' => 'th', 'ธ' => 'th', - 'น' => 'n', 'บ' => 'b', 'ป' => 'p', 'ผ' => 'ph', 'ฝ' => 'f', 'พ' => 'ph', 'ฟ' => 'f', 'ภ' => 'ph', - 'ม' => 'm', 'ย' => 'y', 'ร' => 'r', 'ฤ' => 'rue', 'ฤๅ' => 'rue', 'ล' => 'l', 'ฦ' => 'lue', 'ฦๅ' => 'lue', - 'ว' => 'w', 'ศ' => 's', 'ษ' => 's', 'ส' => 's', 'ห' => 'h', 'ฬ' => 'l', 'ฮ' => 'h', 'ะ' => 'a', '–ั' => 'a', - 'รร' => 'a', 'า' => 'a', 'รร' => 'an', 'ำ' => 'am', '–ิ' => 'i', '–ี' => 'i', '–ึ' => 'ue', '–ื' => 'ue', - '–ุ' => 'u', '–ู' => 'u', 'เะ' => 'e', 'เ–็' => 'e', 'เ' => 'e', 'แะ' => 'ae', 'แ' => 'ae', 'โะ' => 'o', - 'โ' => 'o', 'เาะ' => 'o', 'อ' => 'o', 'เอะ' => 'oe', 'เ–ิ' => 'oe', 'เอ' => 'oe', 'เ–ียะ' => 'ia', - 'เ–ีย' => 'ia', 'เ–ือะ' => 'uea', 'เ–ือ' => 'uea', '–ัวะ' => 'ua', '–ัว' => 'ua', 'ว' => 'ua', 'ใ' => 'ai', - 'ไ' => 'ai', '–ัย' => 'ai', 'ไย' => 'ai', 'าย' => 'ai', 'เา' => 'ao', 'าว' => 'ao', '–ุย' => 'ui', - 'โย' => 'oi', 'อย' => 'oi', 'เย' => 'oei', 'เ–ือย' => 'ueai', 'วย' => 'uai', '–ิว' => 'io', 'เ–็ว' => 'eo', - 'เว' => 'eo', 'แ–็ว' => 'aeo', 'แว' => 'aeo', 'เ–ียว' => 'iao', - - // Korean - 'ㄱ' => 'k', 'ㅋ' => 'kh', 'ㄲ' => 'kk', 'ㄷ' => 't', 'ㅌ' => 'th', 'ㄸ' => 'tt', 'ㅂ' => 'p', 'ㅍ' => 'ph', - 'ㅃ' => 'pp', 'ㅈ' => 'c', 'ㅊ' => 'ch', 'ㅉ' => 'cc', 'ㅅ' => 's', 'ㅆ' => 'ss', 'ㅎ' => 'h', 'ㅇ' => 'ng', - 'ㄴ' => 'n', 'ㄹ' => 'l', 'ㅁ' => 'm', 'ㅏ' => 'a', 'ㅓ' => 'e', 'ㅗ' => 'o', 'ㅜ' => 'wu', 'ㅡ' => 'u', - 'ㅣ' => 'i', 'ㅐ' => 'ay', 'ㅔ' => 'ey', 'ㅚ' => 'oy', 'ㅘ' => 'wa', 'ㅝ' => 'we', 'ㅟ' => 'wi', 'ㅙ' => 'way', - 'ㅞ' => 'wey', 'ㅢ' => 'uy', 'ㅑ' => 'ya', 'ㅕ' => 'ye', 'ㅛ' => 'oy', 'ㅠ' => 'yu', 'ㅒ' => 'yay', - 'ㅖ' => 'yey', - - // Vietnamese - 'ả' => 'a', 'Ả' => 'a', 'ạ' => 'a', 'Ạ' => 'a', 'ằ' => 'a', 'Ằ' => 'a', 'ẳ' => 'a', 'Ẳ' => 'a', 'ẵ' => 'a', - 'Ẵ' => 'a', 'ắ' => 'a', 'Ắ' => 'a', 'ặ' => 'a', 'Ặ' => 'a', 'ầ' => 'a', 'Ầ' => 'a', 'ẩ' => 'a', 'Ẩ' => 'a', - 'ẫ' => 'a', 'Ẫ' => 'a', 'ấ' => 'a', 'Ấ' => 'a', 'ậ' => 'a', 'Ậ' => 'a', 'ẻ' => 'e', 'Ẻ' => 'e', 'ẽ' => 'e', - 'Ẽ' => 'e', 'ẹ' => 'e', 'Ẹ' => 'e', 'ề' => 'e', 'Ề' => 'e', 'ể' => 'e', 'Ể' => 'e', 'ễ' => 'e', 'Ễ' => 'e', - 'ế' => 'e', 'Ế' => 'e', 'ệ' => 'e', 'Ệ' => 'e', 'ỉ' => 'i', 'Ỉ' => 'i', 'ị' => 'i', 'Ị' => 'i', 'ỏ' => 'o', - 'Ỏ' => 'o', 'ọ' => 'o', 'Ọ' => 'o', 'ồ' => 'o', 'Ồ' => 'o', 'ổ' => 'o', 'Ổ' => 'o', 'ỗ' => 'o', 'Ỗ' => 'o', - 'ố' => 'o', 'Ố' => 'o', 'ộ' => 'o', 'Ộ' => 'o', 'ờ' => 'o', 'Ờ' => 'o', 'ở' => 'o', 'Ở' => 'o', 'ỡ' => 'o', - 'Ỡ' => 'o', 'ớ' => 'o', 'Ớ' => 'o', 'ợ' => 'o', 'Ợ' => 'o', 'ủ' => 'u', 'Ủ' => 'u', 'ụ' => 'u', 'Ụ' => 'u', - 'ừ' => 'u', 'Ừ' => 'u', 'ử' => 'u', 'Ử' => 'u', 'ữ' => 'u', 'Ữ' => 'u', 'ứ' => 'u', 'Ứ' => 'u', 'ự' => 'u', - 'Ự' => 'u', 'ỷ' => 'y', 'Ỷ' => 'y', 'ỹ' => 'y', 'Ỹ' => 'y', 'ỵ' => 'y', 'Ỵ' => 'y', - ]; - - return strtr($string, $transliterate_table); + return transliterator_transliterate($rules, $string); } /** * @param string $string + * @param string $rules * @param string $separator * * @return string */ - public static function standardize(string $string, string $separator = '_'): string + public static function standardize(string $string, string $rules, string $separator = '_'): string { - $string = self::transliterate($string); + $string = self::transliterate($string, $rules); $string = trim($string); $string = strtolower($string); @@ -310,12 +125,12 @@ public static function standardize(string $string, string $separator = '_'): str */ public static function toArray(string $string, string $delimiter = ','): array { - $array_temp = explode($delimiter, $string); + $arrayTemp = explode($delimiter, $string); $array = []; - foreach ($array_temp as $item) { - $item_clear = trim($item); - if ($item_clear) { - $array[] = $item_clear; + foreach ($arrayTemp as $item) { + $itemClear = trim($item); + if ($itemClear) { + $array[] = $itemClear; } } diff --git a/src/UrlHelper.php b/src/UrlHelper.php index e56c35a..1308e53 100644 --- a/src/UrlHelper.php +++ b/src/UrlHelper.php @@ -22,14 +22,14 @@ class UrlHelper { /** * @param string $url - * @param string $public_path + * @param string $publicPath * * @return string */ - public static function toPath(string $url, string $public_path): string + public static function toPath(string $url, string $publicPath): string { - $unix_public = rtrim(str_replace('\\', '/', $public_path), '\\/') . '/'; + $unixPublic = rtrim(str_replace('\\', '/', $publicPath), '\\/') . '/'; - return $unix_public . ltrim($url, '/'); + return $unixPublic . ltrim($url, '/'); } } diff --git a/tests/src/StringHelperTest.php b/tests/src/StringHelperTest.php index e93aceb..e641fb9 100644 --- a/tests/src/StringHelperTest.php +++ b/tests/src/StringHelperTest.php @@ -45,26 +45,26 @@ public function testCutWords() public function testTransliterate() { self::assertEquals( - 'ochen prostoj primer', - StringHelper::transliterate('очень простой пример') + 'ochenʹ prostoy primer', + StringHelper::transliterate('очень простой пример', StringHelper::RUSSIAN_RULES) ); self::assertEquals( 'velmi jednoduchy priklad', - StringHelper::transliterate('velmi jednoduchý příklad') + StringHelper::transliterate('velmi jednoduchý příklad', 'Latin-ASCII') ); } public function testStandardize() { self::assertEquals( - 'ochen-prostoj-primer', - StringHelper::standardize('очень простой Пример', '-') + 'ochen-prostoy-primer', + StringHelper::standardize('очень простой Пример', StringHelper::RUSSIAN_RULES, '-') ); self::assertEquals( 'velmi_jednoduchy_priklad', - StringHelper::standardize(' Velmi:;+ Jednoduchý___příklad ') + StringHelper::standardize(' Velmi:;+ Jednoduchý___příklad ', 'Latin-ASCII') ); } From cf717bd13ba8212afd6700592e07cfe37deb50e4 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sat, 1 Sep 2018 15:29:46 +0700 Subject: [PATCH 3/3] Added examples for snake_case <-> CamelCase string converting. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index c8b0682..a60503b 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,10 @@ echo StringHelper::standardize('очень простой Пример', 'Russi echo StringHelper::standardize('очень простой Пример', 'Russian-Latin/BGN', '-'); // Prints 'ochen-prostoj-primer', use '-' for slugify string var_dump(StringHelper::toArray('1,2,3,')); // Prints Array ['1', '2', '3'], ',' is default separator + +echo StringHelper::snakecaseToCamelcase('snake_case'); // Prints 'SnakeCase' +echo StringHelper::snakecaseToCamelcase('snake_case', true); // Prints 'snakeCase' +echo StringHelper::camelcaseToSnakecase('CamelCase'); // Prints 'camel_case' ``` ### UrlHelper