Skip to content

Implement new api:routes command. #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

hskrasek
Copy link
Member

@hskrasek hskrasek commented May 8, 2014

Below is my implementation of the api:routes command. Functions basically the same as the base routes command but with different data.

No tests included, since I have no idea how you would even test Artisan commands.

@@ -184,4 +187,13 @@ protected function registerMiddlewares()
$this->app->middleware('Dingo\Api\Http\Middleware\RateLimit', [$this->app]);
}

protected function registerCommands()
{
$this->app['api.routes'] = $this->app->share(function($app) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bind it in the container as dingo.api.command.routes.

@jasonlewis
Copy link
Contributor

This looks really solid @hskrasek. Only things I'm going to want you to change are to use tabs instead of spaces, opening brace should be on a new line, use the literal array syntax [] instead of array()... And, I think that's it. This is kind of like Laravel, doesn't really follow PSR-2.

And don't worry about testing. 😄

@Anahkiasen
Copy link

Why does this not use Symfony's Table helper like Artisan's command route ? That'd be much more solid

@jasonlewis
Copy link
Contributor

It does, doesn't it?

$this->table = $this->getHelperSet()->get('table');

@hskrasek
Copy link
Member Author

hskrasek commented May 9, 2014

It basically is an exact clone of the Artisan routes command. With the addition of maybe one function, and small changes here and there :P.

@jasonlewis I shall make those changes now.

@Anahkiasen
Copy link

Ah yeah sorry I'm used to Symfony 2.5's helpers so I was looking for the use at the top of the file, my bad.

@jasonlewis
Copy link
Contributor

Cheers @hskrasek, just refer to some of the other files for the style. 👍

@Anahkiasen
Copy link

Question then though: if dingo/api is meant for Laravel only, why not just extend RoutesCommand and override the relevant methods ?

@hskrasek
Copy link
Member Author

hskrasek commented May 9, 2014

@Anahkiasen I had tried that and ran into some errors at the time (can't remember the exact error, I've slept since then). I might look into extending the RoutesCommand again, but at the moment it functions all the same. That and if Otwell decides to change something all of a sudden with the RoutesCommand, it is less likely to break this command.

@jasonlewis
Copy link
Contributor

@Anahkiasen Plus I think some sort of separation is required, especially if you have many API routes and many regular routes.

@Anahkiasen
Copy link

No I meant using the core code of it but still just displaying the API routes, just that when Laravel does update to 2.5's Table helper, you'd inherit that too. Since Laravel 4.2 comes with 2.5 components it's likely to happen soon.

@hskrasek
Copy link
Member Author

hskrasek commented May 9, 2014

@jasonlewis Style changes pushed up now.

And I believe @Anahkiasen is saying instead of ApiRoutesCommand extends Command, doing ApiRoutesCommand extends RoutesCommand and then just overriding what I need to override to display only the API Routes. It was something to do with parent::__construct(), if I remember correctly. I will mess around with it later today and see if I can get it to work that way, unless you want them seperated @jasonlewis

@Anahkiasen
Copy link

Yeah that's what I meant

@jasonlewis
Copy link
Contributor

Ah yeah, makes sense, take a look and see if it would be possible @hskrasek. Otherwise I'll merge this in tomorrow (my time).

return new ApiRoutesCommand($app['router']);
});

$this->commands('api.routes');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be updated as well to reflect the new container binding.

@hskrasek
Copy link
Member Author

@jasonlewis I was able to change up the command to extend the RoutesCommand. Everything seems to be in working order.

@Anahkiasen
Copy link

aw yiss, really waiting for this.

@hskrasek
Copy link
Member Author

I haven't tested this, since I didn't even know the options existed until looking at the source, but this command should also support the filtering capabilities that the base Artisan routes command has.

@jasonlewis
Copy link
Contributor

Merged this in locally and have now pushed it at 2dae069. Cheers @hskrasek.

@jasonlewis jasonlewis closed this May 23, 2014
@hskrasek hskrasek deleted the feature/api-routes-command branch May 23, 2014 14:49
@hskrasek
Copy link
Member Author

Woot! No problem, now to find something else to try and contribute to in this package :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants