/** * Deletes all the files and directories in a directory, recursively. * * @param \FilesystemIterator $directoryItem The Filesystem directory we'll be deleting from */ private function deleteDirContent($directoryItem) { $items = new \FilesystemIterator($directoryItem->getPathname()); foreach ($items as $item) { if ($item->isDir()) { $this->deleteDirContent($item); rmdir($item->getPathname()); } else { unlink($item->getPathname()); } } }
/** * Function to handle the "/particlesystems/" REST-GET call to get all * particle systems. * * It looks for all existing particle systems on the file-system and * returns them all in JSON-format. * The JSON will be an JSON-object, containing an JSON-object "particleSystems", * which contains an array of all particle systems in JSON. * * @return string - The JSON answer. */ function get_particlesystems() { if (!file_exists("particle/")) { return '{"particleSystems": []}'; } $particleSystems = array(); $iterator = new FilesystemIterator("particle/", FilesystemIterator::SKIP_DOTS); while ($iterator->valid()) { $file = fopen($iterator->getPathname(), "r"); $content = fread($file, filesize($iterator->getPathname())); fclose($file); array_push($particleSystems, $content); $iterator->next(); } return '{"particleSystems":' . "[" . implode(",", $particleSystems) . "]" . "}"; }