phpci/PHPCI/Plugin/CopyBuild.php

59 lines
1.6 KiB
PHP
Raw Normal View History

2013-05-17 18:50:27 +02:00
<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2013, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link http://www.phptesting.org/
*/
namespace PHPCI\Plugin;
2013-10-10 02:01:06 +02:00
use PHPCI\Builder;
use PHPCI\Model\Build;
2013-10-10 02:12:30 +02:00
2013-05-17 18:50:27 +02:00
/**
* Copy Build Plugin - Copies the entire build to another directory.
2013-05-17 18:50:27 +02:00
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Plugins
*/
class CopyBuild implements \PHPCI\Plugin
{
protected $directory;
protected $ignore;
2013-05-17 18:50:27 +02:00
protected $phpci;
2013-10-10 02:12:30 +02:00
public function __construct(Builder $phpci, Build $build, array $options = array())
2013-05-17 18:50:27 +02:00
{
$path = $phpci->buildPath;
$this->phpci = $phpci;
$this->directory = isset($options['directory']) ? $options['directory'] : $path;
$this->ignore = isset($options['respect_ignore']) ? (bool)$options['respect_ignore'] : false;
}
/**
* Copies files from the root of the build directory into the target folder
2013-05-17 18:50:27 +02:00
*/
public function execute()
{
$build = $this->phpci->buildPath;
if ($this->directory == $build) {
return false;
}
$cmd = 'mkdir -p "%s" && cp -R "%s" "%s"';
2013-05-17 18:50:27 +02:00
$success = $this->phpci->executeCommand($cmd, $this->directory, $build, $this->directory);
if ($this->ignore) {
foreach ($this->phpci->ignore as $file) {
$cmd = 'rm -Rf "%s/%s"';
$this->phpci->executeCommand($cmd, $this->directory, $file);
}
}
return $success;
}
}