2014-01-25 4 views

답변

1

이것은 $app->detectEnvironment() 방법 (/bootstrap/start.php)에서 가능하지만 배열을 보내는 대신 닫는 방법을 사용합니다.

$env = $app->detectEnvironment(function(){ 
    // get current http_host 
    $baseurl = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; 

    // our available environment 
    $envs = [ 
     'foo' => ['foo.com', 'bar.foo.com'], 
     'kex' => ['kex.foo.com'] 
    ]; 

    // default environment, you should not change this 
    $environment = 'production'; 

    // search trough each available environment to see if it matched our http_host 
    foreach($envs as $key => $env) { 
     foreach ($env as $url) { 
      if ($url == $baseurl) { 
       $environment = $key; 

       // match found, lets break our loop 
       break 2; 
      } 
     } 
    } 

    // we create segments of /our/path so we can check if it matches your condition 
    $segments = explode('/', isset($_SERVER['REQUEST_URI']) ? trim($_SERVER['REQUEST_URI']) : null); 

    // check if the first (second) segment matches our /path 
    if (isset($segments[1]) && $segments[1] == 'path') 
     return $environment . '-route'; // append -route to our environment and return it 

    return $environment; 
}); 

라인 2 - 24 흉내 내기 Laravel의 기본 방법 (배열 사용). 당신은 그 아래에 있습니다.

관련 문제