Ejemplo n.º 1
0
 function testProps()
 {
     $storage_test_root = "/test/storage_dir/";
     StorageFactory::setStorageRoot($storage_test_root);
     $test_file = new File("/test/FilePropsTest.php");
     $this->assertFalse($test_file->hasAttachedStorage(), "Il file ha delle proprieta' con lo storage vuoto!!");
     $storage = $test_file->getAttachedStorage();
     $storage->add(array("test" => array("hello" => 1, "world" => "good")));
     $this->assertTrue($test_file->hasAttachedStorage(), "Il file storage delle proprieta' non e' stato creato!!");
     $sum = md5("/test/");
     //path is calculated using the parent dir
     $store_subdir = "_" . substr($sum, 0, 1);
     $storage_test_root_dir = new Dir($storage_test_root);
     $real_store_dir = $storage_test_root_dir->getUniqueSubdir();
     $r = $real_store_dir->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $props_file_dir = $r[1][0];
     $this->assertEquals($props_file_dir->getName(), $store_subdir, "La directory creata non corrisponde!!");
     $final_stored_path = new File($real_store_dir->getPath() . $props_file_dir->getName() . DS . md5("FilePropsTest.php") . ".ini");
     $this->assertTrue($final_stored_path->exists(), "Il file finale delle props non e' stato trovato!!");
     $test_file->deleteAttachedStorage();
     $this->assertFalse($test_file->hasAttachedStorage(), "Il file delle proprieta' non e' stato eliminato!!");
     $r = $real_store_dir->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $all_elements = array_merge($r[0], $r[1]);
     foreach ($all_elements as $f) {
         $f->delete(true);
     }
     StorageFactory::setStorageRoot(StorageFactory::getDefaultStorageRoot());
 }
