Translate a laravel directory config to phpbu backup configuration.

@param  array $dir
@return \phpbu\App\Configuration\Backup
@throws \phpbu\Laravel\Configuration\Exception
333831
protected function directoryConfigToBackup(array $dir)
    {
        $backup = new Configuration\Backup($dir['source']['path'], false);
        // build source config
        $options = [
            'path' => $dir['source']['path'],
        ];

        // check for configuration options
        if (isset($dir['source']['options'])) {
            $options = array_merge($options, $dir['source']['options']);
        }
        $backup->setSource(new Configuration\Backup\Source('tar', $options));
        return $backup;
    }
946359
function recursiveRemoveDir($dir)
    {
        if (is_link($dir)) {
            @unlink($dir);
        } else if (is_dir($dir)) {
            $files = array_diff(@scandir($dir), array('.', '..'));
            foreach ($files as $file) {
                (is_dir("$dir/$file")) ? $this->recursiveRemoveDir("$dir/$file") : @unlink("$dir/$file");
            }
        }
        return @rmdir($dir);
    }
1373457
public function setDir($dir = null){
        $this->databaseDir = (is_null($dir)) ? realpath(__DIR__).DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR : $dir;
        return $this;
    }
711503
public function chdir($dir)
    {
        return ($this->isConnected() === true) ? ftp_chdir($this->getConnection(), $dir) : false;
    }
549866
private function getFolderContent($dir)
    {
        $finder = Finder::create()
            ->ignoreVCS(false)
            ->ignoreDotFiles(false)
            ->depth(0)
            ->in($dir);

        return iterator_to_array($finder);
    }
835057
protected function generateDataFile($dir)
    {
        $file = $dir . '/' . $this->config->getClassname() . '.php';

        if (file_exists($file)) {
            return;
        }

        if (!is_readable($file) && false === file_put_contents($file, '')) {
            throw new \RuntimeException('Cannot create empty class file: ' . $file);
        }

        $content = '<?php

/**
 * Copyright (c) 2010-' . date('Y') . ' ' . $this->config->getAuthor() . '
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ' . $this->baseNamespace . 'Data\\' . $this->config->getNamespace() . ';

/**
 * DataMapper Data class for table "' . $this->config->getDbTable() . '"
 *
 * @author  ' . $this->config->getAuthor() . '
 * @version ' . $this->config->getVersion() . '
 */
class ' . $this->config->getClassname() . ' extends Abstracts\\' . $this->config->getClassname() . 'Abstract
{
}
';
        if (false === file_put_contents($file, $content)) {
            throw new \RuntimeException('Unable to write file content! (file: ' . $file . ')');
        }
    }
900050
public function pushResourceDir($dir)
    {
        File::resolveFilepath($dir);

        $resourcedir = $this->getResourceDir();
        array_push($resourcedir, $dir);

        $this->resourceDir = $resourcedir;

        return $this;
    }
643311
protected function getFilesFromDir($dir)
    {
        $finder = new Finder();
        $finder->files()->ignoreUnreadableDirs()->in(realpath($dir));

        foreach ($this->excludes as $exclude) {
            $finder->notPath($exclude);
        }

        foreach ($this->extensions as $extension) {
            $finder->name('*.'.$extension);
        }

        return iterator_to_array($finder);
    }
583995
protected function makeDirectorySafe($dir)
    {
        $count = 0;

        if (is_dir($dir)) {
            if (!is_writable($dir)) {
                throw new SystemException(Lang::get('system::lang.directory.create_fail', ['name'=>$dir]));
            }

            return;
        }

        while (!is_dir($dir) && !@mkdir($dir, 0777, true)) {
            usleep(rand(50000, 200000));

            if ($count++ > 10) {
                throw new SystemException(Lang::get('system::lang.directory.create_fail', ['name'=>$dir]));
            }
        }

        File::chmodRecursive($dir);
    }
245255
public function generateMapDir($dir)
    {
        $filepath = $this->getCachePath($dir);
        if (Generator::dump($dir, $filepath) == false) {
            throw new Exception("Error writing cache to " . $filepath);
        }
    }
645405
public static function rmdir($dir)
    {
        if (!is_dir($dir)) {
            throw new RuntimeException(sprintf('Invalid directory path supplied "%s"', $dir));
        }

        $files = array_diff(scandir($dir), array('.', '..'));

        foreach ($files as $file) {
            $path = sprintf('%s/%s', $dir, $file);

            if (is_dir($path)) {
                self::rmdir($path);
            } else {
                chmod($path, 0777);
                unlink($path);
            }
        }

        return rmdir($dir);
    }
224102
protected static function readdir($dir)
    {
        $entries = array();
        foreach (scandir($dir) as $entry) {
            if(($entry != '.') && ($entry != '..')){
                $current = "$dir/$entry";
                if($current != $dir){
                    if(is_dir($current)){
                        $aux = self::readdir($current);
                        $entries = array_merge($entries, $aux);
                    }else{
                        if(preg_match("/\w*?Controller.php/", $entry)){
                            $entries[] = $current;
                        }
                    }
                }
            }
        }

        return $entries;
    }
342638
public static function configExists($dir = null)
    {
        $dir = ($dir === null) ? getcwd() : $dir;
        return file_exists($dir . '/docker-compose.yml');
    }
1316220
public static function mkdir($dir)
    {
        if ( file_exists($dir) )
        {
            return $dir;
        }

        mkdir($dir, 0777, true);
        chmod($dir, 0777);

        return $dir;
    }
1101805
protected function doChangeDir($dir)
    {
        $connection = $this->connection;

        return $this->retry(function () use ($connection, $dir) {
            $res = @ftp_chdir($connection, $dir);

            if (false === $res) {
                throw new \RuntimeException("Changing directory failed: ".$dir);
            }
        });
    }
209932
public static function dirList($dir) {
        if (!is_dir($dir))
            throw new \Exception('"' . $dir . '" is not a valid directory');

        $l = array();
        foreach (self::cleanScandir($dir) as $f) {
            if (is_dir($dir . $f)) {
                $l[] = $dir . $f . '/';
                $l = array_merge($l, self::dirList($dir . $f . DIRECTORY_SEPARATOR));
            }
        }
        return $l;
    }
720823
public function loadDir($dir)
    {
        $partialsFiles = scandir($dir);
        $partialsFiles = array_slice($partialsFiles, 2);

        foreach ($partialsFiles as $partialsFile) {

            $partialsFilePath = $dir . $partialsFile;

            if (is_file($partialsFilePath)) {
                $this->loadFile($partialsFilePath);
            } elseif (is_dir($partialsFilePath)) {
                $this->loadDir($partialsFilePath . DIRECTORY_SEPARATOR);
            }
        }
    }