Compare commits

..
5 Commits
Author SHA1 Message Date
Barry vd. Heuvel 9a67d9132f Skip decrement/increment
They are a bit weird.
2014-08-26 10:54:34 +02:00
Barry vd. Heuvel bd33e05304 Don't add magic methods
Fixes #105
2014-08-26 10:53:32 +02:00
Barry vd. Heuvel 83bdb7acd7 Use shortname instead of alias
Fixes #106
2014-08-26 10:49:07 +02:00
Barry vd. Heuvel 4fc9c671e8 Add getShortName
For #106
2014-08-26 10:48:29 +02:00
Barry vd. Heuvel 6c18c3f39a Add json format 2014-08-19 09:49:07 +02:00
5 changed files with 74 additions and 15 deletions
+14 -5
View File
@@ -12,11 +12,11 @@ namespace Barryvdh\LaravelIdeHelper;
class Alias
{
protected $alias;
protected $facade;
protected $extends = null;
protected $classType = 'class';
protected $short;
protected $namespace = '__root';
protected $root = null;
protected $classes = array();
@@ -42,7 +42,6 @@ class Alias
$facade = '\\' . ltrim($facade, '\\');
$this->facade = $facade;
$this->detectRoot();
if ((!$this->isTrait() && $this->root)) {
@@ -54,8 +53,10 @@ class Alias
$this->addClass($this->root);
$this->detectNamespace();
$this->detectClassType();
if($facade === '\Illuminate\Database\Eloquent\Model'){
$this->usedMethods = array('decrement', 'increment');
}
}
/**
@@ -114,6 +115,12 @@ class Alias
return $this->alias;
}
/**
* Return the short name (without namespace)
*/
public function getShortName(){
return $this->short;
}
/**
* Get the namespace from the alias
*
@@ -145,6 +152,8 @@ class Alias
$nsParts = explode('\\', $this->alias);
$this->short = array_pop($nsParts);
$this->namespace = implode('\\', $nsParts);
}else{
$this->short = $this->alias;
}
}
@@ -252,7 +261,7 @@ class Alias
if (!in_array($method->name, $this->usedMethods)) {
// Only add the methods to the output when the root is not the same as the class.
// And don't add the __*() methods
if ($this->extends !== $class && $method->name !== '__clone') {
if ($this->extends !== $class && substr($method->name, 0, 2) !== '__') {
$this->methods[] = new Method($method, $this->alias, $reflection, $method->name, $this->interfaces);
}
$this->usedMethods[] = $method->name;
+15 -5
View File
@@ -82,6 +82,14 @@ class GeneratorCommand extends Command
);
} else {
$filename = $this->argument('filename');
$format = $this->option('format');
// Strip the php extension
if (substr($filename, -4, 4) == '.php') {
$filename = substr($filename, 0, -4);
}
$filename .= '.' . $format;
if ($this->option('memory')) {
$this->useMemoryDriver();
@@ -100,7 +108,7 @@ class GeneratorCommand extends Command
}
$generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers);
$content = $generator->generate();
$content = $generator->generate($format);
$written = $this->files->put($filename, $content);
if ($written !== false) {
@@ -131,12 +139,11 @@ class GeneratorCommand extends Command
*/
protected function getArguments()
{
$filename = $this->config->get('laravel-ide-helper::filename');
return array(
array(
'filename',
InputArgument::OPTIONAL,
'The path to the helper file',
$this->config->get('laravel-ide-helper::filename')
'filename', InputArgument::OPTIONAL, 'The path to the helper file', $filename
),
);
}
@@ -148,7 +155,10 @@ class GeneratorCommand extends Command
*/
protected function getOptions()
{
$format = $this->config->get('laravel-ide-helper::format');
return array(
array('format', "F", InputOption::VALUE_OPTIONAL, 'The format for the IDE Helper', $format),
array('helpers', "H", InputOption::VALUE_NONE, 'Include the helper files'),
array('memory', "M", InputOption::VALUE_NONE, 'Use sqlite memory driver'),
array('sublime', "S", InputOption::VALUE_NONE, 'DEPRECATED: Use different style for SublimeText CodeIntel'),
+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{
+4 -3
View File
@@ -4,14 +4,15 @@ return array(
/*
|--------------------------------------------------------------------------
| Filename
| Filename & Format
|--------------------------------------------------------------------------
|
| The default path to the helper file
| The default filename (without extension) and the format (php or json)
|
*/
'filename' => '_ide_helper.php',
'filename' => '_ide_helper',
'format' => 'php',
/*
|--------------------------------------------------------------------------
+1 -1
View File
@@ -16,7 +16,7 @@ namespace <?= $namespace == '__root' ? '' : $namespace ?>{
<?php endif; ?>
<?php foreach($aliases as $alias): ?>
<?= $alias->getClassType() ?> <?= $alias->getAlias() ?> <?= $alias->getExtends() ? 'extends ' . $alias->getExtends() : '' ?>{
<?= $alias->getClassType() ?> <?= $alias->getShortName() ?> <?= $alias->getExtends() ? 'extends ' . $alias->getExtends() : '' ?>{
<?php foreach($alias->getMethods() as $method): ?>
<?= trim($method->getDocComment(' ')) ?>