Skip to content

Commit cec1691

Browse files
author
Eric Heinzl
committed
Initial commit
1 parent 56e02d2 commit cec1691

File tree

20 files changed

+5383
-1
lines changed

20 files changed

+5383
-1
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/vendor
2+
/.idea
3+
Homestead.json
4+
Homestead.yaml
5+
.env
6+
.phpunit.result.cache

.styleci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
php:
2+
preset: laravel
3+
disabled:
4+
- unused_use
5+
js: true
6+
css: true

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Eric Heinzl. [eric.heinzl@gmail.com](mailto:eric.heinzl@gmail.com)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
# ValetDashboard
1+
# Valet-Dashboard
22
A simple dashboard for Laravel Valet.
3+
4+
![ValetDashboard Screenshot](resources/assets/valet_dashboard.png?raw=true "ValetDashboard Screenshot")
5+
6+
- **License**: [MIT License](LICENSE.md)
7+
- **GitHub Repository**: <https://github.com/xPand4B/ValetDashboard>
8+
- **Issue Tracker**: <https://github.com/xPand4B/ValetDashboard/issues>
9+
10+
## How to install
11+
Simply run `composer install` and `valet link` inside the root directory!
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class ViewServiceProvider extends ServiceProvider
8+
{
9+
const VALET_PORT = '';
10+
const VALET_XDG_HOME = '/.config/valet';
11+
CONST VALET_OLD_HOME = '/.valet';
12+
const VALET_CONFIG_FILE = '/config.json';
13+
14+
const IGNORED_DIRECTORIES = [
15+
'00-Helper',
16+
'valet',
17+
];
18+
19+
/**
20+
* Bootstrap any application services.
21+
*
22+
* @return void
23+
*/
24+
public function boot()
25+
{
26+
$this->shareValetInfos();
27+
}
28+
29+
/**
30+
* Register the service provider.
31+
*
32+
* @return void
33+
*/
34+
public function register()
35+
{
36+
//
37+
}
38+
39+
/**
40+
* Share valet-infos into view
41+
*/
42+
private function shareValetInfos(): void
43+
{
44+
$valetHomePath = $this->getValetHomePath();
45+
$valetConfig = $this->getValetConfigFileContent($valetHomePath);
46+
$tld = $this->getValetTld($valetConfig);
47+
48+
$valetInfos = [
49+
'tld' => $tld,
50+
'port' => self::VALET_PORT,
51+
'paths' => $this->getSitesFromPaths($valetConfig->paths, $tld)
52+
];
53+
54+
view()->share('valet', $valetInfos);
55+
}
56+
57+
private function getValetHomePath(): string
58+
{
59+
$valet_xdg_home = getenv('HOME') . self::VALET_XDG_HOME;
60+
$valet_old_home = getenv('HOME') . self::VALET_OLD_HOME;
61+
62+
return is_dir($valet_xdg_home) ? $valet_xdg_home : $valet_old_home;
63+
}
64+
65+
/**
66+
* @return mixed
67+
*/
68+
private function getValetConfigFileContent(string $homePath)
69+
{
70+
return json_decode(
71+
file_get_contents($homePath . self::VALET_CONFIG_FILE)
72+
);
73+
}
74+
75+
private function getSitesFromPaths(array $paths, string $tld): array
76+
{
77+
$result = [];
78+
79+
foreach ($paths as $path) {
80+
$trimmedPath = str_replace(getenv('HOME'), '~', $path);
81+
$result[$trimmedPath] = [];
82+
83+
foreach (scandir($path) as $key => $site) {
84+
if (mb_strtolower($site) === 'valetdashboard') {
85+
continue;
86+
}
87+
if ($site == basename(__DIR__)) {
88+
continue;
89+
}
90+
if (!(is_dir("$path/$site") || is_link("$path/$site"))) {
91+
continue;
92+
}
93+
if ($site[0] === '.') {
94+
continue;
95+
}
96+
if (in_array($site, self::IGNORED_DIRECTORIES)) {
97+
continue;
98+
}
99+
100+
if ($site === 'cloud.shopware') {
101+
$tld .= '/admin';
102+
}
103+
104+
$url = 'http://' . $site . '.' . $tld . self::VALET_PORT;
105+
106+
if ($site === 'cloud.shopware') {
107+
$tld = str_replace('/admin', '', $tld);
108+
}
109+
110+
111+
// if ($site === 'swDashboard') {
112+
// $url = 'http://shopware.dashboard';
113+
// }
114+
115+
$result[$trimmedPath][$site] = $url;
116+
}
117+
118+
array_multisort($result[$trimmedPath]);
119+
}
120+
121+
return $result;
122+
}
123+
124+
private function getValetTld($valetConfig): string
125+
{
126+
return $valetConfig->tld ?? $valetConfig->domain;
127+
}
128+
}

