ngmy/okuribito-laravel

OkuribitoLaravel can monitor view loading and record it. This helps to remove unused view files.

0.1.0 2019-05-30 12:46 UTC

This package is auto-updated.

Last update: 2024-11-29 05:57:01 UTC


README

Build Status Coverage Status

Latest Stable Version Total Downloads Latest Unstable Version License

OkuribitoLaravel can monitor view loading and record it. This helps to remove unused view files.

This package is inspired by Ruby's Okuribito gem.

Requirements

OkuribitoLaravel has the following requirements:

  • PHP >= 7.1.3
  • Laravel >= 5.5

Installation

Execute the require Composer command:

composer require ngmy/okuribito-laravel

This will update your composer.json file and install this package into the vendor directory.

Migration

Execute the migrate Artisan command:

php artisan migrate

This will create the view_load_logs table in your database.

Publishing Configuration

Execute the vendor:publish Artisan command:

php artisan vendor:publish

This will publish the configuration file to the config/ngmy-okuribito-laravel.php file.

You can also use the tag to execute the command:

php artisan vendor:publish --tag=ngmy-okuribito-laravel

You can also use the service provider to execute the command:

php artisan vendor:publish --provider="Ngmy\OkuribitoLaravel\OkuribitoServiceProvider"

Basic Usage

Update the config/ngmy-okuribito-laravel.php file's monitor_views option to the view you want to monitor loading:

'monitor_views' => 'your.view.foo',

You can also specify multiple views:

'monitor_views' => [
    'your.view.bar',
    'your.view.baz',
],

You can also use a wildcard:

'monitor_views' => 'your.view.*',

This value is specified in the same format as the first argument of Laravel's View::composer method.

When the specified view is loaded, it is recorded to the view_load_logs table in your database.

You have other options available. See the config/ngmy-okuribito-laravel.php file for details.

Advanced Usage

Customizing Record Method

Creating your implementation of the ViewLoadLogRepositoryInterface interface.

<?php
declare(strict_types=1);

namespace Your\Namespace;

use Ngmy\OkuribitoLaravel\Domain\Model\View\View;
use Ngmy\OkuribitoLaravel\Domain\Model\ViewLoadLog\ViewLoadLog;
use Ngmy\OkuribitoLaravel\Domain\Model\ViewLoadLog\ViewLoadLogRepositoryInterface;

class YourViewLoadLogRepository implements ViewLoadLogRepositoryInterface
{
    public function existsByView(View $view): bool
    {
        // Implement your existsByView() method here
    }

    public function save(ViewLoadLog $log): void
    {
        // Implement your save() method here
    }
}

Binding the ViewLoadLogRepositoryInterface interface to your implementation in your service provider's register method.

$this->app->bind(
    \Ngmy\OkuribitoLaravel\Domain\Model\ViewLoadLog\ViewLoadLogRepositoryInterface::class,
    \Your\Namespace\YourViewLoadLogRepository::class
);

License

OkuribitoLaravel is open-sourced software licensed under the MIT license.