This repository has been archived by the owner on Aug 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NamedNodeImpl.php
60 lines (52 loc) · 1.56 KB
/
NamedNodeImpl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/*
* This file is part of Saft.
*
* (c) Konrad Abicht <hi@inspirito.de>
* (c) Natanael Arndt <arndt@informatik.uni-leipzig.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Saft\Rdf;
class NamedNodeImpl extends AbstractNamedNode
{
/**
* @var string
*/
protected $uri;
/**
* @param string $uri the URI of the node
*
* @throws \Exception if parameter $value is not a valid URI
*/
public function __construct($uri)
{
if (null == $uri || false == is_string($uri) || false == $this->simpleCheckURI($uri)) {
throw new \Exception('Parameter $uri is not a valid URI: '.$uri);
}
$this->uri = $uri;
}
/**
* @return string URI of the node
*/
public function getUri()
{
return $this->uri;
}
/**
* Checks the general syntax of a given URI. Protocol-specific syntaxes are not checked. Instead, only
* characters disallowed an all URIs lead to a rejection of the check. Use this function, if you need a
* basic check and if performance is an issuse. In case you need a more precise check, that function is
* not recommended.
*
* @param string $string string to check if its a URI or not
*
* @return bool true if given string is a valid URI, false otherwise
*/
protected function simpleCheckURI($string)
{
$regEx = '/^([a-z]{2,}:[^\s]*)$/';
return 1 === preg_match($regEx, (string) $string);
}
}