-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathURI.php
More file actions
162 lines (148 loc) · 4.13 KB
/
URI.php
File metadata and controls
162 lines (148 loc) · 4.13 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
namespace librdf;
/* $Id: URI.php 171 2006-06-15 23:24:18Z das-svn $ */
/**
* URI, a representation of a resource in a world.
*
* PHP version 5
*
* Copyright (C) 2006, David Shea <david@gophernet.org>
*
* LICENSE: This package is Free Software and a derivative work of Redland
* http://librdf.org/. This package is not endorsed by Dave Beckett or the
* University of Bristol. It is licensed under the following three licenses as
* alternatives:
* 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
* 2. GNU General Public License (GPL) V2 or any newer version
* 3. Apache License, V2.0 or any newer version
*
* You may not use this file except in compliance with at least one of the
* above three licenses.
*
* See LICENSE.txt at the top of this package for the complete terms and futher
* detail along with the license tests for the licenses in COPYING.LIB, COPYING
* and LICENSE-2.0.txt repectively.
*
* @package LibRDF
* @author David Shea <david@gophernet.org>
* @copyright 2006 David Shea
* @license LGPL/GPL/APACHE
* @version Release: 1.0.0
* @link http://reallylongword.org/projects/librdf-php/
*/
/**
*/
use librdf\exception\Error;
/**
* A wrapper around the uri datatype.
*
* There is no need to use this class directly, as all LibRDF classes infer
* whether or not a uri is needed from context; all the functions that
* use uri internally take strings as arguments for the sake of
* making things easier for the user. This class exists mainly to make
* error handling and garbage collection of uri resources more
* convenient internally for the LibRDF classes.
*
* @package LibRDF
* @author David Shea <david@gophernet.org>
* @copyright 2006 David Shea
* @license LGPL/GPL/APACHE
* @version Release: 1.0.0
* @link http://reallylongword.org/projects/librdf-php/
*/
class URI
{
/**
* The URI of the RDF/XML namespace.
*
* @var string
*/
const RDF_BASE_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
/**
* The underlying uri resource.
*
* @var resource
* @access private
*/
private $uri;
/**
* Create a new URI object from a string.
*
* @param string $uri_string The string to use for the URI
* @return void
* @throws Error If unable to create a new URI
* @access public
*/
public function __construct($uri_string)
{
$this->uri = librdf_new_uri(librdf_php_get_world(), $uri_string);
if (!$this->uri) {
throw new Error("Unable to create new URI from string");
}
}
/**
* Free the URI's resources.
*
* @return void
* @access public
*/
public function __destruct()
{
if ($this->uri) {
librdf_free_uri($this->uri);
}
}
/**
* Return the string representation of the URI.
*
* @return string The URI string
* @access public
*/
public function __toString()
{
return librdf_uri_to_string($this->uri);
}
/**
* Create a new URI object from an existing URI.
*
* @return void
* @throws Error If unable to copy the URI
* @access public
*/
public function __clone()
{
$this->uri = librdf_new_uri_from_uri($this->uri);
if (!$this->uri) {
throw new Error("Unable to create new URI from URI");
}
}
/**
* Return the underlying URI resource.
*
* This function is intended for other LibRDF classes and should not
* be called.
*
* @return resource The URI resource
* @access public
*/
public function getURI()
{
return $this->uri;
}
/**
* Compare this URI against another URI for equality.
*
* @param URI $uri The URI against which to compare
* @return boolean Whether the two URIs are equal
* @access public
*/
public function isEqual(URI $uri)
{
if (librdf_uri_equals($this->uri, $uri->getURI())) {
return true;
} else {
return false;
}
}
}
?>