Ensures that the sub-directories of a directory exist.

@param string      $directory The directory.
@param Config|null $config    Optionl configuration.

@return bool True on success, false on failure.
335836
protected function ensureSubDirs($directory, Config $config = null)
    {
        $config = $config ?: new Config();

        return $this->createDir(Util::dirname($directory), $config);
    }
963119
public static function config($config = null)
	{
		if(is_array($config)) {

            # Setting Configurations
			static::$config = $config + static::$config;
			$pathWithoutTrailingSlash = rtrim(static::$config['directory'], '/');
			static::$config['directory'] = $pathWithoutTrailingSlash.'/';

		} elseif(is_string($config)) {

            # Getting Single Config item
			return isset(static::$config[$config]) ? static::$config[$config] : null;

		} elseif(!$config) {

            # Getting All configurations
			return static::$config;
		} else {
			throw new CacheException('Invalid parameter provided for Cache::config()');
		}
	}
1261626
protected function makeDir($directory)
	{
		if ( ! $this->files->isDirectory($this->getPath($directory)))
		{
			$this->files->makeDirectory($this->getPath($directory), 0777, true);
		}
	}
46493
private function createDirectory(string $directory, int $mode): bool {
    $auth = false;
    if (is_dir($directory)) {
      $auth = true;
    } else {
      @mkdir($directory, $mode, true);
    }
    @chmod($directory, $mode);
    return is_dir($directory);
  }
1016024
protected function ensure_dir_exists( $dir ) {
		if ( ! is_dir( $dir ) ) {
			// Disable the cache if a null device like /dev/null is being used.
			if ( preg_match( '{(^|[\\\\/])(\$null|nul|NUL|/dev/null)([\\\\/]|$)}', $dir ) ) {
				return false;
			}

			if ( ! @mkdir( $dir, 0777, true ) ) {
				$error = error_get_last();
				\WP_CLI::warning( sprintf( "Failed to create directory '%s': %s.", $dir, $error['message'] ) );
				return false;
			}
		}

		return true;
	}
602381
public function setSystemConfigDir($configDir)
    {
        if (!is_dir($configDir)) {
            throw new \InvalidArgumentException(
                sprintf('Invalid System Configuration Directory: %s', $configDir)
            );
        }

        $this->systemConfigDirectory = $configDir;

        return($this);
    }
836389
public function checkConfigDir()
    {
        if (is_writable(dirname(__FILE__) . '/../../../config'))
            return true;
        
        $this->addError('isConfigDirWritable', Yii::t('Install.main','Configuration directory is not writable. This must be corrected before your settings can be applied.'));
        return false;
    }
798987
public function configureIniStore( $configDir=null)
    {
        $this->configDir = $configDir                                           // case 1)
            ? $configDir
            : ( isset($_ENV['BOTK_CONFIGDIR'])                                    // case 2
                ? $_ENV['BOTK_CONFIGDIR'] 
                : (dirname(dirname($_SERVER['SCRIPT_FILENAME'])) . '/configs')
               ); // case 3
                
        return $this;
    }
182570
public function setDataDirectory(string $directory)
    {
        $directory = rtrim(str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $directory), DIRECTORY_SEPARATOR);

        // Check main data directory
        $this->checkDirectory($directory, false);

        // Check/create sub directory
        $directory = $directory . DIRECTORY_SEPARATOR . self::SUB_DIRECTORY;
        $this->checkDirectory($directory, true);

        $this->dataDirectory = $directory;
    }
1357135
public function mkdir($directory, $recursive = false)
    {
        if (!$recursive or $this->isDir($directory)) {
            return $this->ftp->mkdir($directory);
        }

        $result = false;
        $pwd = $this->ftp->pwd();
        $parts = explode('/', $directory);

        foreach ($parts as $part) {
            if (!@$this->ftp->chdir($part)) {
                $result = $this->ftp->mkdir($part);
                $this->ftp->chdir($part);
            }
        }

        $this->ftp->chdir($pwd);

        return $result;
    }
979108
public function fileExists($directory = null)
    {
        $directory = ($directory) ?: $this->fileDirectory;
        $fileExists = file_exists($this->publicDirectory . $directory . $this->file);
        return $fileExists;
    }
280854
public function isFile($directory = null)
    {
        $directory = ($directory) ?: $this->fileDirectory;
        $isFile = is_file($this->publicDirectory . $directory . $this->file);
        return $isFile;
    }
