Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
API Development Course Apr 2021
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sibidharan
API Development Course Apr 2021
Commits
0b0b6f58
Commit
0b0b6f58
authored
3 years ago
by
Sibidharan
Browse files
Options
Downloads
Patches
Plain Diff
Call demo
parent
2cc93d18
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/apis/get_powers.php
+6
-0
6 additions, 0 deletions
api/apis/get_powers.php
api/index.php
+4
-0
4 additions, 0 deletions
api/index.php
call.php
+55
-0
55 additions, 0 deletions
call.php
with
65 additions
and
0 deletions
api/apis/get_powers.php
0 → 100644
+
6
−
0
View file @
0b0b6f58
<?php
$
{
basename
(
__FILE__
,
'.php'
)}
=
function
(){
$power
=
$this
->
name
.
" has superior intelligence and he is rich."
;
return
$power
;
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
api/index.php
+
4
−
0
View file @
0b0b6f58
...
@@ -27,6 +27,10 @@ class API extends REST {
...
@@ -27,6 +27,10 @@ class API extends REST {
else
else
$this
->
response
(
''
,
400
);
// If the method not exist with in this class, response would be "Page not found".
$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*******************/
/*************API SPACE START*******************/
...
...
This diff is collapsed.
Click to expand it.
call.php
0 → 100644
+
55
−
0
View file @
0b0b6f58
<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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment