Separate text filter decorators.

This commit is contained in:
kplaczek
2019-03-01 07:58:22 +01:00
parent ba3f2e954a
commit 246f410953
16 changed files with 357 additions and 109 deletions

View File

@@ -0,0 +1,33 @@
<?php
/**
* Created by PhpStorm.
* User: k
* Date: 28.02.2019
* Time: 21:28
*/
namespace App\Decorators;
class RandomNumberDecorator extends TextConverterDecorator
{
/**
* przeszukiwanie tekstu pod katem zawartości [ liczba, liczba2 ] i zamienianiu tego na randomową liczbę z przedziału
* liczba - liczba2
* obojętnie czy ujemną czy nie
*/
public function getText(): string
{
$text = $this->text->getText();
$re = '/\[\s*(-?\d+)\s*\,\s*(-?\d+)\s*\]/';
preg_match_all($re, $text, $matches, PREG_SET_ORDER, 0);
foreach ($matches as $match) {
$pos = strpos($text, $match[0]);
$text = substr_replace($text, mt_rand($match[1], $match[2]), $pos, strlen($match[0]));
}
return $text;
}
}