-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathJson.php
52 lines (46 loc) · 1.34 KB
/
Json.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
<?php
// src/metadataparsers/json/Json.php
/**
* Example metadata parser class to demonstrate how to create something other
* than MODS or DC metadata.
*
* Intended for demonstration purposes only, not for production.
*/
namespace mik\metadataparsers\json;
use mik\metadataparsers\MetadataParser;
abstract class Json extends MetadataParser
{
/**
* Create a new metadata parser instance
*/
public function __construct($settings)
{
// Call Metadata.php contructor
parent::__construct($settings);
}
/**
* Converts the object's metadata into JSON.
*
* @param object $objectInfo
* The object's metadata.
*
* @return string
* The serialized JSON version of the object's metadata.
*/
abstract public function createJson($objectInfo);
public function outputJson($json, $outputPath = '')
{
/**
* $json - serialized JSON string - required.
* $outputPath - output path for writing to a file.
*/
if ($outputPath !='') {
$filecreationStatus = file_put_contents($outputPath .'/JSON.json', $json);
if ($filecreationStatus === false) {
echo "There was a problem writing the JSON to a file.\n";
} else {
echo "JSON.json file created.\n";
}
}
}
}