Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1431920
BNodeLabeler.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
BNodeLabeler.php
View Options
<?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
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 21:13 (1 d, 10 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
14/ca/3953ae1f0df2a46b7bdc1dbbab89
Default Alt Text
BNodeLabeler.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment