Last active
January 22, 2021 07:34
-
-
Save xiaoxiaoyu93/f48be8b9ab4c95baf13621c5b38efbab to your computer and use it in GitHub Desktop.
Dump/Export Matomo api Mudules & Actions to json
This file contains hidden or 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
<?php | |
namespace Piwik\Plugins\CoreConsole\Commands; | |
use Piwik\API\DocumentationGenerator; | |
use Piwik\API\Proxy; | |
use Piwik\Plugin\ConsoleCommand; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
class ListAllApi extends ConsoleCommand | |
{ | |
protected function configure() | |
{ | |
$this->setName('api:list'); | |
$this->setDescription('List All Api'); | |
} | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
$ApiDocumentation = new DocumentationGenerator(); | |
$metas = Proxy::getInstance()->getMetadata(); | |
$class_list = array_keys($metas); | |
echo json_encode(array_map(function($methods) use(&$class_list){ | |
$class_name = array_shift($class_list); | |
$class_ref = new \ReflectionClass($class_name); | |
$method_list = array_keys($methods); | |
return array_map(function($method)use (&$method_list,$class_ref){ | |
$method_name = array_shift($method_list); | |
if($class_ref->hasMethod($method_name)){ | |
$method_ref = $class_ref->getMethod($method_name); | |
$method['__documentation'] = $method_ref->getDocComment(); | |
} | |
if(isset($method['parameters'])) { | |
$params = $method['parameters'] ?? []; | |
if (is_array($params)) { | |
$method['parameters'] = array_map(function ($p) { | |
if ($p instanceof \Piwik\API\NoDefaultValue) { | |
return null; | |
} | |
return $p; | |
}, $params); | |
} | |
return $method; | |
} | |
return $method; | |
},$methods); | |
},$metas),JSON_PRETTY_PRINT); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
put it to
plugins/CoreConsole/Commands
;then run