/** * @param $name * @param array $properties * @param string $prefix * @return \CatLab\Validator\Models\Model */ public static function make($name, array $properties, $prefix = null) { $model = new self($name); if ($prefix) { $model->setPrefix($prefix); } $model->processProperties($properties); return $model; }
/** * Adds a route in the tree. * * @param DumperRoute $route * The route * * @return DumperPrefixCollection The node the route was added to * * @throws \LogicException */ public function addPrefixRoute(DumperRoute $route) { $prefix = $route->getRoute()->compile()->getStaticPrefix(); for ($collection = $this; null !== $collection; $collection = $collection->getParent()) { // Same prefix, add to current leave if ($collection->prefix === $prefix) { $collection->add($route); return $collection; } // Prefix starts with route's prefix if ('' === $collection->prefix || 0 === strpos($prefix, $collection->prefix)) { $child = new self(); $child->setPrefix(substr($prefix, 0, strlen($collection->prefix) + 1)); $collection->add($child); return $child->addPrefixRoute($route); } } // Reached only if the root has a non empty prefix throw new \LogicException('The collection root must not have a prefix'); }
/** * 返回当前对象的实例,一般用于子查询实例化model * @param string $prefix 表名前缀 * @return self */ public static function sub($prefix = '') { $self = new self(); $self->setPrefix($prefix); return $self; }
/** * Allows to create group of Routes, with defined name and path prefix. * @param string $name Name prefix applied for all routes. * @param string $path Path prefix applied for all routes. * @param Closure $callback Closure callback, which is called to create new collection. * Passed argument is new RouteCOllection object You should * use to add new Routes. * @return self */ public function group($name, $path, Closure $callback) { if ($this->isCompiled()) { throw new RuntimeException('Cannot add new routes when Collection is compiled.'); } $collection = new self(); $collection->setPrefix($name, $path); $callback($collection); $this->mergeWith($collection); return $this; }