Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Foundation;
4
 
5
use Closure;
6
 
7
class EnvironmentDetector
8
{
9
    /**
10
     * Detect the application's current environment.
11
     *
12
     * @param  \Closure  $callback
13
     * @param  array|null  $consoleArgs
14
     * @return string
15
     */
16
    public function detect(Closure $callback, $consoleArgs = null)
17
    {
18
        if ($consoleArgs) {
19
            return $this->detectConsoleEnvironment($callback, $consoleArgs);
20
        }
21
 
22
        return $this->detectWebEnvironment($callback);
23
    }
24
 
25
    /**
26
     * Set the application environment for a web request.
27
     *
28
     * @param  \Closure  $callback
29
     * @return string
30
     */
31
    protected function detectWebEnvironment(Closure $callback)
32
    {
33
        return $callback();
34
    }
35
 
36
    /**
37
     * Set the application environment from command-line arguments.
38
     *
39
     * @param  \Closure  $callback
40
     * @param  array  $args
41
     * @return string
42
     */
43
    protected function detectConsoleEnvironment(Closure $callback, array $args)
44
    {
45
        // First we will check if an environment argument was passed via console arguments
46
        // and if it was that automatically overrides as the environment. Otherwise, we
47
        // will check the environment as a "web" request like a typical HTTP request.
48
        if (! is_null($value = $this->getEnvironmentArgument($args))) {
49
            return $value;
50
        }
51
 
52
        return $this->detectWebEnvironment($callback);
53
    }
54
 
55
    /**
56
     * Get the environment argument from the console.
57
     *
58
     * @param  array  $args
59
     * @return string|null
60
     */
61
    protected function getEnvironmentArgument(array $args)
62
    {
63
        foreach ($args as $i => $value) {
64
            if ($value === '--env') {
65
                return $args[$i + 1] ?? null;
66
            }
67
 
68
            if (str_starts_with($value, '--env')) {
69
                return head(array_slice(explode('=', $value), 1));
70
            }
71
        }
72
    }
73
}