Open
Description
I propose to add class StringObject
. Then it will be possible to manipulate strings in object-oriented style:
$baseWord = new StringObject('soft', 'UTF-8');
$projectName = $baseWord
->preprend('yii')
->addWord('project')
->upperCaseEveryWord();
$projectNameWordsCount = $projectName->wordsCount();
Then we can make class StringHelper
a wrapper over class StringObject
. For example:
class StringHelper
{
public static function createObject(string $string, string $encoding = null): StringObject
{
return new StringObject($string, $encoding);
}
public static function wordsCount(string $string, string $encoding = null): int
{
return static::createObject($string, $encoding)->wordsCount();
}
}
Activity