forked from kanemura1206/maspen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-20808 Fixes for amf web services and test client - a web service …
…browser. Includes : MDL-21552 amf web services need to accept params and return values of proper type MDL-21553 amf web service : In Flash an array has normally a numeri
- Loading branch information
1 parent
279e266
commit 94a9b9e
Showing
9 changed files
with
764 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
/** | ||
* Moodle - Modular Object-Oriented Dynamic Learning Environment | ||
* http://moodle.org | ||
* Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* @package moodle | ||
* @author Penny Leach <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL | ||
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com | ||
* | ||
* Introspection for amf - figures out where all the services are and | ||
* returns a list of their available methods. | ||
* Requires $CFG->amf_introspection = true for security. | ||
*/ | ||
|
||
|
||
/** | ||
* Provides a function to get details of methods available on another class. | ||
* @author HP | ||
* | ||
*/ | ||
class MethodDescriptor { | ||
|
||
private $methods; | ||
private $classes; | ||
|
||
static public $classnametointrospect; | ||
|
||
|
||
public function __construct() { | ||
$this->setup(); | ||
} | ||
|
||
private function setup() { | ||
global $CFG; | ||
if (!empty($this->nothing)) { | ||
return; // we've already tried, no classes. | ||
} | ||
if (!empty($this->classes)) { // we've already done it successfully. | ||
return; | ||
} | ||
/*if (empty($CFG->amf_introspection)) { | ||
throw new Exception(get_string('amfintrospectiondisabled', 'local')); | ||
}*/ | ||
|
||
//just one class here, possibility for expansion in future | ||
$classes = array(MethodDescriptor::$classnametointrospect); | ||
|
||
$hugestructure = array(); | ||
|
||
foreach ($classes as $c) { | ||
$r = new ReflectionClass($c); | ||
|
||
if (!$methods = $r->getMethods()) { | ||
continue; | ||
} | ||
$this->classes[] = $c; | ||
$hugestructure[$c] = array('docs' => $r->getDocComment(), 'methods' => array()); | ||
foreach ($methods as $method) { | ||
if (!$method->isPublic()) { | ||
continue; | ||
} | ||
$params = array(); | ||
foreach ($method->getParameters() as $param) { | ||
$params[] = array('name' => $param->getName(), 'required' => !$param->isOptional()); | ||
} | ||
$hugestructure[$c]['methods'][$method->getName()] = array( | ||
'docs' => $method->getDocComment(), | ||
'params' => $params, | ||
); | ||
} | ||
} | ||
$this->methods = $hugestructure; | ||
if (empty($this->classes)) { | ||
$this->nothing = true; | ||
} | ||
} | ||
|
||
public function getMethods() { | ||
$this->setup(); | ||
return $this->methods; | ||
} | ||
|
||
public function getClasses() { | ||
$this->setup(); | ||
return $this->classes; | ||
} | ||
|
||
public function isConnected() { | ||
return true; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package { | ||
|
||
import flash.events.Event; | ||
import flash.net.NetConnection; | ||
import flash.net.Responder; | ||
|
||
import nl.demonsters.debugger.MonsterDebugger; | ||
|
||
/** | ||
* Wrapper class for the NetConnection/Responder instances | ||
* | ||
* This program is free software. It comes without any warranty, to | ||
* the extent permitted by applicable law. You can redistribute it | ||
* and/or modify it under the terms of the Do What The Fuck You Want | ||
* To Public License, Version 2, as published by Sam Hocevar. See | ||
* http://sam.zoy.org/wtfpl/COPYING for more details. | ||
* | ||
* @author Jordi Boggiano <j[email protected]> | ||
*/ | ||
public class AMFConnector extends NetConnection { | ||
private var responder:Responder; | ||
public var data:Object; | ||
public var error:Boolean = false; | ||
|
||
public function AMFConnector(url:String) { | ||
responder = new Responder(onSuccess, onError); | ||
connect(url); | ||
} | ||
|
||
/** | ||
* executes a command on the remote server, passing all the given arguments along | ||
*/ | ||
public function exec(command:String, ... args:Array):void | ||
{ | ||
if (!args) args = []; | ||
args.unshift(responder); | ||
args.unshift(command); | ||
(call as Function).apply(this, args); | ||
} | ||
|
||
/** | ||
* handles success | ||
*/ | ||
protected function onSuccess(result:Object):void { | ||
MonsterDebugger.trace(this, {'result':result}); | ||
data = result; | ||
dispatchEvent(new Event(Event.COMPLETE)); | ||
data = null; | ||
} | ||
|
||
/** | ||
* handles errors | ||
*/ | ||
protected function onError(result:Object):void { | ||
data = result; | ||
MonsterDebugger.trace(this, {'result':result}); | ||
error = true; | ||
dispatchEvent(new Event(Event.COMPLETE)); | ||
error = false; | ||
data = null; | ||
} | ||
} | ||
} |
Oops, something went wrong.