PHPePub\Core\EPub::setIdentifier PHP Method

setIdentifier() public method

Use the URI, or ISBN if available. An unambiguous reference to the resource within a given context. Recommended best practice is to identify the resource by means of a string conforming to a formal identification system. Used for the dc:identifier metadata parameter in the OPF file, as well as dtb:uid in the NCX file. Identifier type should only be: EPub::IDENTIFIER_URI EPub::IDENTIFIER_ISBN EPub::IDENTIFIER_UUID
public setIdentifier ( string $identifier, string $identifierType ) : boolean
$identifier string
$identifierType string
return boolean $success
    function setIdentifier($identifier, $identifierType)
    {
        if ($this->isFinalized || $identifierType !== EPub::IDENTIFIER_URI && $identifierType !== EPub::IDENTIFIER_ISBN && $identifierType !== EPub::IDENTIFIER_UUID) {
            return false;
        }
        $this->identifier = $identifier;
        $this->identifierType = $identifierType;
        return true;
    }

Usage Example

 /**
  * @inheritdoc
  */
 public function initialization(Config $config)
 {
     $this->epub = new EPub();
     $this->epub->setTitle($config->get('title', 'untitled'));
     if ($isbn = $config->get('ISBN')) {
         $this->epub->setIdentifier($isbn, EPub::IDENTIFIER_ISBN);
     } else {
         $this->epub->setIdentifier($config->get('uri'), EPub::IDENTIFIER_URI);
     }
     $this->epub->setLanguage($config->get('language', 'zh-cn'));
     // Not needed, but included for the example, Language is mandatory, but EPub defaults to "en". Use RFC3066 Language codes, such as "en", "da", "fr" etc.
     $this->epub->setDescription($config->get('description'));
     $this->epub->setAuthor($config->get('author'), $config->get('author'));
     $this->epub->setPublisher($config->get('publisher.name'), $config->get('publisher.url'));
     // I hope this is a non existent address :)
     $this->epub->setDate(time());
     // Strictly not needed as the book date defaults to time().
     $this->epub->setRights($config->get('copyright'));
     // As this is generated, this _could_ contain the name or licence information of the user who purchased the book, if needed. If this is used that way, the identifier must also be made unique for the book.
     $this->epub->setSourceURL($config->get('publisher.url'));
     $this->epub->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP");
     $this->epub->buildTOC(NULL, "toc", "目录", TRUE, TRUE);
 }
All Usage Examples Of PHPePub\Core\EPub::setIdentifier