I propose to add class StringObject. Then it will be possible to manipulate strings in object-oriented style:
$baseWord = newStringObject('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
{
publicstaticfunctioncreateObject(string$string, string$encoding = null): StringObject
{
returnnewStringObject($string, $encoding);
}
publicstaticfunctionwordsCount(string$string, string$encoding = null): int
{
returnstatic::createObject($string, $encoding)->wordsCount();
}
}
I propose to add class
StringObject. Then it will be possible to manipulate strings in object-oriented style:Then we can make class
StringHelpera wrapper over classStringObject. For example: