-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 25a21f2
Showing
11 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/node_modules | ||
/public/build | ||
/public/hot | ||
/public/storage | ||
/storage/*.key | ||
/vendor | ||
.env | ||
.env.backup | ||
.env.production | ||
.phpunit.result.cache | ||
Homestead.json | ||
Homestead.yaml | ||
auth.json | ||
npm-debug.log | ||
yarn-error.log | ||
/.fleet | ||
/.idea | ||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Haroon Mahmood | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Laravel commands history | ||
A simple Laravel package to store every artisan command history with arguments and options in database. | ||
|
||
## Installation | ||
```shell | ||
composer require haroon-mahmood-4276/laravel-commands-history | ||
``` | ||
|
||
Laravel uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider. | ||
|
||
If laravel's auto-discovery doesn't work, add following lines in ```providers``` array in ```config/app.php``` | ||
```shell | ||
/* | ||
* Package Service Providers... | ||
*/ | ||
... | ||
|
||
HaroonMahmood4276\LaravelCommandsHistory\CommandHistoryServiceProvider::class, | ||
HaroonMahmood4276\LaravelCommandsHistory\CommandEventServiceProvider::class, | ||
... | ||
``` | ||
|
||
## Migration | ||
```shell | ||
php artisan migrate | ||
``` | ||
|
||
## Want to contribute | ||
- Fork this repo. | ||
- Contribute in it. | ||
- Open a pull request. | ||
|
||
## Security Vulnerabilities | ||
If you discover a security vulnerability within package, please send an e-mail to Haroon Mahmood via [email protected]. All security vulnerabilities will be promptly addressed. | ||
|
||
## License | ||
This package is open-sourced software licensed under the [MIT license](https://github.com/haroon-mahmood-4276/laravel-commands-history/blob/v1.0.0/LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "haroon-mahmood-4276/laravel-commands-history", | ||
"description": "This package is to store command history in the database", | ||
"type": "library", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"HaroonMahmood4276\\LaravelCommandsHistory\\": "src/" | ||
} | ||
}, | ||
"authors": [{ | ||
"name": "haroon-mahmood-4276", | ||
"email": "[email protected]", | ||
"role": "Developer" | ||
}], | ||
"require": { | ||
"php": ">=8.0" | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"HaroonMahmood4276\\LaravelCommandsHistory\\CommandHistoryServiceProvider", | ||
"HaroonMahmood4276\\LaravelCommandsHistory\\CommandEventServiceProvider" | ||
] | ||
} | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"minimum-stability": "stable", | ||
"prefer-stable": true | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace HaroonMahmood4276\LaravelCommandsHistory; | ||
|
||
use HaroonMahmood4276\LaravelCommandsHistory\Listeners\ArtisanCommandFinishedListener; | ||
use HaroonMahmood4276\LaravelCommandsHistory\Listeners\ArtisanCommandStartingListener; | ||
use Illuminate\Console\Events\CommandFinished; | ||
use Illuminate\Console\Events\CommandStarting; | ||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; | ||
|
||
class CommandEventServiceProvider extends ServiceProvider | ||
{ | ||
protected $listen = [ | ||
CommandStarting::class => [ | ||
ArtisanCommandStartingListener::class | ||
], | ||
CommandFinished::class => [ | ||
ArtisanCommandFinishedListener::class | ||
], | ||
]; | ||
|
||
public function boot() | ||
{ | ||
parent::boot(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace HaroonMahmood4276\LaravelCommandsHistory; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class CommandHistoryServiceProvider extends ServiceProvider | ||
{ | ||
|
||
public function boot() | ||
{ | ||
$this->loadMigrationsFrom(__DIR__ . '/database/migrations'); | ||
} | ||
|
||
public function register() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace HaroonMahmood4276\LaravelCommandsHistory\Listeners; | ||
|
||
use HaroonMahmood4276\LaravelCommandsHistory\Models\CommandHistory; | ||
use Illuminate\Console\Events\CommandFinished; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class ArtisanCommandFinishedListener | ||
{ | ||
/** | ||
* Handle the CommandFinished event. | ||
* | ||
* @param CommandFinished $event | ||
* @return void | ||
*/ | ||
public function handle(CommandFinished $event) | ||
{ | ||
|
||
if (Schema::hasTable('command_histories')) { | ||
|
||
if (!is_null($event->command)) { | ||
|
||
$data = [ | ||
'name' => $event->command, | ||
'exit_code' => $event->exitCode, | ||
'arguments' => $event->input->getArguments(), | ||
'options' => $event->input->getOptions(), | ||
]; | ||
|
||
CommandHistory::create($data); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace HaroonMahmood4276\LaravelCommandsHistory\Listeners; | ||
|
||
use Illuminate\Console\Events\CommandStarting; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class ArtisanCommandStartingListener | ||
{ | ||
/** | ||
* Handle the CommandStarting event. | ||
* | ||
* @param CommandStarting $event | ||
* @return void | ||
*/ | ||
public function handle(CommandStarting $event) | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace HaroonMahmood4276\LaravelCommandsHistory\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class CommandHistory extends Model | ||
{ | ||
protected $dateFormat = 'U'; | ||
|
||
protected $fillable = [ | ||
'name', | ||
'exit_code', | ||
'arguments', | ||
'options', | ||
]; | ||
|
||
protected $casts = [ | ||
'exit_code' => 'integer', | ||
'arguments' => 'array', | ||
'options' => 'array', | ||
]; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/database/migrations/2023_02_09_000002_create_command_histories.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('command_histories', function (Blueprint $table) { | ||
$table->bigIncrements('id'); | ||
$table->string('name')->nullable(); | ||
$table->json('arguments')->nullable(); | ||
$table->json('options')->nullable(); | ||
$table->unsignedInteger('exit_code')->default(0); | ||
$table->integer('created_at')->nullable(); | ||
$table->integer('updated_at')->nullable(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('command_histories'); | ||
} | ||
}; |