Completed
Push — master ( cea9b4...a629b9 )
by ARCANEDEV
13:47
created

ApplicationInfoComposer::compose()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 1
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Arcanesoft\Foundation\ViewComposers\System;
2
3
use FilesystemIterator;
4
use Illuminate\View\View;
5
use RecursiveDirectoryIterator;
6
use RecursiveIteratorIterator;
7
8
/**
9
 * Class     ApplicationInfoComposer
10
 *
11
 * @package  Arcanesoft\Foundation\ViewComposers\System
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class ApplicationInfoComposer
15
{
16
    /* -----------------------------------------------------------------
17
     |  Constants
18
     | -----------------------------------------------------------------
19
     */
20
    const VIEW = 'foundation::admin.system.information._includes.application';
21
22
    /* -----------------------------------------------------------------
23
     |  Main Methods
24
     | -----------------------------------------------------------------
25
     */
26
    /**
27
     * Compose the view.
28
     *
29
     * @param  \Illuminate\View\View  $view
30
     */
31
    public function compose(View $view)
32
    {
33
        $app = app();
34
35
        $view->with('application', [
36
            'url'                 => config('app.url'),
37
            'locale'              => strtoupper(config('app.locale')),
38
            'timezone'            => config('app.timezone'),
39
            'debug_mode'          => config('app.debug', false),
40
            'maintenance_mode'    => $app->isDownForMaintenance(),
41
            'arcanesoft_version'  => foundation()->version(),
42
            'laravel_version'     => $app->version(),
43
            'app_size'            => $this->getApplicationSize(),
44
            'database_connection' => config('database.default'),
45
            'cache_driver'        => config('cache.default'),
46
            'session_driver'      => config('session.driver')
47
        ]);
48
    }
49
50
    /* -----------------------------------------------------------------
51
     |  Other Methods
52
     | -----------------------------------------------------------------
53
     */
54
    /**
55
     * Get the application size.
56
     *
57
     * @return string
58
     */
59
    private function getApplicationSize()
60
    {
61
        $iterator = new RecursiveDirectoryIterator(base_path(), FilesystemIterator::SKIP_DOTS);
62
63
        $size = 0;
64
65
        foreach (new RecursiveIteratorIterator($iterator) as $object) {
66
            $size += $object->getSize();
67
        }
68
69
        return $this->formatSize($size);
70
    }
71
72
    /**
73
     * Format the size for humans.
74
     *
75
     * @param  int  $bytes
76
     *
77
     * @return string
78
     */
79
    private function formatSize($bytes)
80
    {
81
        $kb = 1024;
82
        $mb = $kb * 1024;
83
        $gb = $mb * 1024;
84
        $tb = $gb * 1024;
85
86
        if (($bytes >= 0) && ($bytes < $kb)) {
87
            return $bytes . ' B';
88
        }
89
        elseif (($bytes >= $kb) && ($bytes < $mb)) {
90
            return ceil($bytes / $kb).' KB';
91
        }
92
        elseif (($bytes >= $mb) && ($bytes < $gb)) {
93
            return ceil($bytes / $mb).' MB';
94
        }
95
        elseif (($bytes >= $gb) && ($bytes < $tb)) {
96
            return ceil($bytes / $gb).' GB';
97
        }
98
        elseif ($bytes >= $tb) {
99
            return ceil($bytes / $tb).' TB';
100
        }
101
102
        return $bytes.' B';
103
    }
104
}
105