public function testGetById() { $a = $this->makeResolver('a'); $list = new ResolverList([$a]); $this->assertSame($a, $list->getById('a')); $this->assertNull($list->getById('not in list')); }
public function resolve(ResolverList $resolved, ResolverList $unresolved, $performResolution = true) { // already resolved if ($resolved->contains($this)) { return true; } if ($unresolved->contains($this)) { throw new CircularDependencyException($unresolved, $this); } // add to unresolved list whilst we sort out dependencies $unresolved[] = $this; foreach ($this->depends as $dependency) { $dependency->resolve($resolved, $unresolved, $performResolution); } // all dependencies resolved so we can execute our code $unresolved->remove($this); if ($performResolution) { // pre resolve callback if (isset($this->options['PRE_RESOLVE'])) { call_user_func($this->options['PRE_RESOLVE']); } $output = call_user_func($this->resolve); // post resolution callback if (isset($this->options['POST_RESOLVE'])) { call_user_func($this->options['POST_RESOLVE']); } } $resolved[] = $this; return $output; }
public function setSqlDepends(ResolverList $list, $throwExceptionIfDependNotInList = true) { foreach ($this->getSqlDepends() as $_depend) { if ($depend = $list->getById($_depend)) { $this->addDependency($depend); } elseif ($throwExceptionIfDependNotInList) { throw new DependencyMissingException($_depend, $this, $list); } } }
/** * Resolve a entire assets directory * @return ResolverList */ public function resolveByDirs(array $dirs, ResolverList $assets, ResolverList $resolved) { // apply all obs to the database $resolveByDirs = new DependencyResolver("resolveByDirs-" . json_encode($dirs), function () use($dirs, $assets) { return true; printf("Resolved assets in directories\n%s\n", json_encode($dirs, JSON_PRETTY_PRINT)); }); // add all our resources as the database build setup foreach ($this->getSqlAssetsFromDirs1($dirs) as $file) { // print_r( $file ); $name = substr($file->getBasename(), 0, -4); if ($assets->containsId($name)) { $resolveByDirs->addDependency($assets->getById($name)); } } $resolveByDirs->resolve($resolved, new ResolverList(), true); return $resolved; }