/** * Change the working directory. * * @param string $path * @param \Closure $callback * @return \Basset\Collection|\Basset\Directory */ public function directory($path, Closure $callback = null) { try { $path = $this->finder->setWorkingDirectory($path); $this->directories[$path] = new Directory($this->factory, $this->finder, $path); // Once we've set the working directory we'll fire the callback so that any added assets // are relative to the working directory. After the callback we can revert the working // directory. is_callable($callback) and call_user_func($callback, $this->directories[$path]); $this->finder->resetWorkingDirectory(); return $this->directories[$path]; } catch (DirectoryNotFoundException $e) { $this->getLogger()->error(sprintf('Directory "%s" could not be found in "%s"', $path, $this->path)); return new Directory($this->factory, $this->finder, null); } }
/** * Prepare the default directory for a new collection. * * @return \Basset\Directory */ protected function prepareDefaultDirectory() { $path = $this->finder->setWorkingDirectory('/'); return new Directory($this->factory, $this->finder, $path); }