public function testShouldFireEvents() { $firedEventsCounter = 0; $eventsManager = new \Phalcon\Events\Manager(); $eventsManager->attach('generator:beforeBuild', function (Event $event, Generator $generator) use(&$firedEventsCounter) { $firedEventsCounter++; }); $eventsManager->attach('generator:afterBuild', function (Event $event, Generator $generator) use(&$firedEventsCounter) { $firedEventsCounter++; }); $eventsManager->attach('generator:beforeRender', function (Event $event, Generator $generator) use(&$firedEventsCounter) { $firedEventsCounter++; }); $eventsManager->attach('generator:afterRender', function (Event $event, Generator $generator) use(&$firedEventsCounter) { $firedEventsCounter++; }); $generator = new \Vegas\ApiDoc\Generator(APP_ROOT . '/app/modules', ['match' => '/(.*)Controller(.*)\\.php/i', 'verbose' => false]); $generator->setEventsManager($eventsManager); $generator->build(); $generator->setRenderer(new FakeRenderer()); $generator->render(); $this->assertInstanceOf('\\Phalcon\\Events\\Manager', $generator->getEventsManager()); $this->assertSame(4, $firedEventsCounter); }
/** * Generates documentation * * Usage * <code> * php cli/cli.php app:apidoc generate * </code> */ public function generateAction() { /** * @var \Phalcon\Events\Manager $eventsManager */ $eventsManager = $this->di->get('eventsManager'); /** * Benchmarks building annotations collections */ $buildBenchmark = new Benchmark(); $eventsManager->attach('generator:beforeBuild', function () use($buildBenchmark) { $buildBenchmark->start(); }); $eventsManager->attach('generator:afterBuild', function () use($buildBenchmark) { $buildBenchmark->finish(); }); /** * Benchmarks rendering html */ $renderBenchmark = new Benchmark(); $eventsManager->attach('generator:beforeRender', function () use($renderBenchmark) { $renderBenchmark->start(); }); $eventsManager->attach('generator:beforeRender', function () use($renderBenchmark) { $renderBenchmark->finish(); }); //instantiates generator by passing the input directory and regular expression for matching file names //set verbose on true to get information about parsed classes $generator = new Generator($this->getInputPath(), ['match' => '/(.*)Controller(.*)\\.php/i', 'verbose' => true]); $generator->setEventsManager($eventsManager); //builds information $collections = $generator->build(); //get the view object that will be rendering output html $view = $this->getView(); //instantiate default renderer $renderer = new Renderer($collections, $this->getLayoutFilePath()); $renderer->setView($view); /** * Injects benchmarks into view */ $renderer->setViewVar('buildBenchmark', $buildBenchmark); $renderer->setViewVar('renderBenchmark', $renderBenchmark); //sets renderer to generator $generator->setRenderer($renderer); //creates output file file_put_contents($this->getOutputPath() . 'index.html', $generator->render()); }