Skip to content
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

Make actions map configurable #19

Open
gucouture opened this issue Mar 10, 2013 · 10 comments
Open

Make actions map configurable #19

gucouture opened this issue Mar 10, 2013 · 10 comments
Assignees
Milestone

Comments

@gucouture
Copy link

It would be nice to make this configurable

protected $_action_map = array(
   HTTP_Request::GET    => 'get',
   HTTP_Request::PUT    => 'update',
   HTTP_Request::POST   => 'create',
   HTTP_Request::DELETE => 'delete',
);
@michal-m
Copy link
Owner

Elaborate, please. What do you mean by configurable?

@gucouture
Copy link
Author

I'd like to put those into the config file cause i change 'get' by 'index'

HTTP_Request::GET    => 'get',
HTTP_Request::GET    => 'index',

@michal-m
Copy link
Owner

Well, they are configurable on per-Controller basis, so they're as configurable as you can get (and keep sensible about it).

They're set in my abstract Controller class as an example, but each Controller you create should have its own set of actions defined in $_action_map property and you can map actions to whatever you want.

I'm sorry, but I just don't see any reason to move what is essentially a class property to a separate config file.

Keeping it within Controller just makes it more readable without making any less configurable.

@gucouture
Copy link
Author

I agree but all my controllers works the same way so i'll have to modify all of them with the same code, which is ... kind of bad.

@michal-m
Copy link
Owner

But this doesn't mean my approach is bad, does it? You chose different one - fair enough - but if you want to stick with it means more work for you. I used 'get' as default GET action from the beginning.

You can always create your own abstract RESTful Controller that extends mine but changes the default $_action_map?

@gucouture
Copy link
Author

Your approach is not bad but I wonder why a config is problematic for you. Routing with action_index for GET methods is often used by Kohana users (default routing)

I'll probably change all my controllers, or as your said, extends your controller.

I still think something like this would be interesting in order to make this module more easy to use and to configure:

/**
 * RESTful configuration.
 */
return array
(
    'defaults'    => array(
      'content-type'          => 'application/json',
      'actions' => array(
        'GET' => 'get',
        'POST' => 'create',
        .....
      )
    ),
);

and then in your controller

    /**
     * Controller Constructor
     *
     * @param Request $request
     * @param Response $response
     */
    public function __construct(Request $request, Response $response)
    {
        foreach ($config_defaults['actions'] as $a => $b)
        {
            $this->_$action_map[HTTP_Request::$a] = $b;
        }
.....

This is not tested.

Have a great day!

@michal-m
Copy link
Owner

I see your point and while we're discussing it I think I've come up with a better, completely different way to handle the issue. I might actually implement it overnight and I'm reopening this issue.

@michal-m michal-m reopened this Mar 10, 2013
@gucouture
Copy link
Author

Overnight O_o
I really don't need this right now ;)

Happy coding, i'm eager to see your code.

@michal-m
Copy link
Owner

No worries - I need it ;) (it's 10pm here btw.)

@gucouture
Copy link
Author

Oh, 10pm, still early =) Well, have fun, i'm going to diner 17h15 over here. I'm hungry! See ya!

michal-m added a commit that referenced this issue Mar 11, 2013
… used when filtering api request routes

closes #19
@ghost ghost assigned michal-m Mar 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants