PHP code example of cottagelabs / coar-notifications
1. Go to this page and download the library: Download cottagelabs/coar-notifications library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cottagelabs / coar-notifications example snippets
$conn = array('host' => '127.0.0.1',
'driver' => 'pdo_mysql',
'user' => 'root',
'password' => 'my-secret-pw',
'dbname' => 'coar_notifications',
);
$logger = new Logger('NotifyCOARLogger');
$handler = new RotatingFileHandler(__DIR__ . '/log/NotifyCOARLogger.log', 0, Logger::DEBUG, true, 0664);
$formatter = new LineFormatter(null, null, false, true);
$handler->setFormatter($formatter);
$logger->pushHandler($handler);
// Initialising a COARNotificationManager
$coarNotificationManager = new COARNotificationManager($conn, $logger);
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
$coarNotificationManager->setOptionsResponseHeaders();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$coarNotificationManager->getPostResponse();
}
// This represents the entity sending the notification
$actor = new COARNotificationActor("actorId", "actorName", "Person");
// The journal that the actor wishes to publish in
$object = new COARNotificationObject("https://overlay-journal.com/reviews/000001/00001",
"https://doi.org/10.3214/987654", array("Document", "sorg:Review"));
// The url of the context object, see below
$url = new COARNotificationURL("https://research-organisation.org/repository/preprint/201203/421/content.pdf",
"application/pdf", array("Article", "sorg:ScholarlyArticle"));
// The actual content that is to be actioned on
$context = new COARNotificationContext("https://research-organisation.org/repository/preprint/201203/421/",
"https://doi.org/10.5555/12345680", array("sorg:AboutPage"), $url);
// This represents the target system the notification is to be delivered to
$target = new COARNotificationTarget("https://research-organisation.org/repository",
"http://localhost:81/post");
// Create the notification
$notification = $coarNotificationManager->createOutboundNotification($actor, $object, $context, $target);