Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

backoffice initial commit

  • Loading branch information...
commit 9324d3192c19b8e075f8259f0a24162c3433aaec 1 parent 170bab6
arielsom arielsom authored
112 BackOffice/ServiceBrowser.php
View
@@ -0,0 +1,112 @@
+<?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_ServiceBrowser
+ */
+
+require_once(dirname(__FILE__) . '/ClassLoader.php');
+require_once(dirname(__FILE__) . '/Top.html');
+
+$config = new Amfphp_BackOffice_Config();
+$serviceCaller = new Amfphp_BackOffice_ServiceCaller($config->resolveAmfphpEntryPointUrl());
+//load service descriptors
+$services = $serviceCaller->makeAmfphpJsonServiceCall("AmfphpDiscoveryService", "discover");
+
+//what are we calling?
+$callMethodName = null;
+if(isset($_GET['methodName'])){
+ $callMethodName = $_GET['methodName'];
+}
+$callServiceName = null;
+if(isset($_GET['serviceName'])){
+ $callServiceName = $_GET['serviceName'];
+}
+
+$callParameters = $_POST;
+/**
+ * 3 cases:
+ * - POST has some content, this means there is at least one parameter and the call must be made. set to true.
+ * - GET callWithoutParams is set, this means it's a call to a method without parameters. set to true.
+ * - lastly, it can be just a call to select a service method, but without a call. set to false.
+ *
+ */
+$makeServiceCall = false;
+if((count($_POST) > 0) || isset($_GET['callWithoutParams'])){
+ $makeServiceCall = true;
+}
+
+//generate service/method menu
+echo "\n<ul id='menu'>";
+foreach ($services as $service) {
+ echo "\n <li><b>$service->name</b>";
+ echo "\n<ul>";
+ foreach ($service->methods as $method) {
+ if(substr($method->name, 0, 1) == '_'){
+ //methods starting with a '_' as they are reserved, so filter them out
+ continue;
+ }
+ echo "\n <li><a href='?serviceName=" . $service->name . "&methodName=" . $method->name . "'>" . $method->name . "</a></li>";
+ }
+ echo "\n</ul>";
+ echo "</li>";
+}
+echo "\n</ul><div id='content'>";
+
+//generate method calling interface
+if ($callServiceName && $callMethodName) {
+ $serviceDescriptor = $services->$callServiceName;
+ $methodDescriptor = $serviceDescriptor->methods->$callMethodName;
+ $parameterDescriptors = $methodDescriptor->parameters;
+ echo "<h3>$callMethodName method on $callServiceName service</h3>";
+ if (count($parameterDescriptors) > 0) {
+
+ echo "\nUse JSON notation for complex values. ";
+ echo "\n<form action='?serviceName=$callServiceName&amp;methodName=$callMethodName' method='POST'>\n<table>";
+ foreach ($parameterDescriptors as $parameterDescriptor) {
+ $parameterName = $parameterDescriptor->name;
+ echo "\n <tr><td>$parameterName</td><td><input name='$parameterName' ";
+ if ($callParameters) {
+ echo "value='" . $callParameters[$parameterName] . "'";
+ }
+ echo "></td></tr>";
+ }
+ echo "\n</table>\n<input type='submit' value='Call method &raquo;'></form>";
+ } else {
+ echo "This method has no parameters.";
+ echo "\n<form action='?serviceName=$callServiceName&amp;methodName=$callMethodName&amp;callWithoutParams' method='POST'>\n";
+ echo "\n<input type='submit' value='Call method'></form>";
+ }
+}
+
+//make service call and show results
+if ($makeServiceCall) {
+ $callStartTimeMs = microtime(true);
+ //$_POST is associative. Transform it into an array, as it's the format AmfphpJson expects.
+ $paramArray = array();
+ foreach($callParameters as $value){
+ $paramArray[] = $value;
+ }
+ $result = $serviceCaller->makeAmfphpJsonServiceCall($callServiceName, $callMethodName, $paramArray);
+ $callDurationMs = round((microtime(true) - $callStartTimeMs) * 1000);
+
+
+ echo "<h3>Result ( call took " . $callDurationMs . " ms )</h3>";
+ echo '<pre>';
+ echo print_r($result, true);
+ echo '</pre>';
+}
+echo "</div>\n";
+
+
+
+
+
+?>
+ </body>
+</html>
57 BackOffice/ServiceCaller.php
View
@@ -0,0 +1,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_Generators
+
+ /**
+ * Makes a call to the amfphp entry point and returns the data
+ *
+ *
+ * @author Ariel Sommeria-klein
+ * @package Amfphp_Backoffice
+ */
+class Amfphp_BackOffice_ServiceCaller {
+
+ protected $amfphpEntryPointUrl;
+
+ public function __construct($amfphpEntryPointUrl) {
+ $this->amfphpEntryPointUrl = $amfphpEntryPointUrl;
+
+
+ }
+
+ /**
+ * makes a request to the amfphp server
+ * @param string $serviceName
+ * @param string $methodName
+ * @param string $parameters
+ * @return mixed array or object, json decoded
+ */
+ function makeAmfphpJsonServiceCall($serviceName, $methodName, $parameters = array()) {
+ $jsonEncodedParams = json_encode($parameters);
+ $requestString = "{\"serviceName\":\"$serviceName\", \"methodName\":\"$methodName\", \"parameters\":$jsonEncodedParams}";
+ //echo $requestString;
+
+ $curl = curl_init();
+ curl_setopt($curl, CURLOPT_URL, $this->amfphpEntryPointUrl);
+ curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
+ curl_setopt($curl, CURLOPT_POST, 1);
+
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $requestString);
+ curl_setopt($curl, CURLOPT_HEADER, true);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($curl, CURLOPT_HEADER, false);
+ $response = curl_exec($curl);
+ echo $response;
+ return json_decode($response);
+ }
+
+}
+
+?>
26 BackOffice/Top.html
View
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>AmfPHP Back Office</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <LINK rel=stylesheet type="text/css" href="style.css">
+ </head>
+ <body>
+ <div id="header">
+ <a href="?"><b>AmfPHP Back Office</b></a>
+ <ul>
+ <li><a href="http://www.silexlabs.org/amfphp/feedback/">Feedback</a></li>
+ <li><a href="http://www.silexlabs.org/groups/amfphp/amfphp-users/">Forum</a></li>
+ <li><a href="http://www.silexlabs.org/amfphp/documentation/">Documentation</a></li>
+ <li><a href="http://community.silexlabs.org/amfphp/reference/">Class Reference</a></li>
+ <li><a href="https://github.com/silexlabs/amfphp-2.0">Source Code</a></li>
+ <li><a href="http://www.silexlabs.org/amfphp/">AmfPHP Website</a></li>
+ <li><a href="http://www.silexlabs.org/">Silex Labs</a></li>
+ <li><a href="http://www.silexlabs.org/category/exchange/exchange-amfphp/">More Plugins</a></li>
+
+ </ul>
+ </div>
+ <ul id="menu">
+ <li><a href="ServiceBrowser.php"><b>Service Browser</b></a></li>
+ <li><a href="ClientGenerator.php"><b>Client Generator</b></a></li>
+ </ul>
6 BackOffice/index.php
View
@@ -0,0 +1,6 @@
+
+<?php
+
+require_once(dirname(__FILE__) . '/Top.html');
+?>
+
99 BackOffice/style.css
View
@@ -0,0 +1,99 @@
+* {
+ font-size: 12px;
+ font-family: Arial, Helvetica, sans-serif;
+ color: #FFFFFF;
+ margin: 0px;
+ padding: 0px;
+}
+
+html, body {
+ background: #333333;
+}
+
+a {
+ color: #C4D6DC;
+ text-decoration: none;
+}
+
+input {
+ background: none;
+ padding: 5px;
+ border: 1px solid #525252;
+ -moz-border-radius: 8px;
+ -webkit-border-radius: 8px;
+ border-radius: 8px;
+ margin: 5px;
+}
+
+#header {
+ background: #000000;
+ height: 20px;
+ padding: 20px;
+ padding-top: 10px;
+ border-bottom: 1px solid #525252;
+ font-size: 24px;
+}
+
+#header b {
+ font-size: 24px;
+ color: #C4D6DC;
+}
+
+#header ul {
+ float: right;
+ list-style-type: none;
+ margin-top: 7px;
+}
+
+#header ul li {
+ float: left;
+ margin-left: 20px;
+}
+
+#menu {
+ margin: 20px;
+ padding: 11px;
+ background: #525252;
+ float: left;
+ -moz-border-radius: 8px;
+ -webkit-border-radius: 8px;
+ border-radius: 8px;
+ padding-bottom: 0px;
+}
+
+#menu li {
+ margin-left: 15px;
+ margin-bottom: 10px;
+}
+
+#menu li b {
+ font-size: 14px;
+}
+
+#menu li ul {
+ padding-left: 15px;
+}
+
+#menu li ul li {
+ margin-left: 0px;
+ margin-bottom: 2px;
+}
+
+#content {
+ float: left;
+ margin-top: 20px;
+}
+
+#content h3 {
+ background: #525252;
+ padding: 10px;
+ -moz-border-radius: 8px;
+ -webkit-border-radius: 8px;
+ border-radius: 8px;
+ font-size: 14px;
+ margin-bottom: 10px;
+}
+
+#content form {
+ margin-bottom: 20px;
+}
28 BackOffice/test.css
View
@@ -0,0 +1,28 @@
+.tabs {
+ border: 10px solid #ccc;
+ padding: 20px;
+ margin: 0 0 20px 0;
+}
+
+.tab_links {
+ padding: 0 0 0 10px;
+}
+
+body {
+ font-family: arial;
+ font-size: 11px;
+}
+
+h3 {
+ border-bottom: 1px solid #ccc;
+}
+
+a:link, a:visited, a:active {
+ color: #E01B4C;
+ text-decoration: none;
+}
+
+a:hover {
+ text-decoration: underline;
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.