Skip to content

Commit

Permalink
Adds Str:: convertCase() (#326)
Browse files Browse the repository at this point in the history
* Adds `Str:: convertCase()`

Co-Authored-By: Deeka Wong <8337659+huangdijia@users.noreply.github.com>

* Cs Fix

Co-Authored-By: Deeka Wong <8337659+huangdijia@users.noreply.github.com>

---------

Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
  • Loading branch information
huangdijia and huangdijia authored Aug 30, 2023
1 parent 178c8cb commit 555e8de
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
2 changes: 0 additions & 2 deletions output/Hyperf/HttpServer/Contract/RequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public function boolean($key = null, $default = false): bool;

/**
* Retrieve input from the request as a collection.
*
* @param array|string|null $key
*/
public function collect(array|string|null $key = null): \Hyperf\Collection\Collection;

Expand Down
37 changes: 23 additions & 14 deletions output/Hyperf/Stringable/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ public static function classNamespace($value)
{
}

/**
* Convert the case of a string.
*
* @return string
*/
public static function convertCase(string $string, int $mode = MB_CASE_FOLD, ?string $encoding = 'UTF-8')
{
}

/**
* Set the callable that will be used to generate UUIDs.
*/
public static function createUuidsUsing(callable $factory = null)
{
}

/**
* Indicate that UUIDs should be created normally and not using a custom factory.
*/
public static function createUuidsNormally()
{
}

/**
* Extracts an excerpt from text that matches the first instance of a phrase.
*
Expand Down Expand Up @@ -207,20 +230,6 @@ public static function transliterate($string, $unknown = '?', $strict = false)
{
}

/**
* Set the callable that will be used to generate UUIDs.
*/
public static function createUuidsUsing(callable $factory = null)
{
}

/**
* Indicate that UUIDs should be created normally and not using a custom factory.
*/
public static function createUuidsNormally()
{
}

/**
* Split a string into pieces by uppercase characters.
*
Expand Down
11 changes: 11 additions & 0 deletions output/Hyperf/Stringable/Stringable.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ public function classNamespace()
{
}

/**
* Convert the case of a string.
*
* @param int $mode
* @param string $encoding
* @return static
*/
public function convertCase($mode = MB_CASE_FOLD, $encoding = 'UTF-8')
{
}

/**
* Extracts an excerpt from text that matches the first instance of a phrase.
*
Expand Down
10 changes: 10 additions & 0 deletions src/StrMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public function classNamespace()
};
}

/**
* Convert the case of a string.
*
* @return string
*/
public static function convertCase()
{
return fn (string $string, int $mode = MB_CASE_FOLD, ?string $encoding = 'UTF-8') => mb_convert_case($string, $mode, $encoding);
}

public function createUuidsNormally()
{
return fn () => UuidContainer::$uuidFactory = null;
Expand Down
6 changes: 6 additions & 0 deletions src/StringableMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public function classNamespace()
return fn () => new static(Str::classNamespace($this->value));
}

public function convertCase()
{
/* @phpstan-ignore-next-line */
return fn ($mode = MB_CASE_FOLD, $encoding = 'UTF-8') => new static(Str::convertCase($this->value, $mode, $encoding));
}

public function excerpt()
{
/* @phpstan-ignore-next-line */
Expand Down

0 comments on commit 555e8de

Please sign in to comment.