phpci/PHPCI/Plugin/Wipe.php

69 lines
1.6 KiB
PHP
Raw Normal View History

2014-04-12 14:31:31 +02:00
<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2014, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/
2014-04-12 14:31:31 +02:00
namespace PHPCI\Plugin;
use PHPCI\Builder;
use PHPCI\Model\Build;
/**
* Wipe Plugin - Wipes a folder
* @author Claus Due <claus@namelesscoder.net>
* @package PHPCI
* @subpackage Plugins
*/
class Wipe extends AbstractPlugin
2014-04-12 14:31:31 +02:00
{
2014-05-02 15:48:40 +02:00
/**
* @var \PHPCI\Builder
*/
2014-04-12 14:31:31 +02:00
protected $phpci;
2014-05-02 15:48:40 +02:00
/**
* @var \PHPCI\Model\Build
*/
protected $build;
protected $directory;
/**
* Set up the plugin, configure options, etc.
* @param Builder $phpci
* @param Build $build
* @param array $options
*/
2014-04-12 14:31:31 +02:00
public function __construct(Builder $phpci, Build $build, array $options = array())
{
$path = $phpci->buildPath;
$this->phpci = $phpci;
2014-05-02 15:48:40 +02:00
$this->build = $build;
2015-03-16 12:09:45 +01:00
$this->directory = isset($options['directory']) ? $this->phpci->interpolate($options['directory']) : $path;
2014-04-12 14:31:31 +02:00
}
/**
* Wipes a directory's contents
*/
public function execute()
{
$build = $this->phpci->buildPath;
if ($this->directory == $build || empty($this->directory)) {
return true;
}
if (is_dir($this->directory)) {
2014-05-09 09:57:22 +02:00
$cmd = 'rm -Rf "%s"';
if (IS_WIN) {
$cmd = 'rmdir /S /Q "%s"';
}
return $this->phpci->executeCommand($cmd, $this->directory);
2014-04-12 14:31:31 +02:00
}
return true;
2014-04-12 14:31:31 +02:00
}
}