1 | <?php |
||
13 | class BasePath |
||
14 | { |
||
15 | const KEY = 'BASE_PATH'; |
||
16 | const KEY_GENERATOR = 'BASE_PATH_GENERATOR'; |
||
17 | |||
18 | use Utils\BasePathTrait; |
||
19 | |||
20 | /** |
||
21 | * @var bool |
||
22 | */ |
||
23 | private $autodetect = false; |
||
24 | |||
25 | /** |
||
26 | * Returns the basePath. |
||
27 | * |
||
28 | * @param ServerRequestInterface $request |
||
29 | * |
||
30 | * @return string|null |
||
31 | */ |
||
32 | public static function getBasePath(ServerRequestInterface $request) |
||
36 | |||
37 | /** |
||
38 | * Returns a callable to build a full path. |
||
39 | * |
||
40 | * @param ServerRequestInterface $request |
||
41 | * |
||
42 | * @return callable|null |
||
43 | */ |
||
44 | public static function getGenerator(ServerRequestInterface $request) |
||
48 | |||
49 | /** |
||
50 | * Constructor. Set the path prefix. |
||
51 | * |
||
52 | * @param string|null $basePath |
||
53 | */ |
||
54 | public function __construct($basePath = null) |
||
60 | |||
61 | /** |
||
62 | * Autodetect the basePath. |
||
63 | * |
||
64 | * @param bool $autodetect |
||
65 | * |
||
66 | * @return self |
||
67 | */ |
||
68 | public function autodetect($autodetect = true) |
||
74 | |||
75 | /** |
||
76 | * Execute the middleware. |
||
77 | * |
||
78 | * @param ServerRequestInterface $request |
||
79 | * @param ResponseInterface $response |
||
80 | * @param callable $next |
||
81 | * |
||
82 | * @return ResponseInterface |
||
83 | */ |
||
84 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
103 | |||
104 | /** |
||
105 | * Auto-detect the base path from the request environment. |
||
106 | * |
||
107 | * Uses a variety of criteria in order to detect the base URL of the request |
||
108 | * (i.e., anything additional to the document root). |
||
109 | * |
||
110 | * This code has been adapted from the Zend implementation: |
||
111 | * https://github.com/zendframework/zend-http/blob/master/src/PhpEnvironment/Request.php |
||
112 | * |
||
113 | * @param ServerRequestInterface $request |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | private static function detectBasePath(ServerRequestInterface $request) |
||
190 | } |
||
191 |