Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
haroon-mahmood-4276 committed Feb 11, 2023
0 parents commit 25a21f2
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .gitignore
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
21 changes: 21 additions & 0 deletions LICENSE
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.
37 changes: 37 additions & 0 deletions README.md
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).
32 changes: 32 additions & 0 deletions composer.json
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
}
18 changes: 18 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions src/CommandEventServiceProvider.php
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();
}
}
18 changes: 18 additions & 0 deletions src/CommandHistoryServiceProvider.php
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()
{
}
}
35 changes: 35 additions & 0 deletions src/Listeners/ArtisanCommandFinishedListener.php
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);
}
}
}
}
21 changes: 21 additions & 0 deletions src/Listeners/ArtisanCommandStartingListener.php
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)
{

}
}
23 changes: 23 additions & 0 deletions src/Models/CommandHistory.php
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',
];
}
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');
}
};

0 comments on commit 25a21f2

Please sign in to comment.