* Template compiler
  *
  * @param string $contents
  * @return string
  */
 $compiler = function ($contents) use($paser) {
     $contents = preg_replace_callback('/\\{\\{\\s*([\\w\\.]+)\\s*\\}\\}/', $paser, $contents);
     return $contents;
 };
 $configFiles = '/deployer/environments/prod';
 $stage = env('app.stage');
 if ($stage == 'dev') {
     $configFiles = '/deployer/environments/dev';
 }
 $finder = new \Symfony\Component\Finder\Finder();
 $iterator = $finder->ignoreDotFiles(false)->files()->name('/\\.tpl$/')->in(getcwd() . $configFiles);
 $tmpDir = sys_get_temp_dir();
 $releaseDir = env('release_path');
 /* @var $file \Symfony\Component\Finder\SplFileInfo */
 foreach ($iterator as $file) {
     $success = false;
     // Make tmp file
     $tmpFile = tempnam($tmpDir, 'tmp');
     if (!empty($tmpFile)) {
         try {
             $contents = $compiler($file->getContents());
             // cookie validation keys
             if (basename($file) === 'main-local.php.tpl') {
                 $length = 32;
                 $bytes = openssl_random_pseudo_bytes($length);
                 $key = strtr(substr(base64_encode($bytes), 0, $length), '+/=', '_-.');
Esempio n. 2
0
         $value = $matches[0];
     }
     return $value;
 };
 /**
  * Template compiler
  *
  * @param string $contents
  * @return string
  */
 $compiler = function ($contents) use($paser) {
     $contents = preg_replace_callback('/\\{\\{\\s*([\\w\\.]+)\\s*\\}\\}/', $paser, $contents);
     return $contents;
 };
 $finder = new \Symfony\Component\Finder\Finder();
 $iterator = $finder->ignoreDotFiles(false)->files()->name('/\\.tpl$/')->in(getcwd() . '/deployer/templates');
 $tmpDir = sys_get_temp_dir();
 $releaseDir = env('deploy_path');
 /* @var $file \Symfony\Component\Finder\SplFileInfo */
 foreach ($iterator as $file) {
     $success = false;
     // Make tmp file
     $tmpFile = tempnam($tmpDir, 'tmp');
     if (!empty($tmpFile)) {
         try {
             $contents = $compiler($file->getContents());
             // cookie validation key
             if (basename($file) === 'web.php.tpl') {
                 $length = 32;
                 $bytes = openssl_random_pseudo_bytes($length);
                 $key = strtr(substr(base64_encode($bytes), 0, $length), '+/=', '_-.');
/**
 * Return the contents of `$directory` as a single depth list ordered by total filesize.
 *
 * Will schedule background threads to recursively calculate the filesize of subdirectories.
 * The total filesize of each directory and subdirectory is cached in a transient for 1 week.
 *
 * @param string $directory The directory to list
 *
 * @todo doesn't really belong in this class, should just be a function
 * @return array            returns an array of files ordered by filesize
 */
function list_directory_by_total_filesize($directory, Excludes $excludes)
{
    $files = $files_with_no_size = $empty_files = $files_with_size = $unreadable_files = array();
    if (!is_dir($directory)) {
        return $files;
    }
    $finder = new \Symfony\Component\Finder\Finder();
    $finder->followLinks();
    $finder->ignoreDotFiles(false);
    $finder->ignoreUnreadableDirs();
    $finder->depth('== 0');
    $site_size = new Site_Size('file', $excludes);
    $files = $finder->in($directory);
    foreach ($files as $entry) {
        // Get the total filesize for each file and directory
        $filesize = $site_size->filesize($entry);
        if ($filesize) {
            // If there is already a file with exactly the same filesize then let's keep increasing the filesize of this one until we don't have a clash
            while (array_key_exists($filesize, $files_with_size)) {
                $filesize++;
            }
            $files_with_size[$filesize] = $entry;
        } elseif (0 === $filesize) {
            $empty_files[] = $entry;
        } else {
            $files_with_no_size[] = $entry;
        }
    }
    // Sort files by filesize, largest first
    krsort($files_with_size);
    // Add 0 byte files / directories to the bottom
    $files = $files_with_size + array_merge($empty_files, $unreadable_files);
    // Add directories that are still calculating to the top
    if ($files_with_no_size) {
        // We have to loop as merging or concatenating the array would re-flow the keys which we don't want because the filesize is stored in the key
        foreach ($files_with_no_size as $entry) {
            array_unshift($files, $entry);
        }
    }
    return $files;
}
Esempio n. 4
0
                    if (file_put_contents($tmpFile, $contents) > 0) {
                        if (basename($file) === 'yii.tpl') {
                            upload($tmpFile, "{$releaseDir}/" . $target);
                            run('chmod +x ' . "{$releaseDir}/" . $target);
                        } else {
                            run("mkdir -p {$releaseDir}/" . dirname($target));
                            upload($tmpFile, "{$releaseDir}/" . $target);
                        }
                        $success = true;
                    }
                } catch (\Exception $e) {
                    $success = false;
                }
                // Delete tmp file
                unlink($tmpFile);
            }
            if ($success) {
                writeln(sprintf("<info>✔</info> %s", $file->getRelativePathname()));
            } else {
                writeln(sprintf("<fg=red>✘</fg=red> %s", $file->getRelativePathname()));
            }
        }
        $theme = env('app.theme');
        $finder = new \Symfony\Component\Finder\Finder();
        $iterator = $finder->ignoreDotFiles(false)->files()->name('/\\.*$/')->in(getcwd() . '/themes/' . $theme . '/build');
        foreach ($iterator as $file) {
            upload($file, "{$releaseDir}/" . $file->getRelativePathname());
            writeln(sprintf("<info>✔</info> %s", $file->getRelativePathname()));
        }
    }
})->desc('Configures your local development environment')->onlyForStage('local');
Esempio n. 5
0
         $value = $matches[0];
     }
     return $value;
 };
 /**
  * Template compiler
  *
  * @param string $contents
  * @return string
  */
 $compiler = function ($contents) use($paser) {
     $contents = preg_replace_callback('/\\{\\{\\s*([\\w\\.]+)\\s*\\}\\}/', $paser, $contents);
     return $contents;
 };
 $finder = new \Symfony\Component\Finder\Finder();
 $iterator = $finder->ignoreDotFiles(false)->files()->name('/\\.tpl$/')->in(getcwd() . '/shared');
 $tmpDir = sys_get_temp_dir();
 $deployDir = env('deploy_path');
 /* @var $file \Symfony\Component\Finder\SplFileInfo */
 foreach ($iterator as $file) {
     $success = false;
     // Make tmp file
     $tmpFile = tempnam($tmpDir, 'tmp');
     if (!empty($tmpFile)) {
         try {
             $contents = $compiler($file->getContents());
             $target = preg_replace('/\\.tpl$/', '', $file->getRelativePathname());
             // Put contents and upload tmp file to server
             if (file_put_contents($tmpFile, $contents) > 0) {
                 run("mkdir -p {$deployDir}/shared/" . dirname($target));
                 upload($tmpFile, "{$deployDir}/shared/" . $target);