Skip to content
Snippets Groups Projects
Commit 0b0b6f58 authored by Sibidharan's avatar Sibidharan :speech_balloon:
Browse files

Call demo

parent 2cc93d18
No related branches found
No related tags found
No related merge requests found
<?php
${basename(__FILE__, '.php')} = function(){
$power = $this->name." has superior intelligence and he is rich.";
return $power;
};
\ No newline at end of file
......@@ -27,6 +27,10 @@ class API extends REST {
else
$this->response('',400); // If the method not exist with in this class, response would be "Page not found".
}
public function __call($method, $args){
}
/*************API SPACE START*******************/
......
call.php 0 → 100644
<pre><?php
class Superhero {
public function __construct($name){
$this->name = $name;
}
public function __call($method, $args){
echo "Method Called: $method\n";
var_dump($args);
$methods = get_class_methods('Superhero');
var_dump($methods);
foreach($methods as $m){
if($m == $method){
echo("Calling the private function from __call(): ".$m."\n");
return $this->$m();
}
}
$dir = __DIR__.'/api/apis';
$methods = scandir($dir);
foreach($methods as $m){
if($m == "." or $m == ".."){
echo $m;
continue;
}
$basem = basename($m, '.php');
echo "Trying to call $basem() for $method()\n";
if($basem == $method){
include $dir."/".$m;
$func = Closure::bind(${$basem}, $this, get_class());
if(is_callable($func)){
return call_user_func_array($func, $args);
} else {
echo "Something is wrong";
}
}
}
}
private function getName(){
return $this->name;
}
}
$hero = new Superhero("Batman");
echo $hero->getName()."\n";
echo $hero->get_powers();
?>
</pre>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment