php-censor/src/Plugin.php

107 lines
2.1 KiB
PHP
Raw Normal View History

2013-05-03 17:02:53 +02:00
<?php
2016-07-19 20:28:11 +02:00
namespace PHPCensor;
2013-05-03 17:02:53 +02:00
use PHPCensor\Model\Build;
2016-07-11 18:00:04 +02:00
2013-05-16 03:16:56 +02:00
/**
2017-03-04 16:39:56 +01:00
* @author Dan Cryer <dan@block8.co.uk>
*/
2016-07-11 18:00:04 +02:00
abstract class Plugin
2013-05-03 17:02:53 +02:00
{
const STATUS_PENDING = 0;
const STATUS_RUNNING = 1;
const STATUS_SUCCESS = 2;
const STATUS_FAILED = 3;
const STATUS_FAILED_ALLOWED = 4;
2016-07-11 18:00:04 +02:00
/**
* @var \PHPCensor\Builder
2016-07-11 18:00:04 +02:00
*/
protected $builder;
2016-07-11 18:00:04 +02:00
/**
* @var \PHPCensor\Model\Build
2016-07-11 18:00:04 +02:00
*/
protected $build;
/**
* @var array
*/
protected $options;
/**
* @var string
*/
protected $priorityPath = 'local';
2016-07-11 18:00:04 +02:00
/**
* @param Builder $builder
2016-07-11 18:00:04 +02:00
* @param Build $build
* @param array $options
*/
public function __construct(Builder $builder, Build $build, array $options = [])
2016-07-11 18:00:04 +02:00
{
$this->builder = $builder;
2016-07-11 18:00:04 +02:00
$this->build = $build;
$this->options = $options;
2018-03-04 08:30:34 +01:00
if (!empty($options['priority_path']) && in_array($options['priority_path'], ['global', 'system'], true)) {
$this->priorityPath = $options['priority_path'];
}
$this->builder->logDebug('Plugin options: ' . json_encode($options));
2016-07-11 18:00:04 +02:00
}
/**
* Find a binary required by a plugin.
*
* @param array|string $binary
* @param boolean $quiet Returns null instead of throwing an exception.
*
* @return string|false
*
* @throws \Exception when no binary has been found and $quiet is false.
*/
public function findBinary($binary, $quiet = false)
{
return $this->builder->findBinary($binary, $quiet, $this->priorityPath);
}
2017-01-06 05:14:45 +01:00
/**
* @return Build
*/
public function getBuild()
{
return $this->build;
}
/**
* @return Builder
*/
public function getBuilder()
{
return $this->builder;
}
2018-03-04 08:30:34 +01:00
/**
* @return string
*/
public function getPriorityPath()
{
return $this->priorityPath;
}
2016-07-11 18:00:04 +02:00
/**
* @return boolean
*/
abstract public function execute();
2017-01-11 16:15:54 +01:00
/**
* @return string
*/
public static function pluginName()
{
return '';
}
}