Skip to content

Commit 878e3b1

Browse files
committed
move example/controllers file to test dir
1 parent 8970aee commit 878e3b1

File tree

13 files changed

+42
-44
lines changed

13 files changed

+42
-44
lines changed

example/cached.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// enable autoRoute
2828
// you can access '/demo' '/admin/user/info', Don't need to configure any route
2929
'autoRoute' => 1,
30-
'controllerNamespace' => 'Inhere\Route\Example\Controllers',
30+
'controllerNamespace' => 'Inhere\RouteTest\controllers',
3131
'controllerSuffix' => 'Controller',
3232
]);
3333

example/object.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// enable autoRoute
2727
// you can access '/demo' '/admin/user/info', Don't need to configure any route
2828
'autoRoute' => 1,
29-
'controllerNamespace' => 'Inhere\Route\Example\Controllers',
29+
'controllerNamespace' => 'Inhere\RouteTest\controllers',
3030
'controllerSuffix' => 'Controller',
3131
]);
3232

example/pre-match.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// enable autoRoute
2828
// you can access '/demo' '/admin/user/info', Don't need to configure any route
2929
'autoRoute' => 1,
30-
'controllerNamespace' => 'Inhere\Route\Example\Controllers',
30+
'controllerNamespace' => 'Inhere\RouteTest\controllers',
3131
'controllerSuffix' => 'Controller',
3232
]);
3333

example/some-routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*/
99

10-
use Inhere\Route\Example\Controllers\HomeController;
10+
use Inhere\RouteTest\controllers\HomeController;
1111
use Inhere\Route\RouterInterface;
1212

1313
function handler0()

example/static.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// enable autoRoute
2323
// you can access '/demo' '/admin/user/info', Don't need to configure any route
2424
'autoRoute' => 1,
25-
'controllerNamespace' => 'Inhere\Route\Example\Controllers',
25+
'controllerNamespace' => 'Inhere\RouteTest\controllers',
2626
'controllerSuffix' => 'Controller',
2727
]);
2828

example/swoole_svr.php renamed to example/swoole-server.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Date: 2017/7/14
66
* Time: 下午9:12
77
* you can test use:
8-
* php example/swoole_svr.php
8+
* php example/swoole-server.php
99
* then you can access url: http://127.0.0.1:5675
1010
*/
1111

@@ -24,7 +24,7 @@
2424
// enable autoRoute
2525
// you can access '/demo' '/admin/user/info', Don't need to configure any route
2626
'autoRoute' => 1,
27-
'controllerNamespace' => 'Inhere\Route\Example\Controllers',
27+
'controllerNamespace' => 'Inhere\RouteTest\controllers',
2828
'controllerSuffix' => 'Controller',
2929
]);
3030

@@ -38,9 +38,8 @@
3838

3939
$dispatcher = new Dispatcher([
4040
'dynamicAction' => true,
41-
], function ($path, $method) use ($router) {
42-
return $router->match($path, $method);
43-
});
41+
]);
42+
$dispatcher->setRouter($router);
4443

