AppserverIo\Appserver\Meta\Composer\Script\Setup::prepareDirectory PHP Метод

prepareDirectory() публичный статический Метод

Prepares the passed directory if necessary.
public static prepareDirectory ( string $directory, integer $mode = 509 ) : void
$directory string The directory to prepare
$mode integer The mode of the directory
Результат void
    public static function prepareDirectory($directory, $mode = 0775)
    {
        // make the passed directory OS compliant
        $toBePreapared = Setup::prepareOsSpecificPath($directory);
        // make sure the directory exists
        if (is_dir(dirname($toBePreapared)) === false) {
            mkdir(dirname($toBePreapared), $mode, true);
        }
    }

Usage Example

Пример #1
0
 /**
  * Processes the template and replace the properties with the OS specific values.
  *
  * @param string  $template The path to the template
  * @param boolean $override TRUE if the file should be overwritten if exists, else FALSE
  * @param integer $mode     The mode of the target file
  *
  * @return void
  */
 public static function processTemplate($template, $override = false, $mode = 0644)
 {
     // prepare the target filename
     $targetFile = Setup::prepareOsSpecificPath($template);
     // query whether we've to override the file
     if ($override === false && is_file($targetFile) === true) {
         return;
     }
     // prepare the target directory
     Setup::prepareDirectory($template);
     // process the template and store the result in the passed file
     ob_start();
     include Setup::prepareOsSpecificPath(sprintf('resources/templates/%s.phtml', $template));
     file_put_contents($targetFile, ob_get_clean());
     // set the correct mode for the file
     Setup::changeFilePermissions($template, $mode);
 }