public function testFactory() { $factory = new TagFactory(); $author = $factory->create('author', 'lil-g'); $this->assertTrue($author instanceof AuthorTag); $this->assertEquals('lil-g', $author->getName()); $unknown = $factory->create('wurst'); $this->assertTrue($unknown instanceof UnknownTag); $this->assertEquals('wurst', $unknown->getTagName()); }
/** * Execute the console command. * * @return mixed */ public function handle() { // recuperation du controller $controller = $this->argument('controller'); // création de la méthode $method = camel_case($this->argument('name')); $method = PhpMethod::create($method); $method->setStatic(true); // Gestion du body $body = file_get_contents(__DIR__ . '/stubs/table.stub'); $method->setBody($body); // block de commentaire $dockblock = new Docblock(); $dockblock->appendTag(TagFactory::create('name', 'Artisan')); $dockblock->appendTag(TagFactory::create('see', 'php artisan ffmake:table')); $dockblock->appendTag(TagFactory::create('generated', Carbon::now())); $method->setDocblock($dockblock); // Récupération du controller à mettre à jour $controller = ucfirst(camel_case($controller . '_controller')); $controller = new \ReflectionClass('App\\Http\\Controllers\\' . $controller); $class = PhpClass::fromReflection($controller)->setMethod($method); $class->setParentClassName('Controller'); // fix la gestion des namespaec pour la parent class // Génration du code $generator = new CodeGenerator(); $class = '<?php ' . $generator->generate($class); // inscription du code dans la classe file_put_contents($controller->getFileName(), $class); $this->info('Action generated dans le fichier : ' . $controller->getFileName()); }
/** * Parses an individual tag line * * @param string $line * @throws \InvalidArgumentException * @return \gossi\docblock\tags\AbstractTag */ protected function parseTag($line) { $matches = []; if (!preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\\s*([^\\s].*)|$)?/us', $line, $matches)) { throw new \InvalidArgumentException('Invalid tag line detected: ' . $line); } $tagName = $matches[1]; $content = isset($matches[2]) ? $matches[2] : ''; return TagFactory::create($tagName, $content); }
/** * Execute the console command. * * @return mixed */ public function handle() { $controller = $this->argument('controller'); // création de la méthode $method = camel_case($this->argument('method') . '_' . $this->argument('name')); $method = PhpMethod::create($method); // PARAMS $this->generateParams($method); // BODY $body = ''; $body .= $this->generateAcl(); // TEMPLATE $template = camel_case('template_' . $this->option('template')); if (!method_exists($this, $template)) { exc('Impossible de trouver le template : ' . $template); } $body .= call_user_func([$this, $template]); $method->setBody($body); // DOCKBOCK $dockblock = new Docblock(); $dockblock->appendTag(TagFactory::create('name', 'Artisan')); $dockblock->appendTag(TagFactory::create('see', 'php artisan ffmake:action')); $dockblock->appendTag(TagFactory::create('generated', Carbon::now())); $method->setDocblock($dockblock); // CONTROLLER $controller = ucfirst(camel_case($controller . '_controller')); $controller = new \ReflectionClass('App\\Http\\Controllers\\' . $controller); $class = PhpClass::fromReflection($controller)->setMethod($method); $class->setParentClassName('Controller'); // fix la gestion des namespaec pour la parent class // GENERATION $generator = new CodeGenerator(); $class = '<?php ' . $generator->generate($class); // inscription du code dans la classe file_put_contents($controller->getFileName(), $class); $this->info('Action generated dans le fichier : ' . $controller->getFileName()); }