sweetchuck/robo-string

Exposes string manipulation methods from the symfony/string package

2.x-dev 2023-12-29 11:09 UTC

This package is auto-updated.

Last update: 2024-04-29 12:04:10 UTC


README

CircleCI codecov

This Robo task is useful when you need to do string manipulation in a \Robo\State\Data.

Install

composer require sweetchuck/robo-string

Task - taskStringUnicode()

<?php

declare(strict_types = 1);

use Robo\Tasks;
use Robo\State\Data as StateData;
use Sweetchuck\Robo\String\StringTaskLoader;

class RoboFileExample extends Tasks
{
    use StringTaskLoader;

    /**
     * @command string:simple
     */
    public function cmdStringSimpleExecute(string $string = 'Hello', string $suffix = 'World')
    {
        return $this
            ->collectionBuilder()
            ->addTask(
                $this
                    ->taskStringUnicode()
                    ->setString($string)
                    ->callIsEmpty()
                    ->callAppend(" $suffix")
                    ->callSnake()
            )
            ->addCode(function (StateData $data): int {
                $output = $this->output();
                $output->writeln('Is empty: ' . var_export($data['string.isEmpty'], true));
                $output->writeln("Snake: {$data['string.snake']}");
                $output->writeln("Result: {$data['string']}");

                return 0;
            });
    }
}

Run vendor/bin/robo string:simple
Output:

Is empty: false
Snake: hello_world
Result: hello_world