private $_argNames;
private $_argValues;
- public function __construct($pattern, array $methods, $controllerName, $actionName = null)
+ public function __construct($pattern, array $actions, $controllerName)
{
$this->_controllerName = $controllerName;
- $this->_actionName = $actionName;
+ $this->_actions = $actions;
+ $this->_methods = array_keys($actions);
$this->_pattern = $pattern;
- $this->_methods = $methods;
}
public function matches($path) {
return $this->_controllerName;
}
- public function getActionName()
+ public function getActionName($method)
{
- return $this->_actionName;
+ return $this->_actions[$method];
}
public function getActionArgs()
foreach($this->_maps as $pattern => $routeInfo)
{
- $methods = isset($routeInfo['methods']) ? $routeInfo['methods'] : array('GET');
+ //$methods = isset($routeInfo['methods']) ? $routeInfo['methods'] : array('GET');
$controller = isset($routeInfo['controller']) ? $routeInfo['controller'] : 'index';
- $action = isset($routeInfo['action']) ? $routeInfo['action'] : 'index';
+ $actions = isset($routeInfo['actions']) ? $routeInfo['actions'] : array('GET' => 'index');
//TODO: really I should be using a builder or a factory with DI for this but yolo.
- $this->_routes[] = new Route($pattern, $methods, $controller, $action);
+ $this->_routes[] = new Route($pattern, $actions, $controller);
}
}
public function getActionName()
{
$matchedRoute = $this->findMatch();
- return $matchedRoute ? $matchedRoute->getActionName() : 'index';
+ return $matchedRoute ? $matchedRoute->getActionName($this->_request->getMethod()) : 'index';
}
public function getActionArgs()
\r
return [\r
'/simfiles' => [\r
- 'methods' => ['GET'],\r
'controller' => 'Simfile',\r
- 'action' => 'list'\r
+ 'actions' => [\r
+ 'GET'=> 'list'\r
+ ]\r
],\r
\r
'/simfiles/latest/simfile' => [\r
- 'methods' => ['GET'],\r
'controller' => 'Simfile',\r
- 'action' => 'latestSimfile'\r
+ 'actions' => [\r
+ 'GET' => 'latestSimfile'\r
+ ]\r
],\r
\r
'/simfiles/latest/pack' => [\r
- 'methods' => ['GET'],\r
'controller' => 'Simfile',\r
- 'action' => 'latestPack'\r
+ 'actions' => [\r
+ 'GET' => 'latestPack'\r
+ ]\r
],\r
\r
'/simfiles/popular' => [\r
- 'methods' => ['GET'],\r
'controller' => 'Simfile',\r
- 'action' => 'popular'\r
+ 'actions' => [\r
+ 'GET' => 'popular'\r
+ ]\r
],\r
\r
'/simfiles/upload' => [\r
- 'methods' => ['POST'],\r
'controller' => 'Simfile',\r
- 'action' => 'upload'\r
+ 'actions' => [\r
+ 'POST' => 'upload'\r
+ ]\r
],\r
\r
'/cache/update' => [\r
- 'methods' => ['GET'],\r
'controller' => 'SimfileCache',\r
],\r
\r
- '/simfiles/argTest/:testarg' => [\r
- 'methods' => ['GET'],\r
- 'controller' => 'Simfile',\r
- 'action' => 'test'\r
- ],\r
- \r
'/user/auth' => [\r
- 'method' => ['GET'],\r
'controller' => 'UserAuth'\r
],\r
\r
'/user/:facebookId' => [\r
- 'method' => ['GET'],\r
'controller' => 'User',\r
- 'action' => 'getUser'\r
+ 'actions' => [\r
+ 'GET' => 'getUser'\r
+ ]\r
],\r
\r
+ '/user' => [\r
+ 'controller' => 'User',\r
+ 'actions' => [\r
+ 'POST' => 'update',\r
+ ]\r
+ ],\r
+\r
'/files/banner/:hash' => [\r
- 'method' => ['GET'],\r
'controller' => 'File',\r
- 'action' => 'serveBanner'\r
+ 'actions' => [\r
+ 'GET' => 'serveBanner'\r
+ ]\r
],\r
\r
'/files/pack/:hash' => [\r
- 'method' => ['GET'],\r
'controller' => 'File',\r
- 'action' => 'serveSimfileOrPack'\r
+ 'actions' => [\r
+ 'GET' => 'serveSimfileOrPack'\r
+ ]\r
],\r
\r
'/files/simfile/:hash' => [\r
- 'method' => ['GET'],\r
+ 'methods' => ['GET'],\r
'controller' => 'File',\r
- 'action' => 'serveSimfileOrPack'\r
+ 'actions' => [\r
+ 'GET' => 'serveSimfileOrPack'\r
+ ]\r
]\r
];\r