Passed
Pull Request — 4 (#10016)
by
unknown
07:28
created

DatabaselessKernel   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 49
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setBootErrorHandling() 0 4 1
A boot() 0 10 1
A isFlushed() 0 3 1
1
<?php
2
3
namespace SilverStripe\Core;
4
5
use Exception;
6
7
/**
8
 * Boot a kernel without requiring a database connection.
9
 * This is a workaround for the lack of composition in the boot stages
10
 * of CoreKernel, as well as for the framework's misguided assumptions
11
 * around the availability of a database for every execution path.
12
 *
13
 * @internal
14
 */
15
class DatabaselessKernel extends BaseKernel
16
{
17
    protected $queryErrorMessage = 'Booted with DatabaseLessKernel, cannot execute query: %s';
18
19
    /**
20
     * Indicates whether the Kernel has been flushed on boot
21
     * Uninitialised before boot
22
     *
23
     * @var bool
24
     */
25
    private $flush;
26
27
    /**
28
     * Allows disabling of the configured error handling.
29
     * This can be useful to ensure the execution context (e.g. composer)
30
     * can consistently use its own error handling.
31
     *
32
     * @var boolean
33
     */
34
    protected $bootErrorHandling = true;
35
36
    public function setBootErrorHandling(bool $bool)
37
    {
38
        $this->bootErrorHandling = $bool;
39
        return $this;
40
    }
41
42
    /**
43
     * @param false $flush
44
     * @throws Exception
45
     */
46
    public function boot($flush = false)
47
    {
48
        $this->flush = $flush;
49
50
        $this->bootPHP();
51
        $this->bootManifests($flush);
52
        $this->bootErrorHandling();
53
        $this->bootConfigs();
54
55
        $this->setBooted(true);
56
    }
57
58
    /**
59
     * @return bool
60
     */
61
    public function isFlushed()
62
    {
63
        return $this->flush;
64
    }
65
}
66