PHP code example of dagstuhl / datacite

1. Go to this page and download the library: Download dagstuhl/datacite 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/ */

    

dagstuhl / datacite example snippets


$dataCiteRecord = new DataCiteRecord();
$dataCiteRecord->setDoi('10.publisher.example-doi');
$dataCiteRecord->addTitle(Title::main('This is an example title', 'en'));

$creator = Creator::personal('Concatenated Names', 'Given Name', 'Family Name');
$creator->addAffiliation(new Affiliation('This is a sample affiliation'));

$dataCiteRecord->addCreator($creator);

$name = Name::organizational('Schloss Dagstuhl - Leibniz-Zentrum für Informatik');
$name->addAffiliation(Affiliation::ror('00k4h2615'));
$contributor = Contributor::editor($name);

$dataCiteRecord->addContributor($contributor);

$related = [];
$related[] = RelatedIdentifier::isPartOf('arXiv:....', RelatedIdentifier::TYPE_ARXIV);
$related[] = RelatedIdentifier::cites('10....', RelatedIdentifier::TYPE_DOI);

$alternate = [];
$alternate[] = AlternateIdentifier::urn('this is a demo urn');
$alternate[] = AlternateIdentifier::isbn('this is a demo urn');

$dataCiteRecord->setRelatedIdentifiers($related);
$dataCiteRecord->setAlternateIdentifiers($alternate);

$type = new Type(
    TYPE::RESOURCE_TYPE_GENERAL_TEXT,
    TYPE::RESOURCE_TYPE_BOOK,
    TYPE::BIBTEX_TYPE_BOOK
);

// or choose a pre-defined type, e.g.,

$type = Type::conferenceProceedingsPaper();
$type = Type::conferenceJournalPaper();
$type = Type::bookChapter();
...

$dataCiteRecord->setType($type);

$dates = [];
$dates[] = Date::created('2020-10-06');
$dates[] = Date::issued('2020-10-06');
$dates[] = Date::copyrighted('2020-10-06');

$dataCiteRecord->setDates($dates);

var_dump($dataCiteRecord->toApiJson());

$dataCiteClient = new DataCiteClient('username', 'password', 'api-url');

$dataCiteRecord = $dataCiteClient->updateDataCiteRecord($dataCiteRecord);

if ($dataCiteRecord === NULL) {
    // error handling goes here
}
        
$dataCiteRecord = $dataCiteClient->setDoiState($dataCiteRecord->getDoi(), DataCiteClient::STATE_FINDABLE);

$dataCiteClient->getException() / ...->getErrorMessage() / ->getResponse() / ->getStatus() 

class MyModelDataProvider implements \Dagstuhl\DataCite\DataCiteDataProvider {
   // ... see the interface for details ... 
}

$dataProvider = new MyModelDataProvider($myModel);     
$dataCiteRecord = DataCiteRecord::fromDataProvider($dataProvider);