/** * Create a directory structure with an anamorphism an insert it in place of * this directory. * * This is for INTERNAL use, use unfold($start_value)->with($unfolder) instead. * * @param \Closure $unfolder * @param mixed $start_value * @throws \LogicException When generated root node is a file. * @return null */ public function insertByAna(\Closure $unfolder, $start_value) { $insert = FixedFDirectory::ana($unfolder, $start_value); if ($insert->isFile()) { throw new \LogicException("Expected generated root node to be a directory, not a file."); } $inserter = array(); $inserter[0] = function ($path, FixedFDirectory $directory) use(&$inserter) { foreach ($directory->contents() as $content) { $new_path = $path . "/" . $content->name(); if ($content->isFile()) { $this->filesystem()->write($new_path, $content->content()); } else { $this->filesystem()->createDir($new_path); $inserter[0]($new_path, $content); } } }; $inserter[0]($this->path(), $insert); }