Skip to content

Commit 7ab4f66

Browse files
committed
Added env()
1 parent cb3a01a commit 7ab4f66

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

app.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,21 @@
22

33
namespace phpish\app;
44

5+
function env($custom_envs=[])
6+
{
7+
$default_envs = [
8+
'/^127\.0\.0\.1.*/' => 'development',
9+
'/^localhost.*/' => 'development',
10+
'/^.*\.dev$/' => 'development',
11+
'/^dev\..*$/' => 'development',
12+
];
13+
$envs = $custom_envs + $default_envs;
14+
foreach ($envs as $pattern=>$env_name) if (preg_match($pattern, $_SERVER['HTTP_HOST'])) return $env_name;
15+
16+
return 'production';
17+
}
518

19+
//TODO: Deprecate in next major version
620
define(__NAMESPACE__.'\ENV', (
721

822
preg_match('/^127\.0\.0\.1.*/', $_SERVER['HTTP_HOST'])
@@ -63,7 +77,7 @@ function handler($method, $paths, $conds, $funcs)
6377
{
6478
if (!is_array($paths)) $paths = array($paths);
6579
foreach ($paths as $key=>$val) if (!is_int($key)) _named_paths($key, $val);
66-
foreach($funcs as $func) _handlers(_handler_hash($method, $paths, $conds, $func));
80+
foreach ($funcs as $func) _handlers(_handler_hash($method, $paths, $conds, $func));
6781
}
6882

6983
function _named_paths($name=NULL, $path=NULL, $reset=false)

0 commit comments

Comments
 (0)