mirror of https://github.com/hauke68/Magallanes
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.8 KiB
78 lines
1.8 KiB
9 years ago
|
<?php
|
||
|
/*
|
||
|
* This file is part of the Magallanes package.
|
||
|
*
|
||
|
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||
|
*
|
||
|
* For the full copyright and license information, please view the LICENSE
|
||
|
* file that was distributed with this source code.
|
||
|
*/
|
||
|
|
||
|
namespace Mage\Task\BuiltIn\FS;
|
||
|
|
||
9 years ago
|
use Mage\Task\Exception\ErrorException;
|
||
9 years ago
|
use Mage\Task\AbstractTask;
|
||
|
|
||
|
/**
|
||
|
* File System Task - Abstract Base class for File Operations
|
||
|
*
|
||
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||
|
*/
|
||
|
abstract class AbstractFileTask extends AbstractTask
|
||
|
{
|
||
9 years ago
|
/**
|
||
|
* Returns the Task options
|
||
|
*
|
||
|
* @return array
|
||
|
* @throws ErrorException
|
||
|
*/
|
||
9 years ago
|
protected function getOptions()
|
||
|
{
|
||
|
$mandatory = $this->getParameters();
|
||
|
|
||
|
foreach ($mandatory as $parameter) {
|
||
|
if (!array_key_exists($parameter, $this->options)) {
|
||
9 years ago
|
throw new ErrorException(sprintf('Parameter "%s" is not defined', $parameter));
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
|
return $this->options;
|
||
|
}
|
||
|
|
||
9 years ago
|
/**
|
||
|
* Returns the mandatory parameters
|
||
|
*
|
||
|
* @return array
|
||
|
*/
|
||
9 years ago
|
abstract protected function getParameters();
|
||
|
|
||
9 years ago
|
/**
|
||
|
* Returns a file with the placeholders replaced
|
||
|
*
|
||
|
* @param string $file
|
||
|
* @return string
|
||
|
* @throws ErrorException
|
||
|
*/
|
||
9 years ago
|
protected function getFile($file)
|
||
|
{
|
||
|
$mapping = [
|
||
|
'%environment%' => $this->runtime->getEnvironment(),
|
||
|
];
|
||
|
|
||
|
if ($this->runtime->getWorkingHost()) {
|
||
|
$mapping['%host%'] = $this->runtime->getWorkingHost();
|
||
|
}
|
||
|
|
||
|
if ($this->runtime->getReleaseId()) {
|
||
|
$mapping['%release%'] = $this->runtime->getReleaseId();
|
||
|
}
|
||
|
|
||
|
$options = $this->getOptions();
|
||
|
return str_replace(
|
||
|
array_keys($mapping),
|
||
|
array_values($mapping),
|
||
|
$options[$file]
|
||
|
);
|
||
|
}
|
||
|
}
|