forked from ganlvtech/down_52pojie_cn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan.php
49 lines (42 loc) · 1.56 KB
/
scan.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
<?php
use Ganlv\Down52PojieCn\FileDescription;
use Ganlv\Down52PojieCn\FileSystem\LocalFileSystem;
use Ganlv\Down52PojieCn\Helpers;
use Ganlv\Down52PojieCn\Serializer\JsonpSerializer;
use Ganlv\Down52PojieCn\Serializer\JsonSerializer;
use Ganlv\Down52PojieCn\Serializer\YamlSerializer;
require __DIR__ . '/vendor/autoload.php';
date_default_timezone_set('Asia/Shanghai');
$config = include __DIR__ . '/config/config.php';
$fileSystem = new LocalFileSystem([
'BASE_PATH' => $config['BASE_PATH'],
'EXCLUDE_FILES' => $config['EXCLUDE_FILES'],
]);
$data = $fileSystem->tree();
if (file_exists($config['DESCRIPTION_FILE'])) {
$yml = file_get_contents($config['DESCRIPTION_FILE']);
$serializer = new YamlSerializer();
$descriptionData = $serializer->unserialize($yml);
$data = FileDescription::merge($data, $descriptionData);
Helpers::log('description.yml merged');
} else {
$descriptionTemplate = FileDescription::extract($data);
$serializer = new YamlSerializer();
$yml = $serializer->serialize($descriptionTemplate);
file_put_contents($config['DESCRIPTION_FILE'], $yml);
Helpers::log('description.yml template generated');
}
switch ($config['OUTPUT_TYPE']) {
case 'jsonp':
$serializer = new JsonpSerializer([
'CALLBACK_NAME' => $config['JSONP_CALLBACK'],
]);
break;
case 'yaml':
$serializer = new YamlSerializer();
break;
default:
$serializer = new JsonSerializer();
}
$serialized = $serializer->serialize($data);
file_put_contents($config['OUTPUT_FILE'], $serialized);