@@ -19,16 +19,40 @@ class Record
19
19
/** @var QuiteSimpleXMLElement */
20
20
public $ data ;
21
21
22
+ static $ recordTpl = '<srw:record xmlns:srw="http://www.loc.gov/zing/srw/">
23
+ <srw:recordSchema>{{recordSchema}}</srw:recordSchema>
24
+ <srw:recordPacking>{{recordPacking}}</srw:recordPacking>
25
+ <srw:recordPosition>{{position}}</srw:recordPosition>
26
+ <srw:recordData>{{data}}</srw:recordData>
27
+ </srw:record> ' ;
28
+
22
29
/**
23
30
* Create a new record
24
- *
25
- * @param Danmichaelo\QuiteSimpleXMLElement\QuiteSimpleXMLElement $doc
31
+ * @param QuiteSimpleXMLElement $doc
26
32
*/
27
- public function __construct ($ doc )
33
+ public function __construct (QuiteSimpleXMLElement $ doc )
28
34
{
29
35
$ this ->position = intval ($ doc ->text ('./srw:recordPosition ' ));
30
36
$ this ->packing = $ doc ->text ('./srw:recordPacking ' );
31
37
$ this ->schema = $ doc ->text ('./srw:recordSchema ' );
32
38
$ this ->data = $ doc ->first ('./srw:recordData ' );
33
39
}
40
+
41
+ /**
42
+ * @param int $position
43
+ * @param string|QuiteSimpleXMLElement $data
44
+ * @param string $recordSchema
45
+ * @param string $recordPacking
46
+ * @return Record
47
+ */
48
+ public static function make ($ position , $ data , $ recordSchema ='marcxchange ' , $ recordPacking ='xml ' )
49
+ {
50
+ $ record = str_replace (
51
+ array ('{{position}} ' , '{{data}} ' , '{{recordSchema}} ' , '{{recordPacking}} ' ),
52
+ array ($ position , $ data , $ recordSchema , $ recordPacking ),
53
+ self ::$ recordTpl
54
+ );
55
+
56
+ return new Record (new QuiteSimpleXMLElement ($ record ));
57
+ }
34
58
}
0 commit comments