@@ -28,26 +28,29 @@ abstract class RouteMapAbstract extends DataIterator implements RouteMapInterfac
2828{
2929
3030 use ContainerTrait;
31+
32+ protected int $ apiVersion = 1 ;
33+
3134 /**
3235 * @var string|ActionInterface
3336 */
3437 protected $ actionClass ;
3538 /**
36- * @var string
39+ * @var string|null
3740 */
38- protected $ packageName ;
41+ protected ? string $ packageName = null ;
3942 /**
4043 * @var string|EntityRequestInterface
4144 */
42- protected $ requestClass ;
45+ protected string $ requestClass ;
4346 /**
4447 * @var string
4548 */
46- protected $ resourceName ;
49+ protected string $ resourceName ;
4750 /**
4851 * @var string
4952 */
50- protected $ routesPrefix ;
53+ protected string $ routesPrefix = "" ;
5154
5255 /**
5356 * RouteMapAbstract constructor.
@@ -60,6 +63,24 @@ final public function __construct(ContainerInterface $container)
6063 $ this ->initialize ();
6164 }
6265
66+ /**
67+ * @return int
68+ */
69+ public function getApiVersion (): int
70+ {
71+ return $ this ->apiVersion ;
72+ }
73+
74+ /**
75+ * @param int $apiVersion
76+ * @return RouteMapAbstract
77+ */
78+ public function setApiVersion (int $ apiVersion ): RouteMapAbstract
79+ {
80+ $ this ->apiVersion = $ apiVersion ;
81+ return $ this ;
82+ }
83+
6384 /**
6485 * Routes
6586 *
@@ -100,6 +121,11 @@ public function add($method, $pattern): RouteInterface
100121 # Add prefix before resource
101122 array_unshift ($ prefixes , $ this ->routesPrefix );
102123 }
124+ if ($ this ->getApiVersion () > 1 ) {
125+ # Add version before resource
126+ array_unshift ($ prefixes , 'v ' . $ this ->getApiVersion ());
127+ }
128+
103129 $ pattern = $ this ->trailingSlash ($ pattern );
104130 $ pattern = implode ('/ ' , $ prefixes ) . $ pattern ;
105131 $ pattern = '/ ' . ltrim ($ pattern , '/ ' );
@@ -238,7 +264,7 @@ private function trailingSlash($routeName)
238264 {
239265 $ routeName = rtrim ($ routeName , '] ' );
240266 $ routeName = rtrim ($ routeName , '[/ ' );
241- $ missing = substr_count ($ routeName , '[ ' ) - substr_count ($ routeName , '] ' );
267+ $ missing = substr_count ($ routeName , '[ ' ) - substr_count ($ routeName , '] ' );
242268 $ routeName .= '[/] ' . str_repeat ('] ' , $ missing );
243269
244270 return $ routeName ;
0 commit comments