Page MenuHomeDevCentral

No OneTemporary

diff --git a/app/Analyzers/BasePayloadAnalyzer.php b/app/Analyzers/BasePayloadAnalyzer.php
index fd5944d..f9045e4 100644
--- a/app/Analyzers/BasePayloadAnalyzer.php
+++ b/app/Analyzers/BasePayloadAnalyzer.php
@@ -1,169 +1,169 @@
<?php
namespace Nasqueron\Notifications\Analyzers;
use Config;
use Storage;
use BadMethodCallException;
use InvalidArgumentException;
abstract class BasePayloadAnalyzer {
///
/// Private members
///
/**
* The project name, used to load specific configuration and offer defaults
* @var string
*/
protected $project;
/**
* The request content, as a structured data
* @var \stdClass
*/
protected $payload;
/**
* The configuration for the payload analyzer
* @var BasePayloadAnalyzerConfiguration;
*/
protected $configuration;
///
/// Constructor
///
/**
* Creates a new JenkinsPayloadAnalyzer instance.
*
* @param string $project
* @param \stdClass $payload
*/
public function __construct($project, $payload) {
if (!is_object($payload)) {
throw new InvalidArgumentException("Payload must be an object.");
}
$this->project = $project;
$this->payload = $payload;
- $this->loadConfiguration($project);
+ $this->loadConfiguration();
}
///
/// Configuration
///
/**
* The default name of the configuration file
*/
const CONFIG_DEFAULT_FILE = 'default.json';
/**
* Gets the full path to the configuration file.
*
* @return string
*/
public function getConfigurationFileName () {
$dir = Config::get('services.' . strtolower(static::SERVICE_NAME) . '.analyzer.configDir');
$filename = $dir . '/' . $this->project . '.json';
if (!Storage::has($filename)) {
return $dir . '/' . static::CONFIG_DEFAULT_FILE;
}
return $filename;
}
/**
* Gets full qualified class name for configuration.
*
* @return string
*/
private function getCandidateConfigurationClassName() {
$namespace = 'Nasqueron\Notifications\Analyzers\\' . static::SERVICE_NAME;
return $namespace . "\\" . static::SERVICE_NAME . 'PayloadAnalyzerConfiguration';
}
/**
* Gets full qualified class name for configuration if existing,
* or PayloadAnalyzerConfiguration class if not.
*
* @return string The configuration class to use
*/
private function getConfigurationClassName () {
$class = $this->getCandidateConfigurationClassName();
if (class_exists($class)) {
return $class;
}
return PayloadAnalyzerConfiguration::class;
}
/**
* Loads configuration for the analyzer
*/
public function loadConfiguration () {
$fileName = $this->getConfigurationFileName();
$class = $this->getConfigurationClassName();
$mapper = new \JsonMapper();
$this->configuration = $mapper->map(
json_decode(Storage::get($fileName)),
new $class($this->project)
);
}
///
/// Properties
///
/**
* Gets the name of the item.
*
* @var string
*/
public function getItemName () {
throw new BadMethodCallException("The getItemName method must be implemented in the analyzer class if used.");
}
/**
* Determines if the event isn't related to a specific item,
* but to the general service.
*
* @return bool
*/
public function isAdministrativeEvent () {
return false;
}
/**
* Gets the group for a specific payload.
*
* @return string The group, central part of the routing key
*/
public function getGroup () {
// Some events are organization-level only and can't be mapped
// to projects.
if ($this->isAdministrativeEvent()) {
return $this->configuration->administrativeGroup;
}
// If the payload is about some repository matching a table of
// symbols, we need to sort it to the right group.
$item = $this->getItemName();
foreach ($this->configuration->map as $mapping) {
if ($mapping->doesItemBelong($item)) {
return $mapping->group;
}
}
return $this->configuration->getDefaultGroup();
}
}
diff --git a/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
index 6d6be8a..8e4b1b1 100644
--- a/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
+++ b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
@@ -1,77 +1,77 @@
<?php
namespace Nasqueron\Notifications\Analyzers\Phabricator;
use Nasqueron\Notifications\Analyzers\BasePayloadAnalyzer;
use Nasqueron\Notifications\Phabricator\PhabricatorStory;
class PhabricatorPayloadAnalyzer extends BasePayloadAnalyzer {
/**
* The name of the service, used to get specific classes and config
*/
const SERVICE_NAME = "Phabricator";
///
/// Private members
///
/**
* The story
* @var PhabricatorStory
*/
private $story;
///
/// Constructor
///
/**
* Creates a new PhabricatorPayloadAnalyzer instance.
*
* @param string $project
* @param PhabricatorStory $story
*/
public function __construct($project, PhabricatorStory $story) {
$this->project = $project;
$this->story = $story;
- $this->loadConfiguration($project);
+ $this->loadConfiguration();
}
///
/// Qualification of the story
///
/**
* Gets the group for a specific story.
*
* @return string the group, central part of the routing key
*/
public function getGroup () {
// If the payload is about some repository matching a table of
// symbols, we need to sort it to the right group.
foreach ($this->configuration->map as $mapping) {
foreach ($this->story->getProjects() as $project) {
if ($mapping->doesItemBelong($project)) {
return $mapping->group;
}
}
}
// Words
foreach ($this->configuration->map as $mapping) {
if ($mapping->doesStoryBelong($this->story)) {
return $mapping->group;
}
}
// By default, fallback group is the project name or a specified value.
if (empty($this->configuration->defaultGroup)) {
return strtolower($this->project);
}
return $this->configuration->defaultGroup;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, May 3, 06:52 (18 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3674171
Default Alt Text
(6 KB)

Event Timeline