src/SlimController/Slim.php
public function addRoutes(array $routes, $globalMiddlewares = array())
    {
        if (!is_array($globalMiddlewares)) {
            if (func_num_args() > 2) {
                $args = func_get_args();
                $globalMiddlewares = array_slice($args, 1);
            } else {
                $globalMiddlewares = array($globalMiddlewares);
            }
        }

        foreach ($routes as $path => $routeArgs) {
            // create array for simple request
            $routeArgs = (is_array($routeArgs)) ? $routeArgs : array('any' => $routeArgs);

            if (array_keys($routeArgs) === range(0, count($routeArgs) - 1)) {
                // route args is a sequential array not associative
                $routeArgs = array('any' => array($routeArgs[0],
                    isset($routeArgs[1]) && is_array($routeArgs[1]) ? $routeArgs[1] : array_slice($routeArgs, 1))
                );
            }

            foreach ($routeArgs as $httpMethod => $classArgs) {
                // assign vars if middleware callback exists
                if (is_array($classArgs)) {
                    $classRoute       = $classArgs[0];
                    $localMiddlewares = is_array($classArgs[1]) ? $classArgs[1] : array_slice($classArgs, 1);
                } else {
                    $classRoute       = $classArgs;
                    $localMiddlewares = array();
                }

                // specific HTTP method
                $httpMethod = strtoupper($httpMethod);
                if (!in_array($httpMethod, static::$ALLOWED_HTTP_METHODS)) {
                    throw new \InvalidArgumentException("Http method '$httpMethod' is not supported.");
                }

                $routeMiddlewares = array_merge($localMiddlewares, $globalMiddlewares);
                $route = $this->addControllerRoute($path, $classRoute, $routeMiddlewares);

                if (!isset($this->routeNames[$classRoute])) {
                    $route->name($classRoute);
                    $this->routeNames[$classRoute] = 1;
                }

                if ('any' === $httpMethod) {
                    call_user_func_array(array($route, 'via'), static::$ALLOWED_HTTP_METHODS);
                } else {
                    $route->via($httpMethod);
                }
            }
        }

        return $this;
    }
public function addRoutes(array $routes, $globalMiddlewares = array())
    {
        if (!is_array($globalMiddlewares)) {
            if (func_num_args() > 2) {
                $args = func_get_args();
                $globalMiddlewares = array_slice($args, 1);
            } else {
                $globalMiddlewares = array($globalMiddlewares);
            }
        }

        foreach ($routes as $path => $routeArgs) {
            // create array for simple request
            $routeArgs = (is_array($routeArgs)) ? $routeArgs : array('any' => $routeArgs);

            if (array_keys($routeArgs) === range(0, count($routeArgs) - 1)) {
                // route args is a sequential array not associative
                $routeArgs = array('any' => array($routeArgs[0],
                    isset($routeArgs[1]) && is_array($routeArgs[1]) ? $routeArgs[1] : array_slice($routeArgs, 1))
                );
            }

            foreach ($routeArgs as $httpMethod => $classArgs) {
                // assign vars if middleware callback exists
                if (is_array($classArgs)) {
                    $classRoute       = $classArgs[0];
                    $localMiddlewares = is_array($classArgs[1]) ? $classArgs[1] : array_slice($classArgs, 1);
                } else {
                    $classRoute       = $classArgs;
                    $localMiddlewares = array();
                }

                // specific HTTP method
                $httpMethod = strtoupper($httpMethod);
                if (!in_array($httpMethod, static::$ALLOWED_HTTP_METHODS)) {
                    throw new \InvalidArgumentException("Http method '$httpMethod' is not supported.");
                }

                $routeMiddlewares = array_merge($localMiddlewares, $globalMiddlewares);
                $route = $this->addControllerRoute($path, $classRoute, $routeMiddlewares);

                if (!isset($this->routeNames[$classRoute])) {
                    $route->name($classRoute);
                    $this->routeNames[$classRoute] = 1;
                }

                if ('any' === $httpMethod) {
                    call_user_func_array(array($route, 'via'), static::$ALLOWED_HTTP_METHODS);
                } else {
                    $route->via($httpMethod);
                }
            }
        }

        return $this;
    }
public function addRoutes ( array $ routes , $ globalMiddlewares = array ( ) ) { if ( ! is_array ( $ globalMiddlewares ) ) { if ( func_num_args ( ) > 2 ) { $ args = func_get_args ( ) ; $ globalMiddlewares = array_slice ( $ args , 1 ) ; } else { $ globalMiddlewares = array ( $ globalMiddlewares ) ; } } foreach ( $ routes as $ path => $ routeArgs ) { // create array for simple request $ routeArgs = ( is_array ( $ routeArgs ) ) ? $ routeArgs : array ( 'any' => $ routeArgs ) ; if ( array_keys ( $ routeArgs ) === range ( 0 , count ( $ routeArgs ) - 1 ) ) { // route args is a sequential array not associative $ routeArgs = array ( 'any' => array ( $ routeArgs [ 0 ] , isset ( $ routeArgs [ 1 ] ) && is_array ( $ routeArgs [ 1 ] ) ? $ routeArgs [ 1 ] : array_slice ( $ routeArgs , 1 ) ) ) ; } foreach ( $ routeArgs as $ httpMethod => $ classArgs ) { // assign vars if middleware callback exists if ( is_array ( $ classArgs ) ) { $ classRoute = $ classArgs [ 0 ] ; $ localMiddlewares = is_array ( $ classArgs [ 1 ] ) ? $ classArgs [ 1 ] : array_slice ( $ classArgs , 1 ) ; } else { $ classRoute = $ classArgs ; $ localMiddlewares = array ( ) ; } // specific HTTP method $ httpMethod = strtoupper ( $ httpMethod ) ; if ( ! in_array ( $ httpMethod , static :: $ ALLOWED_HTTP_METHODS ) ) { throw new \ InvalidArgumentException ( "Http method '$httpMethod' is not supported." ) ; } $ routeMiddlewares = array_merge ( $ localMiddlewares , $ globalMiddlewares ) ; $ route = $ this -> addControllerRoute ( $ path , $ classRoute , $ routeMiddlewares ) ; if ( ! isset ( $ this -> routeNames [ $ classRoute ] ) ) { $ route -> name ( $ classRoute ) ; $ this -> routeNames [ $ classRoute ] = 1 ; } if ( 'any' === $ httpMethod ) { call_user_func_array ( array ( $ route , 'via' ) , static :: $ ALLOWED_HTTP_METHODS ) ; } else { $ route -> via ( $ httpMethod ) ; } } } return $ this ; }
Add multiple controller based routes

Simple Format
<code>
$app->addRoutes(array(
'/some/path' => 'className:methodName'
));
</code>

With explicit HTTP method
<code>
$app->addRoutes(array(
'/some/path' => array('get' => 'className:methodName')
));
</code>

With local middleware
<code>
$app->addRoutes(array(
'/some/path'  => array('get' => 'className:methodName', function() {})
'/other/path' => array('className:methodName', function() {})
));
</code>

With global middleware
<code>
$app->addRoutes(array(
'/some/path'  => 'className:methodName',
), function() {});
</code>

@param array $routes The route definitions
@param array $globalMiddlewares
@throws \InvalidArgumentException
@internal param $callable ,... $middlewares Optional callable used for all routes as middleware

@return $this
Add multiple controller based routes