for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace nebula\route;
use Iterator;
use ArrayIterator;
use IteratorAggregate;
/**
* 路由集合
*
*/
class RouteCollection implements IteratorAggregate
{
* 属性
* @var RouteMatcher[]
protected $collection = [];
* 创建集合
* @param RouteMatcher[] $collection
public function __construct(array $collection=[])
$this->merge($collection);
}
* 合并集合
* @param array $collection
* @return void
public function merge(array $collection=[])
$this->collection = array_merge($this->collection, $collection);
* 添加集合
* @param string $name
* @param RouteMatcher $collection
public function add(string $name, RouteMatcher $collection)
$this->collection[$name] = $collection;
* 获取集合
* @return RouteMatcher|null
public function get(string $name):?RouteMatcher
return $this->collection[$name] ?? null;
* 获取迭代器
* @return RouteMatcher[]
public function getCollection():array
return $this->collection;
* 从文件创建
* @param string $path
public static function fromFile(string $path)
$collection = \unserialize(\file_get_contents($path));
return new static($collection);
return new static($collection)
nebula\route\RouteCollection
void
* 保存到文件
* @return boolean
public function save(string $path):bool
return \file_put_contents($path, \serialize($this->collection));
return file_put_contents...ize($this->collection))
integer
boolean
public function getIterator():Iterator
return new ArrayIterator($this->collection);