-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSchemaControllerProvider.php
More file actions
120 lines (97 loc) · 3.74 KB
/
Copy pathSchemaControllerProvider.php
File metadata and controls
120 lines (97 loc) · 3.74 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
<?php
/**
* @file SchemaControllerProvider.php
*/
namespace PatternKit;
use PatternKit\Factory\PatternFactory;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Class SchemaControllerProvider
*
* @package PatternKit
*/
class SchemaControllerProvider implements ControllerProviderInterface
{
/**
* Creates a new controller based on the default route.
*
* @param \Silex\Application $app
*
* @return mixed
*/
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
$controllers->get(
'/{pattern}',
function ($pattern) use ($app) {
$patternObj = PatternFactory::getPattern($pattern);
$data = array();
// Navigation
$data['nav'] = getNav($pattern);
if (array_key_exists('sg', $app["config"]["paths"])) {
$data['nav']['sg_active'] = true;
}
// Pull global app config (if available).
if (isset($app['config'])) {
$data["app_config"] = $app['config'];
}
$data['docs_yaml'] = $patternObj->getDocsData()->getYAML();
$data['docs_content'] = $patternObj->getDocsData()->getContent();
$data['schema'] = json_encode($patternObj->getSchema());
$data['docs_json'] = (array)$patternObj->getSeedData();
$data['starting'] = json_encode($patternObj->getSeedData());
$data['raw_schema'] = (array)$patternObj->getRawSchema();
if ($patternObj->getTemplate()) {
$data['template_markup'] = $patternObj->getTemplate();
}
return $app['twig']->render("display-schema.twig", $data);
}
)->bind('schema');
$controllers->match(
'/editor/{pattern}',
function (Request $request, $pattern) use ($app) {
$data = [];
$patternObj = PatternFactory::getPattern($pattern);
$schema = $patternObj->getSchema();
// Navigation
$data['nav'] = getNav($pattern);
if (array_key_exists('sg', $app["config"]["paths"])) {
$data['nav']['sg_active'] = true;
}
// end navigation
// Get the default values for the various config elements.
$seed_data = $patternObj->getSeedData();
// Use the values provided (if available) to override defaults.
$raw_json = $request->getContent();
if (!empty($raw_json)) {
$seed_data = $raw_json;
}
// Apply global configuration.
if (isset($app['config'])) {
$data["app_config"] = $app['config'];
}
$docs_data = $patternObj->getDocsData();
$data['docs_yaml'] = $docs_data->getYAML();
$data['docs_content'] = $docs_data->getContent();
$data['schema'] = json_encode($schema);
$data['docs_json'] = (array)$seed_data;
$data['starting'] = json_encode($seed_data);
$data['raw_schema'] = (array)$patternObj->getRawSchema();
if ($patternObj->getTemplate()) {
$data['template_markup'] = $patternObj->getTemplate();
}
return $app['twig']->render(
"display-just-schema-editor.twig",
$data
);
}
)
// Supporting GET/POST for easier debugging.
->method('GET|POST')
->bind('schema-editor');
return $controllers;
}
}