Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dokuwiki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
BRIC
dokuwiki
Commits
67fe7d43
Commit
67fe7d43
authored
9 years ago
by
Andreas Gohr
Browse files
Options
Downloads
Patches
Plain Diff
first go at using reflection for remote export
parent
d5eb2a76
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/plugins/remote.php
+74
-2
74 additions, 2 deletions
lib/plugins/remote.php
with
74 additions
and
2 deletions
lib/plugins/remote.php
+
74
−
2
View file @
67fe7d43
...
...
@@ -17,10 +17,82 @@ abstract class DokuWiki_Remote_Plugin extends DokuWiki_Plugin {
/**
* Get all available methods with remote access.
*
* @abstract
* By default it exports all public methods of a remote plugin. Methods beginning
* with an underscore are skipped.
*
* @return array Information about all provided methods. {@see RemoteAPI}.
*/
public
abstract
function
_getMethods
();
public
function
_getMethods
()
{
$result
=
array
();
$reflection
=
new
\ReflectionClass
(
$this
);
foreach
(
$reflection
->
getMethods
(
ReflectionMethod
::
IS_PUBLIC
)
as
$method
)
{
// skip parent methods, only methods further down are exported
$declaredin
=
$method
->
getDeclaringClass
()
->
name
;
if
(
$declaredin
==
'DokuWiki_Plugin'
||
$declaredin
==
'DokuWiki_Remote_Plugin'
)
continue
;
$method_name
=
$method
->
getName
();
if
(
substr
(
$method_name
,
0
,
1
)
==
'_'
)
continue
;
// strip asterisks
$doc
=
$method
->
getDocComment
();
$doc
=
preg_replace
(
array
(
'/^[ \t]*\/\*+[ \t]*/m'
,
'/[ \t]*\*+[ \t]*/m'
,
'/\*+\/\s*$/m'
,
'/\s*\/\s*$/m'
),
array
(
''
,
''
,
''
,
''
),
$doc
);
// prepare data
$data
=
array
();
$data
[
'name'
]
=
$method_name
;
$data
[
'public'
]
=
0
;
$data
[
'doc'
]
=
$doc
;
$data
[
'args'
]
=
array
();
// get parameter type from doc block type hint
foreach
(
$method
->
getParameters
()
as
$parameter
)
{
$name
=
$parameter
->
getName
();
$type
=
'string'
;
// we default to string
if
(
preg_match
(
'/^@param[ \t]+([\w|\[\]]+)[ \t]\$'
.
$name
.
'/m'
,
$doc
,
$m
)){
$type
=
$this
->
cleanTypeHint
(
$m
[
1
]);
}
$data
[
'args'
][]
=
$type
;
}
// get return type from doc block type hint
if
(
preg_match
(
'/^@return[ \t]+([\w|\[\]]+)/m'
,
$doc
,
$m
)){
$data
[
'return'
]
=
$this
->
cleanTypeHint
(
$m
[
1
]);
}
else
{
$data
[
'return'
]
=
'string'
;
}
// add to result
$result
[
$method_name
]
=
$data
;
}
return
$result
;
}
/**
* Matches the given type hint against the valid options for the remote API
*
* @param $hint
* @return string
*/
protected
function
cleanTypeHint
(
$hint
)
{
$types
=
explode
(
'|'
,
$hint
);
foreach
(
$types
as
$t
)
{
if
(
substr
(
$t
,
-
2
)
==
'[]'
)
{
return
'array'
;
}
if
(
$t
==
'boolean'
)
{
return
'bool'
;
}
if
(
in_array
(
$t
,
array
(
'array'
,
'string'
,
'int'
,
'double'
,
'bool'
,
'null'
,
'date'
,
'file'
)))
{
return
$t
;
}
}
return
'string'
;
}
/**
* @return RemoteAPI
...
...
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