forked from Dressi/amfphp-2.0
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClientGeneratorBackend.php
57 lines (52 loc) · 2.04 KB
/
ClientGeneratorBackend.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
<?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();
if(!$isAccessGranted){
die('User not logged in');
}
$servicesStr = null;
if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
$servicesStr = $GLOBALS['HTTP_RAW_POST_DATA'];
}else{
$servicesStr = file_get_contents('php://input');
}
$services = json_decode($servicesStr);
$generatorClass = $_GET['generatorClass'];
$generatorManager = new Amfphp_BackOffice_ClientGenerator_GeneratorManager();
$generators = $generatorManager->loadGenerators(array('ClientGenerator/Generators'));
$config = new Amfphp_BackOffice_Config();
$generator = $generators[$generatorClass];
$newFolderName = date("Ymd-his-") . $generatorClass;
//temp for testing.
//$newFolderName = $generatorClass;
$genRootRelativeUrl = 'ClientGenerator/Generated/';
$genRootFolder = AMFPHP_BACKOFFICE_ROOTPATH . $genRootRelativeUrl;
$targetFolder = $genRootFolder . $newFolderName;
$generator->generate($services, $config->resolveAmfphpEntryPointUrl(), $targetFolder);
$urlSuffix = $generator->getTestUrlSuffix();
if ($urlSuffix !== false) {
echo '<a target="_blank" href="' . $genRootRelativeUrl . $newFolderName . '/' . $urlSuffix . '"> try your generated project here</a><br/><br/>';
}
if (Amfphp_BackOffice_ClientGenerator_Util::serverCanZip()) {
$zipFileName = "$newFolderName.zip";
$zipFilePath = $genRootFolder . $zipFileName;
Amfphp_BackOffice_ClientGenerator_Util::zipFolder($targetFolder, $zipFilePath, $genRootFolder);
echo '<script>window.location="' . $genRootRelativeUrl . $zipFileName . '";</script>';
} else {
echo " Server can not create zip of generated project, because ZipArchive is not available.<br/><br/>";
echo 'client project written to ' . $targetFolder;
}
?>