1213729
public function ensureDirectory(
        string $directory,
        int $mode = null,
        bool $recursivePermissions = true
    ): bool {
        if (empty($mode)) {
            $mode = self::DEFAULT_FILE_MODE;
        }

        //Directories always executable
        $mode = $mode | 0111;
        if (is_dir($directory)) {
            //Exists :(
            return $this->setPermissions($directory, $mode);
        }

        if (!$recursivePermissions) {
            return mkdir($directory, $mode, true);
        }

        $directoryChain = [basename($directory)];

        $baseDirectory = $directory;
        while (!is_dir($baseDirectory = dirname($baseDirectory))) {
            $directoryChain[] = basename($baseDirectory);
        }

        foreach (array_reverse($directoryChain) as $directory) {
            if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}")) {
                return false;
            }

            chmod($baseDirectory, $mode);
        }

        return true;
    }
1065498
public function mkdir(string $directory, int $mode = null): bool {
    if (!empty($directory)) {
      if ($folders = explode(DIRECTORY_SEPARATOR, Path::replaceOSSeparator($directory))) {
        $fullpath = null;
        if (empty($mode)) {
          $mode = AccessMode::MOD_0777;
        }
        foreach ($folders as $folder) {
          if (!empty($folder)) {
            $fullpath .= DIRECTORY_SEPARATOR . $folder;
            $this->createDirectory($fullpath, $mode);
          }
        }
      }
    }
    return file_exists($directory);
  }
690826
public function addDirectory($directory)
    {
        $directories = $this->getDirectory(true);

        if (is_string($directory)) {
            $directory = explode(',', $directory);
        } else if (!is_array($directory)) {
            require_once 'Zend/Validate/Exception.php';
            throw new Zend_Validate_Exception ('Invalid options to validator provided');
        }

        foreach ($directory as $content) {
            if (empty($content) || !is_string($content)) {
                continue;
            }

            $directories[] = trim($content);
        }
        $directories = array_unique($directories);

        // Sanity check to ensure no empty values
        foreach ($directories as $key => $dir) {
            if (empty($dir)) {
                unset($directories[$key]);
            }
        }

        $this->_directory = implode(',', $directories);

        return $this;
    }
93086
private function _prepareDir($config)
    {
        $directory = $this->generateDirectoryPath($config);
        $chmod = $config->get('Cache.SerializerPermissions');
        if ($chmod === null) {
            if (!@mkdir($directory) && !is_dir($directory)) {
                trigger_error(
                    'Could not create directory ' . $directory . '',
                    E_USER_WARNING
                );
                return false;
            }
            return true;
        }
        if (!is_dir($directory)) {
            $base = $this->generateBaseDirectoryPath($config);
            if (!is_dir($base)) {
                trigger_error(
                    'Base directory ' . $base . ' does not exist,
                    please create or change using %Cache.SerializerPath',
                    E_USER_WARNING
                );
                return false;
            } elseif (!$this->_testPermissions($base, $chmod)) {
                return false;
            }
            if (!@mkdir($directory, $chmod) && !is_dir($directory)) {
                trigger_error(
                    'Could not create directory ' . $directory . '',
                    E_USER_WARNING
                );
                return false;
            }
            if (!$this->_testPermissions($directory, $chmod)) {
                return false;
            }
        } elseif (!$this->_testPermissions($directory, $chmod)) {
            return false;
        }
        return true;
    }
1426
public function copyDirectory( string $directory, string $destination, $options = null ): bool
	{
		if( !$this->isDirectory( $directory ) )
		{
			return false;
		}

		$options = $options ?: FilesystemIterator::SKIP_DOTS;

		// If the destination directory does not actually exist, we will go ahead and
		// create it recursively, which just gets the destination prepared to copy
		// the files over. Once we make the directory we'll proceed the copying.
		if( !$this->isDirectory( $destination ) )
		{
			$this->makeDirectory( $destination, 0777, true );
		}

		$items = new FilesystemIterator( $directory, $options );
		foreach( $items as $item )
		{
			// As we spin through items, we will check to see if the current file is actually
			// a directory or a file. When it is actually a directory we will need to call
			// back into this function recursively to keep copying these nested folders.
			$target = $destination . '/' . $item->getBasename();
			if( $item->isDir() )
			{
				$path = $item->getPathname();
				if( !$this->copyDirectory( $path, $target, $options ) )
				{
					return false;
				}
			}

			// If the current items is just a regular file, we will just copy this to the new
			// location and keep looping. If for some reason the copy fails we'll bail out
			// and return false, so the developer is aware that the copy process failed.
			else
			{
				if( !$this->copy( $item->getPathname(), $target ) )
				{
					return false;
				}
			}
		}

		return true;
	}