public function match($url) { /* Unfinished shit */ $url = trim($url, '/'); $regex = Regex::of('#:([\\w]+)#'); $path = $regex->with($this->path)->replaceWithCallback(function (Regex $self) { return '([^/]+)'; }); $reg = Regex::of("#^" . $path . "\$#i"); foreach ($reg->with($url) as $match) { var_dump($match); } return false; }
--TEST-- Basic regex test - object.replace (+first) --FILE-- <?php use php\util\Regex; use php\util\RegexException; $regex = Regex::of('([0-9]+)'); var_dump($regex->with('1 2 3')->replace('|$1|')); var_dump($regex->with('1 2 3')->replaceFirst('|$1|')); $tmp = $regex->with('1 2 3'); var_dump($tmp->replaceWithCallback(function (Regex $r) use($tmp) { if ($tmp !== $r) { throw new Exception(); } return '|$1|'; })); ?> --EXPECT-- string(11) "|1| |2| |3|" string(7) "|1| 2 3" string(11) "|1| |2| |3|"
--TEST-- Basic regex test - object.matches --FILE-- <?php use php\util\Regex; use php\util\RegexException; $regex = Regex::of('[0-9]+'); var_dump($regex->with('100500')->matches()); var_dump($regex->with(' 100500 ')->matches()); var_dump($regex->with('a100500')->matches()); ?> --EXPECT-- bool(true) bool(false) bool(false)
--TEST-- Basic regex test - object.reset --FILE-- <?php use php\util\Regex; $regex = Regex::of('[0-9]+')->with('1 2 3'); var_dump($regex->matches()); $regex->reset('123'); var_dump($regex->matches()); ?> --EXPECT-- bool(false) bool(true)