- preg_match: documentation ( source)
- sprintf: documentation ( source)
<?php
interface PatternInterface {
function match($value);
}
class LiteralPattern implements PatternInterface {
private $value;
public function match($value) {
return $value === $this->value;
}
}
class DynamicPattern implements PatternInterface {
private $name;
private $value;
public function match($value, &$matches) {
return (bool) preg_match($this->getExpression(), $value, $matches); // i can has $matches?
}
public function getExpression() {
return sprintf('/^(?<%s>%s)$/', $this->name, $this->value);
}
}