Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4793251
PhabricatorPayloadAnalyzer.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
PhabricatorPayloadAnalyzer.php
View Options
<?php
namespace
Nasqueron\Notifications\Analyzers
;
use
Nasqueron\Notifications\Phabricator\PhabricatorStory
;
use
Config
;
class
PhabricatorPayloadAnalyzer
{
///
/// Private members
///
/**
* The project name, used to load specific configuration and offer defaults
* @var string
*/
private
$project
;
/**
* The story
* @var PhabricatorStory
*/
private
$story
;
/**
* The configuration for the payload analyzer
* @var PhabricatorPayloadAnalyzerConfiguration;
*/
private
$configuration
;
///
/// Constructor
///
/**
* Creates a new GitHubPayloadAnalyzer instance.
*
* @param string $project
* @param string $event
* @param stdClass $payload
*/
public
function
__construct
(
$project
,
PhabricatorStory
$story
)
{
$this
->
project
=
$project
;
$this
->
story
=
$story
;
$this
->
loadConfiguration
(
$project
);
}
///
/// Configuration
///
const
CONFIG_DEFAULT_FILE
=
'default.json'
;
public
function
getConfigurationFileName
()
{
$dir
=
Config
::
get
(
'services.phabricator.analyzer.configDir'
);
$filename
=
$dir
.
'/'
.
$this
->
project
.
'.json'
;
if
(!
file_exists
(
$filename
))
{
return
$dir
.
'/'
.
static
::
CONFIG_DEFAULT_FILE
;
}
return
$filename
;
}
public
function
loadConfiguration
()
{
$fileName
=
$this
->
getConfigurationFileName
();
$mapper
=
new
\JsonMapper
();
$this
->
configuration
=
$mapper
->
map
(
json_decode
(
file_get_contents
(
$fileName
)),
new
PhabricatorPayloadAnalyzerConfiguration
()
);
}
///
/// Qualification of the story
///
public
function
isAdministrativeEvent
()
{
//TODO: determine events who qualify as administrative
return
false
;
}
/**
* Gets the group for a specific story
*
* @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.
foreach
(
$this
->
configuration
->
groupsMapping
as
$mapping
)
{
foreach
(
$this
->
story
->
getProjects
()
as
$project
)
{
if
(
$mapping
->
doesProjectBelong
(
$project
))
{
return
$mapping
->
group
;
}
}
}
// Words
foreach
(
$this
->
configuration
->
groupsMapping
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
Details
Attached
Mime Type
text/x-php
Expires
Fri, Feb 28, 21:45 (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2441654
Default Alt Text
PhabricatorPayloadAnalyzer.php (3 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment