Skip to content

Commit

Permalink
[+]: re-sync with original "Stringy"
Browse files Browse the repository at this point in the history
- rename "slugify()" into "urlify()"
- re-add original "slugify()" method
- rename "toAscii()" into "toTransliterate()"
- re-add toAscii "slugify()" method
- apply php-cs fixes rules
  • Loading branch information
voku committed Jan 11, 2019
1 parent 8af890a commit b7c6498
Show file tree
Hide file tree
Showing 13 changed files with 10,400 additions and 6,772 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### 5.0.0 (2019-01-11)
- rename "slugify()" into "urlify()"
- re-add original "slugify()" method
- rename "toAscii()" into "toTransliterate()"
- re-add toAscii "slugify()" method
- apply php-cs fixes rules


### 4.1.2 (2018-11-29)
- fix error from "UTF8::remove_html()" with strict types

Expand Down
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
WARNING: this is only a extened Fork of "https://github.com/danielstjules/Stringy"

[![Build Status](https://api.travis-ci.org/voku/Stringy.svg?branch=master)](https://travis-ci.org/voku/Stringy)
[![codecov.io](https://codecov.io/github/voku/Stringy/coverage.svg?branch=master)](https://codecov.io/github/voku/Stringy?branch=master)
[![Codacy Badge](https://api.codacy.com/project/badge/grade/97c46467e585467d884bac1130cb45e5)](https://www.codacy.com/app/voku/Stringy)
[![Latest Stable Version](https://poser.pugx.org/voku/stringy/v/stable)](https://packagist.org/packages/voku/stringy)
[![Total Downloads](https://poser.pugx.org/voku/stringy/downloads)](https://packagist.org/packages/voku/stringy)
[![License](https://poser.pugx.org/voku/stringy/license)](https://packagist.org/packages/voku/stringy)
[![Donate to this project using Paypal](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.me/moelleken)
[![Donate to this project using Patreon](https://img.shields.io/badge/patreon-donate-yellow.svg)](https://www.patreon.com/voku)

## :accept: Stringy

A PHP string manipulation library with multibyte support. Compatible with PHP 7+

100% compatible with the original "[Stringy](https://github.com/danielstjules/Stringy)" library, but this fork is optimized
for performance and is using PHP 7+ features.

``` php
s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
```
Expand Down Expand Up @@ -168,7 +171,7 @@ in your composer.json file:

```json
"require": {
"voku/stringy": "~4.0"
"voku/stringy": "~5.0"
}
```

Expand Down Expand Up @@ -1292,6 +1295,22 @@ Advanced substring methods

From the project directory, tests can be ran using `phpunit`

## Support

For support and donations please visit [Github](https://github.com/voku/Stringy/) | [Issues](https://github.com/voku/Stringy/issues) | [PayPal](https://paypal.me/moelleken) | [Patreon](https://www.patreon.com/voku).

For status updates and release announcements please visit [Releases](https://github.com/voku/Stringy/releases) | [Twitter](https://twitter.com/suckup_de) | [Patreon](https://www.patreon.com/voku/posts).

For professional support please contact [me](https://about.me/voku).

## Thanks

- Thanks to [GitHub](https://github.com) (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
- Thanks to [IntelliJ](https://www.jetbrains.com) as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
- Thanks to [Travis CI](https://travis-ci.com/) for being the most awesome, easiest continous integration tool out there!
- Thanks to [StyleCI](https://styleci.io/) for the simple but powerfull code style check.
- Thanks to [PHPStan](https://github.com/phpstan/phpstan) && [Psalm](https://github.com/vimeo/psalm) for relly great Static analysis tools and for discover bugs in the code!

## License

Released under the MIT License - see `LICENSE.txt` for details.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
],
"require": {
"php": ">=7.0.0",
"voku/portable-utf8": "~5.1",
"voku/portable-utf8": "~5.3.3",
"voku/urlify": "~4.0",
"voku/anti-xss": "~4.0",
"voku/anti-xss": "~4.1",
"voku/email-check": "~3.0"
},
"require-dev": {
"phpunit/phpunit": "~6.0|~7.0"
"phpunit/phpunit": "~6.0 || ~7.0"
},
"support": {
"issues": "https://github.com/voku/Stringy/issues",
Expand Down
238 changes: 238 additions & 0 deletions phpcs.php_cs

Large diffs are not rendered by default.

31 changes: 16 additions & 15 deletions src/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

namespace Stringy;

if (!function_exists('Stringy\create')) {
/**
* Creates a Stringy object and returns it on success.
*
* @param mixed $str Value to modify, after being cast to string
* @param string $encoding The character encoding
*
* @return Stringy A Stringy object
* @throws \InvalidArgumentException if an array or object without a
* __toString method is passed as the first argument
*/
function create($str, string $encoding = null)
{
return new Stringy($str, $encoding);
}
if (!\function_exists('Stringy\create')) {
/**
* Creates a Stringy object and returns it on success.
*
* @param mixed $str Value to modify, after being cast to string
* @param string $encoding The character encoding
*
* @throws \InvalidArgumentException if an array or object without a
* __toString method is passed as the first argument
*
* @return Stringy A Stringy object
*/
function create($str, string $encoding = null)
{
return new Stringy($str, $encoding);
}
}
96 changes: 47 additions & 49 deletions src/StaticStringy.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,63 +106,61 @@
* @method static Stringy underscored(string $stringInput, string $encoding = null)
* @method static Stringy upperCamelize(string $stringInput, string $encoding = null)
* @method static Stringy upperCaseFirst(string $stringInput, string $encoding = null)
*
* @package Stringy
*/
class StaticStringy
{
/**
* A mapping of method names to the numbers of arguments it accepts. Each
* should be two more than the equivalent Stringy method. Necessary as
* static methods place the optional $encoding as the last parameter.
*
* @var string[]
*/
protected static $methodArgs = null;
/**
* A mapping of method names to the numbers of arguments it accepts. Each
* should be two more than the equivalent Stringy method. Necessary as
* static methods place the optional $encoding as the last parameter.
*
* @var string[]
*/
protected static $methodArgs = null;

/**
* Creates an instance of Stringy and invokes the given method with the
* rest of the passed arguments. The optional encoding is expected to be
* the last argument. For example, the following:
* StaticStringy::slice('fòôbàř', 0, 3, 'UTF-8'); translates to
* Stringy::create('fòôbàř', 'UTF-8')->slice(0, 3);
* The result is not cast, so the return value may be of type Stringy,
* integer, boolean, etc.
*
* @param string $name
* @param mixed[] $arguments
*
* @return Stringy
*/
public static function __callStatic($name, array $arguments)
{
if (!static::$methodArgs) {
$stringyClass = new \ReflectionClass(Stringy::class);
$methods = $stringyClass->getMethods(\ReflectionMethod::IS_PUBLIC);
/**
* Creates an instance of Stringy and invokes the given method with the
* rest of the passed arguments. The optional encoding is expected to be
* the last argument. For example, the following:
* StaticStringy::slice('fòôbàř', 0, 3, 'UTF-8'); translates to
* Stringy::create('fòôbàř', 'UTF-8')->slice(0, 3);
* The result is not cast, so the return value may be of type Stringy,
* integer, boolean, etc.
*
* @param string $name
* @param mixed[] $arguments
*
* @return Stringy
*/
public static function __callStatic($name, array $arguments)
{
if (!static::$methodArgs) {
$stringyClass = new \ReflectionClass(Stringy::class);
$methods = $stringyClass->getMethods(\ReflectionMethod::IS_PUBLIC);

foreach ($methods as $method) {
$params = $method->getNumberOfParameters() + 2;
static::$methodArgs[$method->name] = $params;
}
}
foreach ($methods as $method) {
$params = $method->getNumberOfParameters() + 2;
static::$methodArgs[$method->name] = $params;
}
}

if (!isset(static::$methodArgs[$name])) {
throw new \BadMethodCallException($name . ' is not a valid method');
}
if (!isset(static::$methodArgs[$name])) {
throw new \BadMethodCallException($name . ' is not a valid method');
}

$numArgs = \count($arguments);
$str = ($numArgs) ? $arguments[0] : '';
$numArgs = \count($arguments);
$str = ($numArgs) ? $arguments[0] : '';

if ($numArgs === static::$methodArgs[$name]) {
$args = \array_slice($arguments, 1, -1);
$encoding = $arguments[$numArgs - 1];
} else {
$args = \array_slice($arguments, 1);
$encoding = null;
}
if ($numArgs === static::$methodArgs[$name]) {
$args = \array_slice($arguments, 1, -1);
$encoding = $arguments[$numArgs - 1];
} else {
$args = \array_slice($arguments, 1);
$encoding = null;
}

$stringy = Stringy::create($str, $encoding);
$stringy = Stringy::create($str, $encoding);

return \call_user_func_array(array($stringy, $name), $args);
}
return \call_user_func_array([$stringy, $name], $args);
}
}
Loading

0 comments on commit b7c6498

Please sign in to comment.