for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Bavix\Router;
class Pattern
{
/**
* if methods === null -> full methods
*
* @var null|array
*/
protected $methods;
* @var array
protected $defaults = [];
* @var string
protected $name;
protected $path;
* Pattern constructor.
* @param string $path
* @param string $name
public function __construct(string $path, ?string $name)
$this->path = $path;
$this->name = $name;
}
* @return string
public function getName(): string
return $this->name ?: $this->generateName();
* @return $this
public function setName(string $name): self
return $this;
* @return array|null
public function getMethods(): ?array
return $this->methods;
* @param array|null $methods
public function setMethods(?array $methods): self
$this->methods = $methods;
* @return array
public function getDefaults(): array
return $this->defaults;
* @param array $defaults
public function setDefaults(array $defaults): self
$this->defaults = $defaults;
public function getPath(): string
return $this->path;
public function setPath(string $path): self
public function toArray(): array
return [
$this->getName() => [
'type' => 'pattern',
'path' => $this->getPath(),
'methods' => $this->getMethods(),
'defaults' => $this->getDefaults(),
]
];
protected function generateName(): string
return \preg_replace('~[^\w-]~', '_', $this->path);