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

RouteMatched Object #16

Closed
gianarb opened this issue Aug 25, 2015 · 5 comments
Closed

RouteMatched Object #16

gianarb opened this issue Aug 25, 2015 · 5 comments

Comments

@gianarb
Copy link
Contributor

gianarb commented Aug 25, 2015

Create a RouteMatch object to increase ease to change router library

@gianarb gianarb added this to the 0.3.0 milestone Aug 25, 2015
@gianarb gianarb changed the title RoutMatch Object RouteMatched Object Aug 27, 2015
@gianarb gianarb removed this from the 0.3.0 milestone Sep 5, 2015
@gianarb
Copy link
Contributor Author

gianarb commented Oct 10, 2015

@wdalmut this is an old issue :) Idea?

Target RouteMatch

The RouteMatch job will be: manage interoperability between penny and all other router.. Will be built during $dispatch->dispatch() process.

interface RouteMatch
{
    /**
     * get callable function. This is the action resolved by dispatcher
     */
    public function getCallable();

    /**
     * set callable function.
     */
    public function setCallable(callable $callable);

    /**
     * this is the future event name
     */
    public function setName($name)

     /**
     * this is the future event name
     */
    public function setName($name)
}

The problem around this implementation is this caos
https://github.com/pennyphp/penny/blob/master/src/App.php#L114

and this line of code https://github.com/pennyphp/penny/blob/master/src/App.php#L106

I will use "name" to remove this 💩
https://github.com/pennyphp/penny/blob/master/src/App.php#L106-L111

@wdalmut
Copy link
Contributor

wdalmut commented Oct 10, 2015

Maybe a tiny interface?

interface RouteMatchInterface
{
    /** @return callable */
    public function getCallable();
    public function getName();
}

any class

class RouteMatch implements RouteMatchInterface
{
    public function __construct($name, callable $dispatchable) { ... }
    // Implements other methods...
}
function myRouter($request) {
    $matcher = //...
    return $matcher->match($request); // returns a RouteMatchInterface object
}

Single line router app

function router($request)
{
  $matcher = function($request) {
    if ($request->getPath() == "/") {
      return new RouteMatch("homepage", function($request, $response) {
        return $response->withBody("OK");
      });
    }
  };
  return $matcher($request);
}

@wdalmut
Copy link
Contributor

wdalmut commented Oct 10, 2015

Or maybe drop the interface and works with a simple array...

return [
  "name" => "homepage",
  "callable" => function ($request) {
    // ...
  }
];

@gianarb
Copy link
Contributor Author

gianarb commented Oct 10, 2015

At the moment the problem is that I use DiC to build callable.. :)
https://github.com/pennyphp/penny/blob/master/src/App.php#L106

The callable is not ready.. I should prepare it

@gianarb
Copy link
Contributor Author

gianarb commented Oct 19, 2015

Closed #91

@gianarb gianarb closed this as completed Oct 19, 2015
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