phpci/PHPCI/Plugin/Wipe.php

61 lines
1.3 KiB
PHP
Raw Normal View History

2014-04-12 14:31:31 +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;
use PHPCI\Builder;
use PHPCI\Model\Build;
/**
* Wipe Plugin - Wipes a folder
* @author Claus Due <claus@namelesscoder.net>
* @package PHPCI
* @subpackage Plugins
*/
class Wipe implements \PHPCI\Plugin
{
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;
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;
2014-04-12 14:31:31 +02:00
$this->directory = isset($options['directory']) ? $options['directory'] : $path;
}
/**
* 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)) {
$cmd = 'rm -rf %s*';
$success = $this->phpci->executeCommand($cmd, $this->directory);
}
return $success;
}
}