/** * @covers Kotchasan\File::makeDirectory * @todo Implement testMakeDirectory(). */ public function testFile() { $this->object->makeDirectory('temp/'); $this->object->makeDirectory('temp/test/'); $f = fopen('temp/test/index.php', 'w'); fclose($f); $this->object->copyDirectory('temp/test/', 'temp/'); $result = array(); $this->object->listFiles('temp/test/', $result); $this->object->removeDirectory('temp/'); $this->assertEquals(array('temp/test/index.php'), $result); }
/** * รายชื่อภาษาที่ติดตั้ง * * @return array */ public static function installedLanguage() { if (!isset(self::$installed_languages)) { $language_folder = self::languageFolder(); $files = array(); \File::listFiles($language_folder, $files); foreach ($files as $file) { if (preg_match('/(.*\\/([a-z]{2,2}))\\.(php|js)/', $file, $match)) { self::$installed_languages[$match[2]] = $match[2]; } } } return self::$installed_languages; }
/** * Create a new file by copying the contents of an existing * file into this directory under the given name. Unlike the * link() method, this creates a separate file. Returns the * directory entry. * * @param File $source source file to copy * @param string $name destination file name * * @return DirectoryEntry created DirectoryEntry object */ public function copy(File $source, $name, $description = '') { // Copy single file? if ($source->storage_id != '') { $new_entry = $this->createFile($name, $description); $new_file = $new_entry->file; // copy contents $source_fp = $source->open('rb'); $dest_fp = $new_file->open('wb'); stream_copy_to_stream($source_fp, $dest_fp); fclose($dest_fp); fclose($source_fp); // copy attributes $new_file->filename = $source->filename; $new_file->restricted = $source->restricted; $new_file->mime_type = $source->mime_type; $new_file->size = $source->size; $new_file->update(); return $new_entry; } //COPY directory $newFolder = $this->mkdir($name, $description); // Todo: This probably could be more sormy $folder = StudipDirectory::get($newFolder->file_id); $folder->filename = $newFolder->name; $folder->store(); foreach ($source->listFiles() as $entry) { $folder->copy($entry->file, $entry->name, $entry->description); } return $folder; }