Page MenuHomeWickedGov Phorge

BNodeLabeler.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

BNodeLabeler.php

<?php
namespace Wikimedia\Purtle;
use InvalidArgumentException;
/**
* Helper class for generating labels for blank nodes.
*
* This serves as a holder for the bnode counter that can be shared between multiple RdfWriter
* instances, to avoid conflicting ids.
*
* @license GPL-2.0-or-later
* @author Daniel Kinzler
*/
class BNodeLabeler {
/**
* @var string
*/
private $prefix;
/**
* @var int
*/
private $counter;
/**
* @param string $prefix
* @param int $start
*
* @throws InvalidArgumentException
*/
public function __construct( $prefix = 'genid', $start = 1 ) {
if ( !is_string( $prefix ) ) {
throw new InvalidArgumentException( '$prefix must be a string' );
}
if ( !is_int( $start ) || $start < 1 ) {
throw new InvalidArgumentException( '$start must be an int >= 1' );
}
$this->prefix = $prefix;
$this->counter = $start;
}
/**
* @param string|null $label node label; will be generated if not given.
*
* @return string
*/
public function getLabel( $label = null ) {
if ( $label === null ) {
$label = $this->prefix . $this->counter;
$this->counter++;
}
return $label;
}
}

File Metadata

Mime Type
text/x-php
Expires
Sat, May 16, 21:13 (1 d, 13 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
14/ca/3953ae1f0df2a46b7bdc1dbbab89
Default Alt Text
BNodeLabeler.php (1 KB)

Event Timeline