4544
// on notFound, output a message.
4645
$dispatcher->on(Dispatcher::ON_NOT_FOUND, function ($path) {
@@ -49,15 +48,15 @@
4948

5049
$server = new \Swoole\Http\Server('127.0.0.1', '5675', SWOOLE_BASE);
5150
$server->set([
52-
51+
//
5352
]);
5453

5554
$server->on('request', function ($request, $response) use ($dispatcher) {
5655
/** @var \Swoole\Http\Response $response */
5756
$uri = $request->server['request_uri'];
5857
$method = $request->server['request_method'];
5958

60-
fwrite(STDOUT, "request $method $uri\n");
59+
// fwrite(STDOUT, "request $method $uri\n");
6160

6261
ob_start();
6362
$ret = $dispatcher->dispatchUri($uri, $method);

src/Router.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ public function any(string $path, $handler, array $pathParams = [], array $opts
226226
}
227227

228228
/**
229-
* @param array|string $methods
230-
* @param string $path
229+
* @param array|string $methods
230+
* @param string $path
231231
* @param callable|string $handler
232-
* @param array $pathParams
233-
* @param array $opts
232+
* @param array $pathParams
233+
* @param array $opts
234234
*/
235235
public function map($methods, string $path, $handler, array $pathParams = [], array $opts = [])
236236
{
@@ -242,9 +242,9 @@ public function map($methods, string $path, $handler, array $pathParams = [], ar
242242
/**
243243
* @param string $method
244244
* @param string $path
245-
* @param $handler
246-
* @param array $pathParams
247-
* @param array $opts
245+
* @param $handler
246+
* @param array $pathParams
247+
* @param array $opts
248248
* @return Route
249249
*/
250250
public function add(string $method, string $path, $handler, array $pathParams = [], array $opts = []): Route
@@ -280,7 +280,7 @@ public function addRoute(Route $route): Route
280280
{
281281
$this->appendGroupInfo($route);
282282

283-
$path = $route->getPath();
283+
$path = $route->getPath();
284284
$method = $route->getMethod();
285285

286286
$this->routeCounter++;
@@ -310,10 +310,10 @@ public function addRoute(Route $route): Route
310310
/**
311311
* Create a route group with a common prefix.
312312
* All routes created in the passed callback will have the given group prefix prepended.
313-
* @param string $prefix
313+
* @param string $prefix
314314
* @param \Closure $callback
315-
* @param array $middleware
316-
* @param array $opts
315+
* @param array $middleware
316+
* @param array $opts
317317
*/
318318
public function group(string $prefix, \Closure $callback, array $middleware = [], array $opts = []): void
319319
{
@@ -382,9 +382,9 @@ protected function appendGroupInfo(Route $route): void
382382
*/
383383
public function match(string $path, string $method = 'GET'): array
384384
{
385-
$path = RouteHelper::formatPath($path, $this->ignoreLastSlash);
385+
$path = RouteHelper::formatPath($path, $this->ignoreLastSlash);
386386
$method = \strtoupper($method);
387-
$sKey = $method . ' ' . $path;
387+
$sKey = $method . ' ' . $path;
388388

389389
// is a static route path
390390
if (isset($this->staticRoutes[$sKey])) {
@@ -445,7 +445,7 @@ protected function matchDynamicRoute(string $path, string $method): array
445445
$fKey = $first = '';
446446
if ($pos = \strpos($path, '/', 1)) {
447447
$first = \substr($path, 1, $pos - 1);
448-
$fKey = $method . ' ' . $first;
448+
$fKey = $method . ' ' . $first;
449449
}
450450

451451
// is a regular dynamic route(the first node is 1th level index key).
@@ -528,8 +528,8 @@ protected function findAllowedMethods(string $path, string $method): array
528528
/**
529529
* Runs the callback for the given request
530530
* @param DispatcherInterface|array $dispatcher
531-
* @param null|string $path
532-
* @param null|string $method
531+
* @param null|string $path
532+
* @param null|string $method
533533
* @return mixed
534534
* @throws \LogicException
535535
* @throws \Throwable
@@ -561,7 +561,7 @@ public function dispatch($dispatcher = null, $path = null, $method = null)
561561

562562
/**
563563
* @param string $name Route name
564-
* @param array $pathVars
564+
* @param array $pathVars
565565
* @return string
566566
*/
567567
public function createUri(string $name, array $pathVars = []): string
@@ -575,7 +575,7 @@ public function createUri(string $name, array $pathVars = []): string
575575

576576
/**
577577
* @param string $name
578-
* @param Route $route
578+
* @param Route $route
579579
*/
580580
public function nameRoute(string $name, Route $route): void
581581
{
@@ -654,7 +654,7 @@ public function getChains(): array
654654
* <b>Traversable</b>
655655
* @since 5.0.0
656656
*/
657-
public function getIterator()
657+
public function getIterator(): \Traversable
658658
{
659659
return new \ArrayIterator($this->getRoutes());
660660
}
@@ -672,8 +672,8 @@ public function __toString(): string
672672
*/
673673
public function toString(): string
674674
{
675-
$indent = ' ';
676-
$strings = ['#Routes Number: ' . $this->count()];
675+
$indent = ' ';
676+
$strings = ['#Routes Number: ' . $this->count()];
677677
$strings[] = "\n#Static Routes:";
678678
/** @var Route $route */
679679
foreach ($this->staticRoutes as $route) {

test/RouterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Inhere\Route\Router;
77
use PHPUnit\Framework\TestCase;
88
use function Inhere\Route\createRouter;
9-
use Inhere\Route\Example\Controllers\DemoController;
9+
use Inhere\RouteTest\controllers\DemoController;
1010

1111
class RouterTest extends TestCase
1212
{
@@ -287,7 +287,7 @@ public function testMatchAutoRoute(): void
287287
// enable autoRoute
288288
// you can access '/demo' '/admin/user/info', Don't need to configure any route
289289
'autoRoute' => true,
290-
'controllerNamespace' => 'Inhere\Route\Example\Controllers',
290+
'controllerNamespace' => 'Inhere\RouteTest\controllers',
291291
'controllerSuffix' => 'Controller',
292292
]);
293293

@@ -301,7 +301,7 @@ public function testMatchAutoRoute(): void
301301
[$status, $path, $route] = $router->match('/admin/user/info');
302302
$this->assertSame(Router::FOUND, $status);
303303
$this->assertSame('/admin/user/info', $path);
304-
$this->assertSame('Inhere\Route\Example\Controllers\admin\UserController@info', $route->getHandler());
304+
$this->assertSame('Inhere\RouteTest\controllers\admin\UserController@info', $route->getHandler());
305305

306306
[$status, $path,] = $router->match('/not-exist');
307307
$this->assertSame(Router::NOT_FOUND, $status);

test/boot.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
$libDir = dirname(__DIR__);
2020
$npMap = [
21-
'Inhere\Route\Example\\' => $libDir . '/example/',
2221
'Inhere\RouteTest\\' => $libDir . '/test/',
2322
'Inhere\Route\\' => $libDir . '/src/',
2423
];

example/Controllers/DemoController.php renamed to test/controllers/DemoController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* Time: 上午12:14
77
*/
88

9-
namespace Inhere\Route\Example\Controllers;
9+
namespace Inhere\RouteTest\controllers;
1010

1111
/**
1212
* Class DemoController
13-
* @package Inhere\Route\Example\Controllers
13+
* @package Inhere\RouteTest\controllers
1414
*/
1515
class DemoController
1616
{

0 commit comments

Comments
 (0)