$child2 = new File\Folder('data3', 'childFolder2'); echo "Success!\n"; echo " Instantiation (data4, grandchild1) -> "; $child3 = new File\Folder('data4', 'grandchild1'); echo "Success!\n"; } catch (\Exception $e) { $success = false; } if (!$success) { echo "EXCEPTION RAISED\n\n"; } echo "\nBasic Operations -- \n"; echo " Add childFolder1 to topFolder -> "; $success = true; try { $top->addFolder($child1, $child1->getIdentifier()); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n\n"; } else { echo "Failure...\n\n"; } $paths = File\Folder::getFolderIdentityPaths($top); echo "Paths: \n"; foreach ($paths as $path) { echo " {$path}\n"; } echo "\n Add grandchild1 to childFolder1 -> "; $success = true;
/** * Take an array of Folders, and create the Folders * * Each array will have a path element for the path * and then a Folders element whose entries are other * path arrays. An empty array ends the sequence * * Very recursive * * @param array $build Not an array of Folders, but as above * */ public static function buildFromArray($build = array()) { $firstKey = array_keys($build); $firstKey = $firstKey[0]; $ret = new Folder($build[$firstKey]['data'], $firstKey); foreach ($build[$firstKey]['folders'] as $key => $folder) { $ret->addFolder(Folder::buildFromArray(array($key => $folder))); } return $ret; }