Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F10813390
DockerHubNotification.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
DockerHubNotification.php
View Options
<?php
namespace
Nasqueron\Notifications\Notifications
;
use
Nasqueron\Notifications\Analyzers\DockerHub\BaseEvent
;
use
InvalidArgumentException
;
/**
* A Docker Hub notification.
*
* As we always sort them to the 'docker' group, and the registry only fires
* one kind of event, this is pretty straightforward without any need for
* configuration files or analyser class.
*
* HOW TO IMPLEMENT PAYLOADS SORT PER REPOSITORY?
*
* If you want to extend this to sort Docker images through some rules, we
* suggest you add a feature request to Docker to include source repository
* for the image, then call the GitHubPayloadAnalyzer with this repo instead
* of implementing a new one. This will allows to avoid to maintain two sets
* of configuration, one for the GitHub repos, one for the Docker repos.
*
* Even without that, you can probably be safe with a class or a method to map
* GitHub and Docker names, either because they are the same, either because
* there is a prefix: e.g. nasqueron/arcanist and nasqueron/docker-arcanist.
*/
class
DockerHubNotification
extends
Notification
{
public
function
__construct
(
string
$project
,
string
$event
,
\stdClass
$payload
)
{
// Straightforward properties
$this
->
service
=
"DockerHub"
;
$this
->
project
=
$project
;
$this
->
type
=
$event
;
$this
->
rawContent
=
$payload
;
$this
->
group
=
"docker"
;
// Properties from the payload
$this
->
analyzeByEvent
();
}
///
/// Analyze by event
///
/**
* Fills properties from event payload.
*/
public
function
analyzeByEvent
()
:
void
{
$analyzer
=
$this
->
getAnalyzer
();
$this
->
rawContent
=
$analyzer
->
getPayload
();
$this
->
text
=
$analyzer
->
getText
();
$this
->
link
=
$analyzer
->
getLink
();
}
/**
* Gets analyzer class name for the current event.
*
* @return string
*/
private
function
getAnalyzerClassName
()
:
string
{
return
"Nasqueron
\N
otifications
\A
nalyzers
\D
ockerHub
\\
"
.
ucfirst
(
$this
->
type
)
.
"Event"
;
}
/**
* Gets analyzer for the current event.
*
* @return \Nasqueron\Notifications\Analyzers\DockerHub\BaseEvent
*/
private
function
getAnalyzer
()
:
BaseEvent
{
$class
=
$this
->
getAnalyzerClassName
();
if
(!
class_exists
(
$class
))
{
throw
new
InvalidArgumentException
(
"Event $this->type doesn't have a matching $class class."
);
}
return
new
$class
(
$this
->
rawContent
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Jul 29, 13:52 (20 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2832361
Default Alt Text
DockerHubNotification.php (2 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment