Skip to content

Commit c8fb318

Browse files
committed
Added helper methods to help categorize report stats more efficiently
1 parent 13d422f commit c8fb318

File tree

5 files changed

+81
-39
lines changed

5 files changed

+81
-39
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<p align="center">
44
<a href="https://packagist.org/packages/lubusin/laravel-decomposer"><img src="https://poser.pugx.org/lubusin/laravel-decomposer/v/stable" alt="Latest Stable Version"></a>
55
<a href="https://packagist.org/packages/lubusin/laravel-decomposer"><img src="https://poser.pugx.org/lubusin/laravel-decomposer/downloads" alt="Total Downloads"></a>
6-
<a href="https://packagist.org/packages/lubusin/laravel-decomposer"><img src="https://poser.pugx.org/lubusin/laravel-decomposer/license" alt="License"></a>
6+
<a href="https://github.com/lubusin/laravel-decomposer/blob/master/LICENSE.txt"><img src="https://poser.pugx.org/lubusin/laravel-decomposer/license" alt="License"></a>
7+
<a href="https://github.com/lubusin/laravel-decomposer/blob/master/contributing.md"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs"></a>
78
</p>
89

910
## Introduction

changelog.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
All notable changes to the Laravel Decomposer will be documented in this file
22

3+
## v1.2.1 (06-04-2017)
4+
- Added following helper methods to help categorize report stats more efficiently:
5+
6+
```php
7+
Decomposer::addLaravelStats($myArray); // Add to the already existing 'Laravel Env'
8+
Decomposer::addServerStats($myArray); // Add to the already existing 'Server Env'
9+
Decomposer::addExtraStats($myArray); // A new block 'Extra Info' will be added containing it
10+
```
11+
312
## v1.2 (03-04-2017)
413
- Now App & Other Package devs can also [add extra personal package or app specific stats](https://github.com/lubusIN/laravel-decomposer/wiki/Add-your-extra-stats) by using Decomposer as a dependency in their project
514
- `getReportJson()` method added to get the same Decomposer report as JSON

src/Decomposer.php

+57-36
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ class Decomposer
1414
const PACKAGE_NAME = 'lubusin/laravel-decomposer';
1515

1616
/**
17-
* Initialise blank array for extra stats to be added
17+
* Initialise blank arrays for extra stats to be added
1818
* by app or other package devs
1919
*/
2020

21-
public static $extraStats = [];
21+
public static $laravelExtras = [];
2222
public static $serverExtras = [];
23+
public static $extraStats = [];
2324

2425
/**
2526
* Get the Decomposer system report as a PHP array
@@ -51,9 +52,19 @@ public static function addExtraStats(array $extraStatsArray)
5152
self::$extraStats = array_merge(self::$extraStats, $extraStatsArray);
5253
}
5354

55+
/**
56+
* Add Laravel specific stats by app or any other package dev
57+
* @param $serverStatsArray
58+
*/
59+
60+
public static function addLaravelStats(array $laravelStatsArray)
61+
{
62+
self::$laravelExtras = array_merge(self::$laravelExtras, $laravelStatsArray);
63+
}
64+
5465

5566
/**
56-
* Add Server stats by app or any other package dev
67+
* Add Server specific stats by app or any other package dev
5768
* @param $serverStatsArray
5869
*/
5970

@@ -82,6 +93,16 @@ public static function getServerExtras()
8293
return self::$serverExtras;
8394
}
8495

96+
/**
97+
* Get additional laravel info added by the app or any other package dev
98+
* @return array
99+
*/
100+
101+
public static function getLaravelExtras()
102+
{
103+
return self::$laravelExtras;
104+
}
105+
85106
/**
86107
* Get the Decomposer system report as JSON
87108
* @return json
@@ -142,46 +163,15 @@ public static function getPackagesAndDependencies($packagesArray)
142163

143164
public static function getLaravelEnv($decomposerVersion)
144165
{
145-
return [
166+
return array_merge([
146167
'version' => App::version(),
147168
'timezone' => config('app.timezone'),
148169
'debug_mode' => config('app.debug'),
149170
'storage_dir_writable' => is_writable(base_path('storage')),
150171
'cache_dir_writable' => is_writable(base_path('bootstrap/cache')),
151172
'decomposer_version' => $decomposerVersion,
152173
'app_size' => self::sizeFormat(self::folderSize(base_path()))
153-
];
154-
}
155-
156-
/**
157-
* Get current installed Decomposer version
158-
*
159-
* @param $composerArray
160-
* @param $packages
161-
* @return string
162-
*/
163-
164-
public static function getDecomposerVersion($composerArray, $packages)
165-
{
166-
if (isset($composerArray['require'][self::PACKAGE_NAME])) {
167-
return $composerArray['require'][self::PACKAGE_NAME];
168-
}
169-
170-
if (isset($composerArray['require-dev'][self::PACKAGE_NAME])) {
171-
return $composerArray['require-dev'][self::PACKAGE_NAME];
172-
}
173-
174-
foreach ($packages as $package) {
175-
if (isset($package['dependencies'][self::PACKAGE_NAME])) {
176-
return $package['dependencies'][self::PACKAGE_NAME];
177-
}
178-
179-
if (isset($package['dev-dependencies'][self::PACKAGE_NAME])) {
180-
return $package['dev-dependencies'][self::PACKAGE_NAME];
181-
}
182-
}
183-
184-
return 'unknown';
174+
], self::getLaravelExtras());
185175
}
186176

187177
/**
@@ -224,6 +214,37 @@ private static function getPackagesArray($composerRequireArray)
224214
return $packages;
225215
}
226216

217+
/**
218+
* Get current installed Decomposer version
219+
*
220+
* @param $composerArray
221+
* @param $packages
222+
* @return string
223+
*/
224+
225+
public static function getDecomposerVersion($composerArray, $packages)
226+
{
227+
if (isset($composerArray['require'][self::PACKAGE_NAME])) {
228+
return $composerArray['require'][self::PACKAGE_NAME];
229+
}
230+
231+
if (isset($composerArray['require-dev'][self::PACKAGE_NAME])) {
232+
return $composerArray['require-dev'][self::PACKAGE_NAME];
233+
}
234+
235+
foreach ($packages as $package) {
236+
if (isset($package['dependencies'][self::PACKAGE_NAME])) {
237+
return $package['dependencies'][self::PACKAGE_NAME];
238+
}
239+
240+
if (isset($package['dev-dependencies'][self::PACKAGE_NAME])) {
241+
return $package['dev-dependencies'][self::PACKAGE_NAME];
242+
}
243+
}
244+
245+
return 'unknown';
246+
}
247+
227248
/**
228249
* Check if SSL is installed or not
229250
* @return boolean

src/controllers/DecomposerController.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ public function index()
2424

2525
$serverExtras = Decomposer::getServerExtras();
2626

27+
$laravelExtras = Decomposer::getLaravelExtras();
28+
2729
$extraStats = Decomposer::getExtraStats();
2830

29-
return view('Decomposer::index', compact('packages', 'laravelEnv', 'serverEnv', 'extraStats', 'serverExtras'));
31+
return view('Decomposer::index', compact('packages', 'laravelEnv', 'serverEnv', 'extraStats', 'serverExtras', 'laravelExtras'));
3032
}
3133
}

src/views/index.blade.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
- Cache Dir Writable: {!! $laravelEnv['cache_dir_writable'] ? '&#10004;' : '&#10008;' !!}
7676
- Decomposer Version: {{ $laravelEnv['decomposer_version'] }}
7777
- App Size: {{ $laravelEnv['app_size'] }}
78+
@foreach($laravelExtras as $extraStatKey => $extraStatValue)
79+
- {{ $extraStatKey }}: {{ is_bool($extraStatValue) ? ($extraStatValue ? '&#10004;' : '&#10008;') : $extraStatValue }}
80+
@endforeach
7881

7982
### Server Environment
8083

@@ -91,7 +94,7 @@
9194
- Tokenizer Ext: {!! $serverEnv['tokenizer'] ? '&#10004;' : '&#10008;'!!}
9295
- XML Ext: {!! $serverEnv['xml'] ? '&#10004;' : '&#10008;' !!}
9396
@foreach($serverExtras as $extraStatKey => $extraStatValue)
94-
- {{ $extraStatKey }} : {{ is_bool($extraStatValue) ? ($extraStatValue ? '&#10004;' : '&#10008;') : $extraStatValue }}
97+
- {{ $extraStatKey }}: {{ is_bool($extraStatValue) ? ($extraStatValue ? '&#10004;' : '&#10008;') : $extraStatValue }}
9598
@endforeach
9699

97100
### Installed Packages &amp; their version numbers
@@ -166,6 +169,9 @@
166169
<li class="list-group-item">Cache Dir Writable: {!! $laravelEnv['cache_dir_writable'] ? '<span class="glyphicon glyphicon-ok"></span>' : '<span class="glyphicon glyphicon-remove"></span>' !!}</li>
167170
<li class="list-group-item">Decomposer Version: {{ $laravelEnv['decomposer_version'] }}</li>
168171
<li class="list-group-item">App Size: {{ $laravelEnv['app_size'] }}</li>
172+
@foreach($laravelExtras as $extraStatKey => $extraStatValue)
173+
<li class="list-group-item">{{ $extraStatKey }}: {!! is_bool($extraStatValue) ? ($extraStatValue ? '<span class="glyphicon glyphicon-ok"></span>' : '<span class="glyphicon glyphicon-remove"></span>') : $extraStatValue !!}</li>
174+
@endforeach
169175
</ul>
170176
</div>
171177

@@ -187,6 +193,9 @@
187193
<li class="list-group-item">Mbstring Ext: {!! $serverEnv['mbstring'] ? '<span class="glyphicon glyphicon-ok"></span>' : '<span class="glyphicon glyphicon-remove"></span>' !!}</li>
188194
<li class="list-group-item">Tokenizer Ext: {!! $serverEnv['tokenizer'] ? '<span class="glyphicon glyphicon-ok"></span>' : '<span class="glyphicon glyphicon-remove"></span>'!!}</li>
189195
<li class="list-group-item">XML Ext: {!! $serverEnv['xml'] ? '<span class="glyphicon glyphicon-ok"></span>' : '<span class="glyphicon glyphicon-remove"></span>' !!}</li>
196+
@foreach($serverExtras as $extraStatKey => $extraStatValue)
197+
<li class="list-group-item">{{ $extraStatKey }}: {!! is_bool($extraStatValue) ? ($extraStatValue ? '<span class="glyphicon glyphicon-ok"></span>' : '<span class="glyphicon glyphicon-remove"></span>') : $extraStatValue !!}</li>
198+
@endforeach
190199
</ul>
191200
</div>
192201

0 commit comments

Comments
 (0)