Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Parsing support for class+method callable and added --filename option #3

Merged
merged 2 commits into from
Mar 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Console/MacrosCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class MacrosCommand extends Command
{
/** @var string The name and signature of the console command */
protected $signature = 'ide-helper:macros';
protected $signature = 'ide-helper:macros {--filename=}';

/** @var string The console command description */
protected $description = 'Generate an IDE helper file for Laravel macros';
Expand Down Expand Up @@ -60,7 +60,7 @@ public function handle()
{
$classes = array_merge($this->classes, config('ide-macros.classes', []));

$fileName = config('ide-macros.filename');
$fileName = $this->option('filename') ?: config('ide-macros.filename');
$this->file = fopen(base_path($fileName), 'w');
$this->writeLine("<?php");

Expand Down Expand Up @@ -89,7 +89,13 @@ public function handle()
$this->generateNamespace($reflection->getNamespaceName(), function () use ($macros, $reflection) {
$this->generateClass($reflection->getShortName(), function () use ($macros) {
foreach ($macros as $name => $macro) {
$function = new \ReflectionFunction($macro);
if(is_array($macro)) {
list($class, $method) = $macro;
$function = new \ReflectionMethod(is_object($class) ? get_class($class) : $class, $method);
} else {
$function = new \ReflectionFunction($macro);
}

if ($comment = $function->getDocComment()) {
$this->writeLine($comment, $this->indent);

Expand Down