summaryrefslogtreecommitdiff
path: root/src/ScormServiceProvider.php
diff options
context:
space:
mode:
authorDevian <devianleong@gmail.com>2021-04-22 17:03:46 +0800
committerDevian <devianleong@gmail.com>2021-04-22 17:03:46 +0800
commit745cf2431a71d0e6c5f08f8605839279b2f7496e (patch)
tree11e4c7a19ac9f9efc1bb253b29b1fa488c34238e /src/ScormServiceProvider.php
Initiate commit
Diffstat (limited to 'src/ScormServiceProvider.php')
-rw-r--r--src/ScormServiceProvider.php62
1 files changed, 62 insertions, 0 deletions
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 @@
+<?php
+
+
+namespace Peopleaps\Scorm;
+
+
+use Illuminate\Filesystem\Filesystem;
+use Illuminate\Support\Collection;
+use Illuminate\Support\ServiceProvider;
+use Peopleaps\Scorm\Manager\ScormManager;
+
+class ScormServiceProvider extends ServiceProvider
+{
+ public function register()
+ {
+ $this->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();
+ }
+}