Skip to content

Instantly share code, notes, and snippets.

@non-senses
Created August 22, 2023 18:34
Show Gist options
  • Save non-senses/d366db0f07eee396e75a0ba40b8779a2 to your computer and use it in GitHub Desktop.
Save non-senses/d366db0f07eee396e75a0ba40b8779a2 to your computer and use it in GitHub Desktop.
<?php
namespace Roofr\Proposal\Commands;
use Illuminate\Console\Command;
const PROPOSALTEAMIDENTIFIER = '@PRO-[1234,5678]';
class NicDev extends Command
{
protected $signature = 'nicdev';
protected $description = 'Command to quick test';
protected $help = 'Used for quick test';
public function handle() {
$items = collect([]);
$routeCollection = \Illuminate\Support\Facades\Route::getRoutes();
foreach ($routeCollection as $route) {
$uri = $route->uri;
$action = $route->getActionName();
if($action === 'Closure') {
continue;
}
$controllerClass = $route->getController();
$methodParts = explode('@', $action);
if(count($methodParts) < 2) {
continue;
}
$methodName = $methodParts[1];
$reflectionMethod = new \ReflectionMethod($controllerClass, $methodName);
$methodDocBlock = $reflectionMethod->getDocComment();
if(strlen($methodDocBlock)) {
$comments = [];
preg_match_all(
'/'.PROPOSALTEAMIDENTIFIER.'.*/i',
$methodDocBlock,
$comments);
if(count($comments) === 0 || count($comments[0]) === 0) {
continue;
}
$items[] = new ItemToDo(
$route->getName(), $route->methods() , $uri, $action, $comments);
}
}
$this->table(['Name', 'Verbs', 'Route', 'Method', 'Notes'], $items->map(function ($x) {
return $x->toArray();
}));
}
}
class ItemToDo {
public $name;
public $route;
public $action;
public $verbs;
public $notes;
public function __construct($name, $verbs, $route, $action, $notes) {
$this->name = $name;
$this->route = $route;
$this->action = $action;
$this->verbs = implode("\n", $verbs);
$this->notes = '';
if(isset($notes[0])) {
$this->notes = implode("\n", $notes[0]);
}
}
public function toArray() {
return [
$this->name,
$this->verbs,
$this->route, $this->action, $this->notes
];
}
/* TODO, to simplify usage */
public static function fromRoute() {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment