-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializer.php
More file actions
143 lines (132 loc) · 3.95 KB
/
Serializer.php
File metadata and controls
143 lines (132 loc) · 3.95 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
<?php
namespace librdf;
/* $Id: Serializer.php 171 2006-06-15 23:24:18Z das-svn $ */
/**
* Serializer, a wrapper around serializer.
*
* 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;
use librdf\URI;
/**
* A wrapper around the serializer datatype.
*
* This class is used in conjunction with {@link Model} to produce
* a serialization of a set of statements.
*
* @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 Serializer
{
/**
* The underlying serializer resource.
*
* @var resource
* @access private
*/
private $serializer;
/**
* Create a new Serializer.
*
* Name is the name of the serializer to use. Common choices are
* "rdfxml", "ntriples" and "turtle".
*
* The "rdfxml" serializer is not pretty, outputing a flat list of
* one XML element per statement. "rdfxml-abbrev" is a bit nicer, but
* slower.
*
* @param string $name The name of the serializer to use
* @param string $mime_type The MIME type of the syntax
* @param string $type_uri The URI of the syntax
* @return void
* @throws Error If unable to create a new serializer
* @access public
*/
public function __construct($name, $mime_type=NULL,
$type_uri=NULL)
{
if ($type_uri) {
$type_uri = new URI($type_uri);
}
$this->serializer = librdf_new_serializer(librdf_php_get_world(),
$name, $mime_type, ($type_uri ? $type_uri->getURI : $type_uri));
if (!$this->serializer) {
throw new Error("Unable to create new serializer");
}
}
/**
* Free the serializer's resources.
*
* @return void
* @access public
*/
public function __destruct()
{
if ($this->serializer) {
librdf_free_serializer($this->serializer);
}
}
/**
* Return the wrapped serializer resource.
*
* This function is intended for other LibRDF classes and should not
* be called.
*
* @return resource The wrapper resource
* @access public
*/
public function getSerializer()
{
return $this->serializer;
}
/**
* Set a prefix to URI mapping.
*
* @param string $uri The namespace URI
* @param string $prefix The string prefix to use
* @return void
* @throws Error If unable to set the prefix
* @access public
*/
public function setNamespace($uri, $prefix)
{
$uri = new URI($uri);
$ret = librdf_serializer_set_namespace($this->serializer,
$uri->getURI(), $prefix);
if ($ret) {
throw new Error("Unable to set namespace prefix");
}
}
}
?>