bootstrap/app.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
require_once __DIR__.'/../vendor/autoload.php';
4+
5+
(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
6+
dirname(__DIR__)
7+
))->bootstrap();
8+
9+
date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));
10+
11+
/*
12+
|--------------------------------------------------------------------------
13+
| Create The Application
14+
|--------------------------------------------------------------------------
15+
|
16+
| Here we will load the environment and create the application instance
17+
| that serves as the central piece of this framework. We'll use this
18+
| application as an "IoC" container and router for this framework.
19+
|
20+
*/
21+
22+
$app = new Laravel\Lumen\Application(
23+
dirname(__DIR__)
24+
);
25+
26+
// $app->withFacades();
27+
28+
// $app->withEloquent();
29+
30+
/*
31+
|--------------------------------------------------------------------------
32+
| Register Container Bindings
33+
|--------------------------------------------------------------------------
34+
|
35+
| Now we will register a few bindings in the service container. We will
36+
| register the exception handler and the console kernel. You may add
37+
| your own bindings here if you like or you can make another file.
38+
|
39+
*/
40+
41+
//$app->singleton(
42+
// Illuminate\Contracts\Debug\ExceptionHandler::class,
43+
// App\Exceptions\Handler::class
44+
//);
45+
//
46+
//$app->singleton(
47+
// Illuminate\Contracts\Console\Kernel::class,
48+
// App\Console\Kernel::class
49+
//);
50+
51+
/*
52+
|--------------------------------------------------------------------------
53+
| Register Config Files
54+
|--------------------------------------------------------------------------
55+
|
56+
| Now we will register the "app" configuration file. If the file exists in
57+
| your configuration directory it will be loaded; otherwise, we'll load
58+
| the default version. You may register other files below as needed.
59+
|
60+
*/
61+
62+
$app->configure('app');
63+
64+
/*
65+
|--------------------------------------------------------------------------
66+
| Register Middleware
67+
|--------------------------------------------------------------------------
68+
|
69+
| Next, we will register the middleware with the application. These can
70+
| be global middleware that run before and after each request into a
71+
| route or middleware that'll be assigned to some specific routes.
72+
|
73+
*/
74+
75+
// $app->middleware([
76+
// App\Http\Middleware\ExampleMiddleware::class
77+
// ]);
78+
79+
// $app->routeMiddleware([
80+
// 'auth' => App\Http\Middleware\Authenticate::class,
81+
// ]);
82+
83+
/*
84+
|--------------------------------------------------------------------------
85+
| Register Service Providers
86+
|--------------------------------------------------------------------------
87+
|
88+
| Here we will register all of the application's service providers which
89+
| are used to bind services into the container. Service providers are
90+
| totally optional, so you are not required to uncomment this line.
91+
|
92+
*/
93+
94+
$app->register(App\Providers\ViewServiceProvider::class);
95+
// $app->register(App\Providers\AuthServiceProvider::class);
96+
// $app->register(App\Providers\EventServiceProvider::class);
97+
98+
/*
99+
|--------------------------------------------------------------------------
100+
| Load The Application Routes
101+
|--------------------------------------------------------------------------
102+
|
103+
| Next we will include the routes file so that they can all be added to
104+
| the application. This will provide all of the URLs the application
105+
| can respond to, as well as the controllers that may handle them.
106+
|
107+
*/
108+
109+
$app->router->group([
110+
'namespace' => 'App\Http\Controllers',
111+
], function ($router) {
112+
require __DIR__.'/../routes/web.php';
113+
});
114+
115+
return $app;

composer.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "xpand4b/valet-dashboard",
3+
"description": "A simple dashboard for Laravel Valet.",
4+
"version": "1.0.0",
5+
"type": "project",
6+
"keywords": [
7+
"framework",
8+
"laravel",
9+
"lumen",
10+
"valet",
11+
"valet+",
12+
"dashboard"
13+
],
14+
"authors": [
15+
{
16+
"name": "Eric Heinzl",
17+
"email": "xpand.4beatz@gmail.com",
18+
"homepage": "https://xpand4b.de",
19+
"role": "Developer"
20+
}
21+
],
22+
"license": "MIT",
23+
"require": {
24+
"php": "^7.3|^8.0",
25+
"laravel/lumen-framework": "^8.0",
26+
"ext-json": "*"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"App\\": "app/"
31+
}
32+
},
33+
"config": {
34+
"preferred-install": "dist",
35+
"sort-packages": true,
36+
"optimize-autoloader": true
37+
},
38+
"minimum-stability": "dev",
39+
"prefer-stable": true,
40+
"scripts": {
41+
"post-root-package-install": [
42+
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
43+
]
44+
}
45+
}

0 commit comments

Comments
 (0)