-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_reporting_models.php
59 lines (46 loc) · 1.75 KB
/
generate_reporting_models.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
53
54
55
56
57
58
59
<?php
use NovakSolutions\FrontDesk\Generate;
require_once('/vendor/autoload.php');
$v3Parser = new Generate\ReportingParser();
$reportingApiDocsAsHtml = http_get_contents("https://developer.frontdeskhq.com/docs/reporting/v3");
$reportingDefinitions = $v3Parser->extractDataFromHtml($reportingApiDocsAsHtml);
//Process Definitions Info Select, Update, Insert, etc...
/** @var mixed $models */
$models = array();
$loader = new Twig_Loader_Filesystem('src/Generate/Templates');
$twig = new Twig_Environment($loader);
$function = new Twig_SimpleFunction('descriptionToPhpDocType',
function ($type) {
switch($type){
case 'boolean':
return "boolean";
default:
return $type;
}
}
);
$twig->addFunction($function);
$template = $twig->loadTemplate('reporting_model.twig');
foreach($reportingDefinitions as $objectName => $endPoints){
$model = array();
$model['modelName'] = preg_replace("/[^A-Za-z0-9]/", "", $objectName);
$model['modelName'] = preg_replace('{s$}', '', $model['modelName']);
$model = array_merge($endPoints, $model);
$frontOrDesk = 'Desk';
$className = $model['modelName'];
$baseClass = 'ReportingModel';
$renderedTemplate = $template->render(compact('frontOrDesk', 'model', 'className', 'baseClass'));
file_put_contents("src/Model/Desk/" . $className . '.php', $renderedTemplate);
}
function http_get_contents($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if(FALSE === ($retval = curl_exec($ch))) {
error_log(curl_error($ch));
} else {
return $retval;
}
}