for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Bavix\Router;
abstract class Rule
{
use Attachable;
/**
* @var null|string
*/
protected $type;
* @var null|Path
protected $path;
* @var array
protected $methods;
protected $defaults;
* Rule constructor.
*
* @param string $key
* @param array $storage
* @param null|self $parent
public function __construct(string $key, array $storage, ?self $parent = null)
$this->prepare();
$this->initializer($key, $storage);
$this->pathInit();
if ($parent) {
$this->afterPrepare($parent);
}
* @param Path|null $path
protected function hinge(?Path $path): void
if ($this->path && $path) {
$this->path->hinge($path);
return;
$this->path = $path ?? $this->path;
* @param self $parent
* @return void
protected function afterPrepare(self $parent): void
$this->hinge($parent->path);
$this->_key = $parent->_key . '.' . $this->_key;
$this->methods = $this->methods ?? $parent->methods;
$this->defaults = \array_merge(
(array)$parent->defaults,
(array)$this->defaults
);
* if this.path === string then new Path(string, [])
* else this.path === array then new Path(...this.path)
protected function pathInit(): void
if (\is_string($this->path)) {
is_string($this->path)
false
$this->path = new Path($this->path);
} elseif (\is_array($this->path)) {
is_array($this->path)
$this->path = new Path(...$this->path);
protected function prepare(): void
// todo: a lot of logic