Skip to content

[enh] Proposal to add class StringObject #6

Description

@rugabarbo

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions