diff --git a/packages/framework/src/Framework/Features/Session/Session.php b/packages/framework/src/Framework/Features/Session/Session.php new file mode 100644 index 00000000000..cb72d8fd300 --- /dev/null +++ b/packages/framework/src/Framework/Features/Session/Session.php @@ -0,0 +1,33 @@ +addWarning('warning'); + */ +class Session +{ + protected array $warnings = []; + + public function addWarning(string $warning): void + { + $this->warnings[] = $warning; + } + + public function getWarnings(): array + { + return $this->warnings; + } + + public function hasWarnings(): bool + { + return ! empty($this->warnings); + } +} diff --git a/packages/framework/src/Framework/Features/Session/SessionServiceProvider.php b/packages/framework/src/Framework/Features/Session/SessionServiceProvider.php new file mode 100644 index 00000000000..aae696831c9 --- /dev/null +++ b/packages/framework/src/Framework/Features/Session/SessionServiceProvider.php @@ -0,0 +1,20 @@ +app->singleton(Session::class, Session::class); + } + + public function boot() + { + // + } +} diff --git a/packages/framework/src/Framework/HydeServiceProvider.php b/packages/framework/src/Framework/HydeServiceProvider.php index 97b63a88ff6..a793558d5b7 100644 --- a/packages/framework/src/Framework/HydeServiceProvider.php +++ b/packages/framework/src/Framework/HydeServiceProvider.php @@ -8,6 +8,7 @@ use Hyde\Foundation\HydeKernel; use Hyde\Framework\Concerns\RegistersFileLocations; use Hyde\Framework\Features\DataCollections\DataCollectionServiceProvider; +use Hyde\Framework\Features\Session\SessionServiceProvider; use Hyde\Framework\Services\AssetService; use Hyde\Framework\Services\YamlConfigurationService; use Hyde\Framework\Views\Components\LinkComponent; @@ -109,6 +110,7 @@ protected function initializeConfiguration() */ protected function registerModuleServiceProviders(): void { + $this->app->register(SessionServiceProvider::class); $this->app->register(HydeConsoleServiceProvider::class); $this->app->register(DataCollectionServiceProvider::class); } diff --git a/packages/framework/tests/Framework/Feature/SessionTest.php b/packages/framework/tests/Framework/Feature/SessionTest.php new file mode 100644 index 00000000000..a8de95fbff2 --- /dev/null +++ b/packages/framework/tests/Framework/Feature/SessionTest.php @@ -0,0 +1,45 @@ +assertInstanceOf(Session::class, $this->app->make(Session::class)); + $this->assertSame(app(Session::class), $this->app->make(Session::class)); + } + + public function test_session_can_add_warning() + { + app(Session::class)->addWarning('warning'); + + $this->assertSame(['warning'], app(Session::class)->getWarnings()); + } + + public function test_session_is_not_persisted() + { + $this->assertSame([], app(Session::class)->getWarnings()); + } + + public function test_session_can_check_if_warnings_are_present() + { + $session = app(Session::class); + + $this->assertFalse($session->hasWarnings()); + + $session->addWarning('warning'); + + $this->assertTrue($session->hasWarnings()); + } +}