Ejemplo n.º 2
0
 public function visit(Dir $dir)
 {
     $files = $dir->listFiles();
     foreach ($files as $f) {
         if ($f instanceof File && $f->getFullExtension() == "blade.php") {
             $content = $f->getContent();
             $broken_list = array();
             $matches = array();
             preg_match_all("/\\@require_local_js\\(['\"](?P<path>[^'\"]+)['\"]\\)/", $content, $matches, PREG_SET_ORDER);
             foreach ($matches as $m) {
                 if (!$this->check_path($m["path"])) {
                     $broken_list[] = $m[0];
                 }
             }
             preg_match_all("/\\@require_local_css\\(['\"](?P<path>[^'\"]+)['\"]\\)/", $content, $matches, PREG_SET_ORDER);
             foreach ($matches as $m) {
                 if (!$this->check_path($m["path"])) {
                     $broken_list[] = $m[0];
                 }
             }
             if (!empty($broken_list)) {
                 $this->has_broken_paths = true;
                 $this->info("");
                 $this->error("Broken paths inside file " . $f->getPath() . " : ");
                 foreach ($broken_list as $bk) {
                     $this->info($bk . " is broken.");
                 }
             }
         }
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $available_lang_dir = new Dir("/resources/lang/");
     if ($available_lang_dir->exists()) {
         $this->info("Available languages :");
         $this->info("");
         $folds = $available_lang_dir->listFolders();
         foreach ($folds as $f) {
             $this->info("[" . $f->getName() . "]");
         }
     } else {
         $this->warn("Localization directory " . $available_lang_dir->getPath() . " does not exists!!");
     }
     $hidden_lang_dir = new Dir("/storage/app/hidden_lang/");
     $this->info("");
     if ($hidden_lang_dir->exists()) {
         $this->info("Hidden languages :");
         $this->info("");
         $folds = $hidden_lang_dir->listFolders();
         foreach ($folds as $f) {
             $this->info("[" . $f->getName() . "]");
         }
     } else {
         $this->info("No hidden localizations found.");
     }
 }
Ejemplo n.º 4
0
 function __construct(Dir $d)
 {
     $folders = $d->listFolders();
     foreach ($folders as $fld) {
         $lang_folder = new AvailableLocale($fld);
         $this->locales[$lang_folder->getName()] = $lang_folder;
     }
 }
Ejemplo n.º 5
0
 /**
  * 
  * Recursively inflate the folder into che provided archive, using local_dir as a prefix for archived files.
  * 
  * @param ZipArchive $zip_archive the current archive
  * @param Dir $current_folder the current folder to compress
  * @param string $local_dir the local dir prefix to use for compressed files.
  * 
  * @internal
  */
 private static function recursiveZipFolder($zip_archive, $current_folder, $local_dir)
 {
     $results = $current_folder->listElements();
     $all_elements = array_merge($results[0], $results[1]);
     foreach ($all_elements as $dir_entry) {
         if ($dir_entry->isFile()) {
             $zip_archive->addFile($dir_entry->getFullPath(), $local_dir . $dir_entry->getFullName());
         } else {
             $zip_archive->addEmptyDir($local_dir . $dir_entry->getName() . DS);
             ZipUtils::recursiveZipFolder($zip_archive, $dir_entry, $local_dir . $dir_entry->getName() . DS);
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $lang = $this->getNameArgument();
     //
     $target = new Dir("/resources/lang/" . $lang);
     if ($target->exists()) {
         $hide_dir = new Dir("/storage/app/hidden_langs");
         if (!$hide_dir->exists()) {
             $this->info("Hidden languages storage dir created.");
             $hide_dir->touch();
         }
         $target->moveTo($hide_dir);
         $this->info("Language " . $lang . " hidden succesfully.");
     } else {
         $this->error("Language " . $lang . " not found.");
     }
 }
Ejemplo n.º 7
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $lang = $this->getNameArgument();
     //
     $target = new Dir("/storage/app/hidden_langs/" . $lang);
     if ($target->exists()) {
         $show_dir = new Dir("/resources/lang/");
         $target->moveTo($show_dir);
         $this->info("Language " . $lang . " reenabled succesfully.");
         $check_dir_delete_if_empty = new Dir("/storage/app/hidden_langs");
         if ($check_dir_delete_if_empty->isEmpty()) {
             $check_dir_delete_if_empty->delete();
             $this->info("Hidden languages storage dir deleted (empty).");
         }
     } else {
         $this->error("Language " . $lang . " not found.");
     }
 }
Ejemplo n.º 8
0
 function testExtractArchive()
 {
     $create_dir = new Dir("/test/zip_test/create/");
     $this->assertTrue($create_dir->exists(), "La directory create non esiste!!");
     $save_dir = new Dir("/test/zip_test/saved/");
     $this->assertTrue($save_dir->exists(), "La directory save non esiste!!");
     $extract_dir = new Dir("/test/zip_test/extract/");
     $this->assertTrue($extract_dir->exists(), "La directory extract non esiste!!");
     $r = $extract_dir->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $extract_dir_files = array_merge($r[0], $r[1]);
     foreach ($extract_dir_files as $f) {
         $f->delete(true);
     }
     $target_file = new File("/test/zip_test/saved/test_archive.zip");
     $this->assertFalse($target_file->exists());
     $dir_to_zip = "/test/zip_test/create/";
     ZipUtils::createArchive($target_file, $dir_to_zip);
     $this->assertTrue($target_file->exists(), "Il file zip non è stato creato!!");
     $this->assertTrue($target_file->getSize() > 0, "Il file creato ha dimensione vuota!!");
     //ora estraggo l'archivio
     $extract_root = "/test/zip_test/extract/";
     ZipUtils::expandArchive($target_file, $extract_root);
     $r = $extract_dir->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $all_elements = array_merge($r[0], $r[1]);
     $this->assertEquals(count($all_elements), 3, "Il numero dei file estratti non corrisponde!!");
     $f1 = new File($extract_root . "my_file_01.php");
     $this->assertTrue($f1->exists(), "Il file my_file_01.php non e' stato estratto!!");
     $this->assertTrue(!$f1->isEmpty(), "Il file my_file_01.php e' vuoto!!");
     //$d1 = new Dir($extract_root."another_dir/");
     //$d2 = new Dir($extract_root."my_subdir/");
     $f2 = new File($extract_root . "another_dir/blabla.ini");
     $this->assertTrue($f2->exists(), "Il file blabla.ini non e' stato estratto!!");
     $this->assertTrue(!$f2->isEmpty(), "Il file blabla.ini e' vuoto!!");
     $r = $save_dir->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $saved_files = array_merge($r[0], $r[1]);
     foreach ($saved_files as $f) {
         $f->delete(true);
     }
     $r = $extract_dir->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $extracted_files = array_merge($r[0], $r[1]);
     foreach ($extracted_files as $f) {
         $f->delete(true);
     }
 }
Ejemplo n.º 9
0
 /**
     @test
 */
 function testPlainDirCache()
 {
     $f = new Dir("/test/cache_test/cc/");
     $this->assertFalse($f->exists(), "La directory della cache esiste già!!");
     $cache = new FlatDirCache($f);
     $this->assertFalse($f->exists(), "La directory della cache esiste già!!");
     $cache->init();
     $this->assertTrue($f->exists(), "La directory della cache non è stata creata!!");
     $this->assertFalse($cache->has_key("prova"), "La chiave prova esiste!!");
     $cache->set("prova", "Hello!! ");
     $this->assertTrue($cache->has_key("prova"), "La chiave prova non esiste!!");
     $this->assertEquals("Hello!! ", $cache->get("prova"), "Il valore salvato non corrisponde!!");
     $this->assertFalse($cache->has_key("12345"), "La chiave 12345 esiste!!");
     $cache->set("12345", "Hello11!! ");
     $this->assertTrue($cache->has_key("12345"), "La chiave 12345 non esiste!!");
     $this->assertEquals("Hello11!! ", $cache->get("12345"), "Il valore salvato non corrisponde!!");
     $cache->set("prova", "New content for prova key");
     $this->assertTrue($cache->has_key("prova"), "La chiave prova non esiste!!");
     $this->assertEquals("New content for prova key", $cache->get("prova"), "Il valore salvato non corrisponde!!");
     $cache->delete_key("12345");
     $this->assertFalse($cache->has_key("12345"), "La chiave 12345 esiste!!");
     $this->assertTrue($cache->has_key("prova"), "La chiave prova non esiste!!");
     $cache->garbage_collect();
     $this->assertFalse($cache->has_key("12345"), "La chiave 12345 esiste!!");
     $this->assertTrue($cache->has_key("prova"), "La chiave prova non esiste!!");
     $cache->set_entry_expire_time(1);
     $this->assertEquals(1, $cache->get_entry_expire_time());
     sleep(5);
     $this->assertFalse($cache->has_key("12345"), "La chiave 12345 esiste!!");
     $this->assertFalse($cache->has_key("prova"), "La chiave prova non esiste!!");
     $cache->set_entry_expire_time(FlatDirCache::DEFAULT_ENTRY_EXPIRE_TIME);
     $cache->set("prova", "Hello!! ");
     $cache->set("12345", "Hello11!! ");
     $cache->clean_cache();
     $this->assertFalse($cache->has_key("prova"), "La chiave prova non esiste!!");
     $this->assertFalse($cache->has_key("12345"), "La chiave 12345 non esiste!!");
     try {
         $cache->get("prova");
         $this->fail();
     } catch (IOException $ex) {
     }
     try {
         $cache->get("12345");
         $this->fail();
     } catch (IOException $ex) {
     }
     $cache->set_garbage_collection_interval(5);
     $this->assertEquals(5, $cache->get_garbage_collection_interval(), "L'intervallo di garbage collection non corrisponde!!'");
     $v = "another content!\"£\$%&/()=?'ì^*é[]@#ù-_.:,;'";
     $v2 = "" . $v;
     $cache->set("newkey", $v);
     $this->assertEquals($v2, $cache->get("newkey"), "Il valore nella cache non corrisponde!!");
     $cache->delete_key("newkey");
     $this->assertFalse($cache->has_key("newkey"), "La chiave newkey non è stata eliminata!!");
     $f->delete();
     $this->assertFalse($f->exists(), "La directory della cache non è stata eliminata!!");
 }
Ejemplo n.º 10
0
 function testCreateStorageOnWrite()
 {
     StorageFactory::setStorageRoot("/test/storage_dir/");
     $d = new Dir("/test/storage_dir/");
     $r = $d->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $all_elements = array_merge($r[0], $r[1]);
     foreach ($all_elements as $f) {
         $f->delete(true);
     }
     $this->assertFalse($d->hasOnlyOneSubdir(), "Lo storage e' gia' presente!!");
     $storage = StorageFactory::getPropertiesStorage("boh", "ciccia");
     $this->assertFalse($storage->exists(), "Lo storage esiste gia'!!");
     $test_props = array("test" => "value", "hello" => "world");
     $storage->add(array("category" => $test_props));
     $this->assertTrue($storage->exists(), "Lo storage non e' stato creato!!");
     $storage->delete();
     $this->assertFalse($storage->exists(), "Lo storage non e' stato eliminato!!");
     $properties = $storage->readAll();
     //readAll
     $this->assertTrue($storage->exists(), "Lo storage non e' stato creato per una lettura!!");
     $this->assertFalse($properties === null, "Il risultato ritornato e' ===null !!");
     $this->assertTrue(is_array($properties), "Il metodo non ha ritornato un array con uno storage inesistente!!");
     $this->assertTrue(count($properties) == 0, "L'array ritornato da una lettura di storage vuoto non e' vuoto!!");
     $storage->delete();
     $storage->remove("blah");
     //remove
     $this->assertTrue($storage->exists(), "Lo storage non e' stato creato per una cancellazione!!");
     $storage->delete();
     $storage->saveAll(array());
     //saveAll
     $this->assertTrue($storage->exists(), "Lo storage non e' stato creato per una cancellazione!!");
     $storage->delete();
     $this->assertFalse($storage->exists(), "Lo storage non e' stato eliminato!!");
     $r = $d->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $all_elements = array_merge($r[0], $r[1]);
     foreach ($all_elements as $f) {
         $f->delete(true);
     }
     StorageFactory::setStorageRoot(StorageFactory::getDefaultStorageRoot());
 }
Ejemplo n.º 11
0
 /**
  * Genera le classi helper.
  * 
  * @param array $previous_folder_list L'array dei predecessori dell'elemento corrente da considerare
  * @param string $namespace Il namespace corrente
  * @param \Mbcraft\Piol\Dir $dir La directory corrente
  */
 function generateHelpers($previous_folder_list, $namespace, Dir $dir)
 {
     $previous_folder_list[] = $this;
     foreach ($this->folders as $k => $cnt) {
         $namespace_dir = GeneratorUtils::getNamespacePartFromString($k);
         $sub_dir = $dir->newDir($namespace_dir);
         $sub_dir->touch();
         $cnt->generateHelpers($previous_folder_list, GeneratorUtils::getNamespaceWith($namespace, $k), $sub_dir);
     }
     foreach ($this->files as $k => $cnt) {
         $cnt->generateHelpers($previous_folder_list, $namespace, $dir);
     }
 }
Ejemplo n.º 12
0
 function testNewTempFileNonWritableDir()
 {
     $d = new Dir("/test/tmp_dir_no_w/");
     $d->touch();
     $d->setPermissions("r--------");
     try {
         File::setTmpFileDir($d);
         $this->fail("Using a non-writable directory as temporary dir should throw an Exception.");
     } catch (IOException $ex) {
     }
     $d->delete();
 }
Ejemplo n.º 13
0
 /**
  * Genera la classe helper per la traduzione.
  * 
  * @param \Mbcraft\Piol\Dir $save_dir La directory in cui salvare la classe.
  * @param string $namespace Il namespace da utilizzare.
  * @param string $key_prefix Il prefisso da utilizzare per le chiavi.
  * @param string $class_name Il nome della classe.
  * @param array $values I valori
  */
 public static function createHelperClass($save_dir, $namespace, $class_name, $key_prefix_parts, $lang_data)
 {
     $f = $save_dir->newFile($class_name . ".php");
     $f->setContent(self::getLangFileContent($namespace, $class_name, $key_prefix_parts, $lang_data));
 }
Ejemplo n.º 14
0
 function testGetPathRelative()
 {
     $my_included_file = new Dir("/test/include_teiop/");
     //$rel_path = $my_included_file->getPath(new Dir(__DIR__));
     //$this->assertEquals("/io/include_teiop/",$rel_path,"Il percorso relativo non viene elaborato correttamente!! : ".$rel_path);
     $rel_path = $my_included_file->getPath(new Dir("/test/"));
     $this->assertEquals("/include_teiop/", $rel_path, "Il percorso relativo non viene elaborato correttamente!! : " . $rel_path);
     try {
         $this->assertEquals("/include_teiop/", $my_included_file->getPath(new Dir("/pluto/tests/io/include_test")), "Il percorso relativo non viene elaborato correttamente!!");
         $this->fail();
     } catch (IOException $ex) {
     }
 }
Ejemplo n.º 15
0
Archivo: Dir.php Proyecto: mbcraft/piol
 /**
  * 
  * Checks if this directory is a parent of the provided child.
  * 
  * @param \Mbcraft\Piol\File|\Mbcraft\Piol\Dir $child
  * @return boolean true if the parameter is a direct child of this directory, false otherwise.
  * 
  * @throws IOException if the child is not a valid File or Dir instance.
  * 
  * @api
  */
 public function isParentOf($child)
 {
     if (!$child instanceof __FileSystemElement) {
         throw new IOException("The provided element is not a valid \\Piol\\File or \\Piol\\Dir.");
     }
     $path_p = $this->getFullPath();
     $path_c = $child->getFullPath();
     //for windows dirs
     $parent_path_c = dirname($path_c) . DIRECTORY_SEPARATOR;
     $parent_path_c = str_replace("\\", DS, $parent_path_c);
     return $parent_path_c == $path_p;
 }
Ejemplo n.º 16
0
 /**
  * 
  * Construct a FlatDirCache instance, using the specified parameter as folder for data.
  * 
  * @param \Mbcraft\Piol\Dir|string $cache_dir the cache directory or string path for the cache data.
  * 
  * @api
  */
 public function __construct($cache_dir)
 {
     $this->root_dir = Dir::asDir($cache_dir);
 }
Ejemplo n.º 17
0
 /**
  * Returns the folder to use for saving generated classes.
  * 
  * @return \Mbcraft\Piol\Dir The dir instance pointing to the 
  *      generated classes folder.
  */
 public static function getGeneratedClassFolder()
 {
     $d = new Dir(self::DEFAULT_GENERATED_CLASS_FOLDER);
     $d->touch();
     return $d;
 }