-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathClientGenerator.php
187 lines (161 loc) · 7.33 KB
/
ClientGenerator.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/**
* This file is part of amfPHP
*
* LICENSE
*
* This source file is subject to the license that is bundled
* with this package in the file license.txt.
* @package Amfphp_BackOffice_ClientGenerator
*/
/**
* includes
*/
require_once(dirname(__FILE__) . '/ClassLoader.php');
$accessManager = new Amfphp_BackOffice_AccessManager();
$isAccessGranted = $accessManager->isAccessGranted();
$config = new Amfphp_BackOffice_Config();
?>
<html>
<title>Amfphp Back Office - Client Generator</title>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript" src="js/amfphp_updates.js"></script>
<script type="text/javascript" src="js/services.js"></script>
<script type="text/javascript">
<?php
echo 'var amfphpVersion = "' . AMFPHP_VERSION . "\";\n";
echo 'var amfphpEntryPointUrl = "' . $config->resolveAmfphpEntryPointUrl() . "\";\n";
if ($config->fetchAmfphpUpdates) {
echo "var shouldFetchUpdates = true;\n";
}else{
echo "var shouldFetchUpdates = false;\n";
}
?>
</script>
</head>
<body>
<div class="page-wrap">
<?php
require_once(dirname(__FILE__) . '/Header.inc.php');
?>
<div id='main' >
<?php
if (!$isAccessGranted) {
?>
<script>
window.location = './SignIn.php';
</script>
<?php
return;
}
?>
<div id="clientGenContent">
<div id="statusMessage" class="warning"></div>
<h2>Generate a client project that consumes your services. </h2>
Use one of the following generators to generate a client Stub project.
<br/>The project includes :<br/>
<ul>
<li>code to make calling your services easy</li>
<li>a starting point for a user interface you can customize</li>
</ul>
<?php
$writeTestFolder = AMFPHP_BACKOFFICE_ROOTPATH . 'ClientGenerator/Generated/';
if(!is_writable($writeTestFolder)){
echo "WARNING: could not write to ClientGenerator/Generated/. <br/> You need to change your permissions to be able to use the client generator.<br/><br/>";
}
?>
Code shall be generated for the following services:
<br/>
<ul id="serviceList"></ul>
<?php
$generatorManager = new Amfphp_BackOffice_ClientGenerator_GeneratorManager();
$generators = $generatorManager->loadGenerators(array('ClientGenerator/Generators'));
//links for each generator
echo "\n<table class='borderTop' id='clientGen'>";
foreach ($generators as $generator) {
echo "\n <tr>";
$generatorName = $generator->getUiCallText();
$generatorClass = get_class($generator);
$infoUrl = $generator->getInfoUrl();
echo "\n <td>$generatorName</td>";
echo "\n <td><a href=\"$infoUrl\">Info</a></td>";
echo "\n <td><a onclick='generate(\"" . $generatorClass . "\")'>Generate!</a></td>";
echo "\n </tr>";
}
?>
<tr><td class="borderTop">IOS</td><td class="borderTop"><a href="http://www.silexlabs.org/amfphp/documentation/client-generators/ios/">Info/Vote Up</a></td> <td class="borderTop">Not Available Yet</td> </tr>
<tr><td>Haxe</td><td><a href="http://www.silexlabs.org/amfphp/documentation/client-generators/haxe/">Info/Vote Up</a></td> <td>Not Available Yet</td> </tr>
<tr><td>Android</td><td><a href="http://www.silexlabs.org/amfphp/documentation/client-generators/android/">Info/Vote Up</a></td> <td>Not Available Yet </td></tr>
<tr class="borderTop"><td class="borderTop">Write your Own?</td><td class="borderTop"><a href="http://www.silexlabs.org/amfphp/documentation/client-generators/writing-you-own-client-generator/">Info</a></td> <td class="borderTop"></td></tr>
</table>
</div>
</div>
</div>
<?php
require_once(dirname(__FILE__) . '/Footer.inc.php');
?>
<script>
$(function () {
amfphp.entryPointUrl = amfphpEntryPointUrl + "?contentType=application/json";
$("#tabName").html("Client Generator <a href='http://www.silexlabs.org/amfphp/documentation/using-the-back-office/client-generator/' target='_blank'>?</a>");
$("#clientGeneratorLink").addClass("chosen");
amfphp.entryPointUrl = amfphpEntryPointUrl + "?contentType=application/json";
amfphp.services.AmfphpDiscoveryService.discover(onServicesLoaded, function( jqXHR, textStatus ) {
displayStatusMessage(textStatus + "<br/><br/>" + jqXHR.responseText);
});
});
function displayStatusMessage(html){
$('#statusMessage').html(html);
}
/**
* callback for when service data loaded from server .
* generates method list.
*/
function onServicesLoaded(data)
{
if(typeof data == "string"){
displayStatusMessage(data);
return;
}
if(data.length == 0){
displayStatusMessage("No Services were found on the server. If this is a new installation, create a class in Amfphp/Services/ and it should appear here.");
}
serviceData = data;
//generate service/method list
var rootUl = $("ul#serviceList");
$(rootUl).empty();
for(serviceName in serviceData){
var service = serviceData[serviceName];
var serviceLi = $("<li>" + serviceName + "</li>")
.appendTo(rootUl);
$(serviceLi).attr("title", service.comment);
$("<ul/>").appendTo(serviceLi);
}
if (shouldFetchUpdates) {
//only load update info once services loaded(that's the important stuff)
amfphpUpdates.init("#newsPopup", "#newsLink", "#textNewsLink", "#latestVersionInfo");
amfphpUpdates.loadAndInitUi();
}
}
function generate(generatorClass){
var callData = JSON.stringify({"serviceName":"AmfphpDiscoveryService", "methodName":"discover","parameters":[]});
var request = $.ajax({
url: "ClientGeneratorBackend.php?generatorClass=" + generatorClass,
type: "POST",
data: JSON.stringify(serviceData)
});
request.done(onGenerationDone);
request.fail(function( jqXHR, textStatus ) {
displayStatusMessage(textStatus + "<br/><br/>" + jqXHR.responseText);
});
}
function onGenerationDone(data){
$('#statusMessage').html(data);
var n = $(document).height();
$('html, body').animate({ scrollTop: n }, 50);
}
</script>