This component is designed to ease string handling.
// Output: This is the Contact page.
$this->stringParser->recursiveReplaceTokensAndTags('This is the ##page_title## page.', ['page_title' => 'Contact']);
use Codefog\HasteBundle\StringParser;
// Output: This is the page.
$this->stringParser->convertToText('<p>This is the {{page::title}} page.</p>', StringParser::NO_TAGS & StringParser::NO_INSERTTAGS);
This is most useful for converting values to simple tokens. Simple tokens can only handle string values and have special support for if/else constructs.
Example with an indexed array:
$value = ['foo', 'bar'];
$data = [];
$this->stringParser->flatten($value, 'prefix', $data);
// Result
$data = [
'prefix_foo' => '1',
'prefix_bar' => '1',
'prefix' => 'foo, bar',
];
Example with an associative array:
$value = ['foo' => 'bar'];
$data = [];
$this->stringParser->flatten($value, 'prefix', $data);
// Result
$data = [
'prefix_foo' => 'bar',
'prefix' => '',
];