From 745cf2431a71d0e6c5f08f8605839279b2f7496e Mon Sep 17 00:00:00 2001 From: Devian Date: Thu, 22 Apr 2021 17:03:46 +0800 Subject: Initiate commit --- src/ScormServiceProvider.php | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/ScormServiceProvider.php (limited to 'src/ScormServiceProvider.php') diff --git a/src/ScormServiceProvider.php b/src/ScormServiceProvider.php new file mode 100644 index 0000000..1806775 --- /dev/null +++ b/src/ScormServiceProvider.php @@ -0,0 +1,62 @@ +app->bind('scorm-manager', function($app) { + return new ScormManager(); + }); + } + + public function boot() + { + $this->offerPublishing(); + } + + protected function offerPublishing() { + // function not available and 'publish' not relevant in Lumen + if (! function_exists('config_path')) { + return; + } + + $this->publishes([ + __DIR__.'/../config/scorm.php' => config_path('scorm.php'), + ], 'config'); + + $this->publishes([ + __DIR__.'/../database/migrations/create_scorm_tables.php.stub' => $this->getMigrationFileName('create_scorm_tables.php'), + ], 'migrations'); + } + + /** + * Returns existing migration file if found, else uses the current timestamp. + * + * @return string + */ + protected function getMigrationFileName($migrationFileName): string + { + $timestamp = date('Y_m_d_His'); + + $filesystem = $this->app->make(Filesystem::class); + + return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) + ->flatMap(function ($path) use ($filesystem) { + return $filesystem->glob($path.'*_create_scorm_tables.php'); + })->push($this->app->databasePath()."/migrations/{$timestamp}_create_scorm_tables.php") + ->flatMap(function ($path) use ($filesystem, $migrationFileName) { + return $filesystem->glob($path.'*_'.$migrationFileName); + }) + ->push($this->app->databasePath()."/migrations/{$timestamp}_{$migrationFileName}") + ->first(); + } +} -- cgit v1.2.3