php-censor/src/Plugin/Wipe.php

56 lines
1.1 KiB
PHP
Raw Normal View History

2014-04-12 14:31:31 +02:00
<?php
2016-07-19 20:28:11 +02:00
namespace PHPCensor\Plugin;
2014-04-12 14:31:31 +02:00
2016-07-19 20:28:11 +02:00
use PHPCensor\Builder;
use PHPCensor\Model\Build;
use PHPCensor\Plugin;
2014-04-12 14:31:31 +02:00
/**
* Wipe Plugin - Wipes a folder
*
2017-03-04 16:39:56 +01:00
* @author Claus Due <claus@namelesscoder.net>
*/
2016-07-11 18:00:04 +02:00
class Wipe extends Plugin
2014-04-12 14:31:31 +02:00
{
2014-05-02 15:48:40 +02:00
protected $directory;
2017-01-11 16:15:54 +01:00
/**
* @return string
*/
public static function pluginName()
{
return 'wipe';
}
/**
2016-07-11 18:00:04 +02:00
* {@inheritdoc}
*/
public function __construct(Builder $builder, Build $build, array $options = [])
2014-04-12 14:31:31 +02:00
{
parent::__construct($builder, $build, $options);
2016-07-11 18:00:04 +02:00
$path = $this->builder->buildPath;
$this->directory = isset($options['directory']) ? $this->builder->interpolate($options['directory']) : $path;
2014-04-12 14:31:31 +02:00
}
/**
* Wipes a directory's contents
*/
public function execute()
{
$build = $this->builder->buildPath;
2014-04-12 14:31:31 +02:00
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"';
return $this->builder->executeCommand($cmd, $this->directory);
2014-04-12 14:31:31 +02:00
}
return true;
2014-04-12 14:31:31 +02:00
}
}