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

Pattern based request re-dispatcher #51

Closed
tanakahisateru opened this issue Feb 9, 2012 · 3 comments
Closed

Pattern based request re-dispatcher #51

tanakahisateru opened this issue Feb 9, 2012 · 3 comments
Milestone

Comments

@tanakahisateru
Copy link
Owner

I want to write multiple action in single script file.

Current:

$method = $this->request->server->get('HTTP_METHOD');
if($method == 'GET' && preg_match('/^(.*?)\\/edit$/', $this->subpath, $matches)) {
   $id = $matches[1];
   // show data
   $this->terminate();
}
else if($method == 'POST' && preg_match('/^(.*?)\\/edit$/', $this->subpath, $matches)) {
   $id = $matches[1];
   // save data
   $this->terminate();
}
else if(preg_match('/^.*?\\/edit$/', $this->subpath)) {
    $this->forbidden();
}

Expected:

$d = $this->dispatcher($this->subpath);
$d->on('GET',  '{id}/edit', function($id) { /* show data */ return false; });
$d->on('POST', '{id}/edit', function($id) { /* save data */ return false; });
$d->on('*',    '*/edit',   function() { Pinoco::instance()->forbidden(); });

or

$d = $this->dispatcher($this->subpath);
$d->on('GET',  '{id}/edit', array($controller, 'onGetEdit'));
$d->on('POST', '{id}/edit', array($controller, 'onPostEdit'));
$d->on('*',    '*/edit',   array($this, 'forbidden'));
@tanakahisateru
Copy link
Owner Author

issue renamed

tanakahisateru added a commit that referenced this issue Jul 30, 2012
@tanakahisateru
Copy link
Owner Author

Invalid commit log above?

@tanakahisateru
Copy link
Owner Author

Pinoco_Router has been implemented. It can be used as:

$this->router()->pass(array('', 'index.html',))
    ->on('list', function() use($self, $data) {
        // ...
    })
    ->on('show/{id}', function($id) use($self, $data) {
        // ...
    })
    ->on('POST:post', function() use($self, $data) {
        // ...
    })
    ->on('GET:post', array($this, 'forbidden'))
    ->on('*', array($this, 'notfound'));

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

1 participant