Add json format

This commit is contained in:
Barry vd. Heuvel
2014-08-19 09:49:07 +02:00
parent 19aa77ac49
commit 6c18c3f39a
3 changed files with 59 additions and 9 deletions
+40 -1
View File
@@ -56,9 +56,21 @@ class Generator
/**
* Generate the helper file contents;
*
* @param string $format The format to generate the helper in (php/json)
* @return string;
*/
public function generate()
public function generate($format = 'php')
{
// Check if the generator for this format exists
$method = 'generate'.ucfirst($format).'Helper';
if (method_exists($this, $method)) {
return $this->$method();
}
return $this->generatePhpHelper();
}
public function generatePhpHelper()
{
$app = app();
return $this->view->make('laravel-ide-helper::ide-helper')
@@ -68,6 +80,33 @@ class Generator
->render();
}
public function generateJsonHelper()
{
$classes = array();
foreach ($this->getNamespaces() as $aliases) {
foreach($aliases as $alias) {
$functions = array();
foreach ($alias->getMethods() as $method) {
$functions[$method->getName()] = '('. $method->getParamsWithDefault().')';
}
$classes[$alias->getAlias()] = array(
'functions' => $functions,
);
}
}
$flags = JSON_FORCE_OBJECT;
if (defined('JSON_PRETTY_PRINT')) {
$flags |= JSON_PRETTY_PRINT;
}
return json_encode(array(
'php' => array(
'classes' => $classes,
),
), $flags);
}
protected function detectDrivers()
{
try{