/**
  * Make directory:
  * - Make directory and sub directory
  * 
  * @param string $directory Path of directory
  * @param int $mode Define chmod of path directory
  * @return bool Info if create the folder
  */
 public function make(string $directory, int $mode = null)
 {
     if (!empty($directory)) {
         if ($folders = explode(DIRECTORY_SEPARATOR, Path::replaceOSSeparator($directory))) {
             $fullpath = null;
             if (empty($mode)) {
                 $mode = 0777;
             }
             foreach ($folders as $folder) {
                 if (!empty($folder)) {
                     $fullpath .= DIRECTORY_SEPARATOR . $folder;
                     $this->createDirectory($fullpath, $mode);
                 }
             }
         }
     }
     return file_exists($directory);
 }
 /**
  * Delete directory:
  * - Delete directory and sub directory
  * 
  * @param string $directory Path of directory
  * @return bool Info if delete directory
  */
 public final function rm(string $directory)
 {
     if (is_dir($directory)) {
         foreach (new DirectoryIterator(Path::replaceOSSeparator($directory)) as $fileInfo) {
             if (!$fileInfo->isDot()) {
                 if ($fileInfo->isDir()) {
                     $this->rm($fileInfo->getPathname());
                     @rmdir($fileInfo->getPathname());
                 } else {
                     if ($fileInfo->isFile()) {
                         @unlink($fileInfo->getPathname());
                     }
                 }
             }
         }
         @rmdir($directory);
     }
     return file_exists($directory);
 }
Esempio n. 3
0
 /**
  * Load package:
  * - Identify and load package language;
  * 
  * @param string $package Package of language
  * @return stdClass Return package of language
  */
 private static function loadPackage(string $package)
 {
     $language = null;
     if (!empty($package)) {
         $filename = null;
         if ($packageData = explode(":", $package)) {
             if (!empty($packageData[0])) {
                 $filename .= Lang::$root[$packageData[0]];
             }
             if (!empty($packageData[1])) {
                 $filename .= DIRECTORY_SEPARATOR . $packageData[1];
             }
             $pathaname = Lang::selectPackage($filename);
             if (file_exists($pathaname)) {
                 $pathaname = Path::replaceOSSeparator($pathaname);
                 $decode = json_decode(file_get_contents((new SplFileObject($pathaname, "r"))->getPathname()));
                 $language = JSON_ERROR_NONE == json_last_error() ? $decode : null;
             }
         }
     }
     return $language;
 }