GithubHelp home page GithubHelp logo

Comments (2)

scryba avatar scryba commented on May 18, 2024

Better still DatabaseSchedulingServiceProvider should extend Illuminate\Support\ServiceProvider and not DatabaseScheduleApplicationServiceProvider.

DatabaseScheduleApplicationServiceProvider will be extended by the user and defined in config/app.php by the user but not automatically.

it should finally be:

namespace RobersonFaria\DatabaseSchedule;

use Cron\CronExpression;
use RobersonFaria\DatabaseSchedule\Console\Commands\PhpUnitTestJobCommand;
use RobersonFaria\DatabaseSchedule\View\Helpers;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Validator;
use RobersonFaria\DatabaseSchedule\Observer\ScheduleObserver;
use Illuminate\Console\Scheduling\Schedule as BaseSchedule;
use RobersonFaria\DatabaseSchedule\Console\Commands\TestJobCommand;
use RobersonFaria\DatabaseSchedule\Console\Commands\ScheduleClearCacheCommand;
use RobersonFaria\DatabaseSchedule\Console\Scheduling\Schedule;
use Illuminate\Support\ServiceProvider;

class DatabaseSchedulingServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerRoutes();

        Route::model('schedule', config('database-schedule.model'));

        $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');

        $this->loadViewsFrom(__DIR__ . '/../resources/views', 'schedule');

        $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'schedule');

        Validator::extend('cron', function ($attribute, $value, $parameters, $validator) {
            return CronExpression::isValidExpression($value);
        });

        $this->publishes([
            __DIR__ . '/../config/database-schedule.php' => config_path('database-schedule.php'),
        ], 'config');

        $this->publishes([
            __DIR__ . '/../resources/lang/' => resource_path('lang/vendor/schedule'),
        ], 'translates');

        $this->publishes([
            __DIR__ . '/../resources/views' => resource_path('views/vendor/schedule'),
        ], 'views');

        $config = $this->app['config'];

        if ($config->get('database-schedule.cache.enabled')) {
            $model = $config->get('database-schedule.model');
            $model::observe(ScheduleObserver::class);
        }

        if (substr(app()->version(), 0, 1) >= 8) {
            \Illuminate\Pagination\Paginator::useBootstrap();
        }

        $this->app->resolving(BaseSchedule::class, function ($schedule) {
            $schedule = app(Schedule::class, ['schedule' => $schedule]);
            return $schedule->execute();
        });

        $this->commands([
            TestJobCommand::class,
            PhpUnitTestJobCommand::class,
            ScheduleClearCacheCommand::class,
        ]);
    }

    protected function registerRoutes()
    {
        Route::group([
            'prefix' => config('database-schedule.route.prefix'),
            'namespace' => 'RobersonFaria\DatabaseSchedule\Http\Controllers',
            'middleware' => config('database-schedule.middleware', 'web'),
        ], function () {
            $this->loadRoutesFrom(__DIR__ . '/../routes/web.php');
        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->mergeConfigFrom(
            __DIR__ . '/../config/database-schedule.php',
            'database-schedule'
        );

        // @link https://stackoverflow.com/questions/21574413/when-making-a-laravel-package-how-do-i-register-the-service-provider-and-alias
        AliasLoader::getInstance()->alias('Helpers', Helpers::class);
    }

    protected function scheduleTimezone($config)
    {
        return $config->get('schedule.timezone');
    }

    protected function scheduleCache()
    {
        return $_ENV[''] ?? null;
    }
}

from laravel-database-schedule.

robersonfaria avatar robersonfaria commented on May 18, 2024

Hello, unfortunately I'm working on several projects at the moment and I'm not able to give this package enough attention.
Please open a pull request with your suggestion, if possible with automated tests, which I will be happy to approve.

from laravel-database-schedule.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.