diff --git a/README.md b/README.md index b567aef..1065bc9 100644 --- a/README.md +++ b/README.md @@ -10,32 +10,6 @@ The **icanboogie/bind-http** package binds [icanboogie/http][] to [ICanBoogie][] -## Prototype methods - -The following prototype methods are defined, the [ApplicationBindings][] trait may be used for type -hinting: - -- `ICanBoogie\Application::get_initial_request`: Returns the initial request. -- `ICanBoogie\Application::get_request`: Returns the current request. - -The following example demonstrates how this getters may be used: - -```php -initial_request; -$request = $app->request; -``` - - - - ---------- @@ -54,6 +28,5 @@ test suite. Alternatively, run `make test-coverage` to run the test suite with t -[ApplicationBindings]: lib/ApplicationBindings.php [ICanBoogie]: https://icanboogie.org/ [icanboogie/http]: https://github.com/ICanBoogie/HTTP diff --git a/composer.json b/composer.json index a2eafa2..3a926f8 100644 --- a/composer.json +++ b/composer.json @@ -43,10 +43,7 @@ }, "extra": { "icanboogie": { - "config-path": "config", - "config-constructor": { - "http_dispatchers": "ICanBoogie\\Binding\\HTTP\\Hooks::synthesize_dispatchers_config#http" - } + "config-path": "config" } }, "scripts": { diff --git a/config/prototype.php b/config/prototype.php deleted file mode 100644 index e288e19..0000000 --- a/config/prototype.php +++ /dev/null @@ -1,19 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ICanBoogie\Binding\HTTP; - -use ICanBoogie\Application; -use ICanBoogie\Binding\Prototype\ConfigBuilder; - -return fn(ConfigBuilder $config) => $config - ->bind(Application::class, 'get_initial_request', [ Hooks::class, 'app_get_initial_request' ]) - ->bind(Application::class, 'get_request', [ Hooks::class, 'app_get_request' ]); diff --git a/config/services.yml b/config/services.yml index cf53940..4a414f3 100644 --- a/config/services.yml +++ b/config/services.yml @@ -3,10 +3,10 @@ services: autowire: true ICanBoogie\HTTP\Responder: - alias: ICanBoogie\HTTP\Responder\WithProvider + alias: ICanBoogie\HTTP\Responder\DelegateToProvider public: true - ICanBoogie\HTTP\Responder\WithProvider: ~ + ICanBoogie\HTTP\Responder\DelegateToProvider: ~ ICanBoogie\HTTP\Responder\WithEvent: decorates: ICanBoogie\HTTP\Responder diff --git a/lib/ApplicationBindings.php b/lib/ApplicationBindings.php deleted file mode 100644 index 9f17e46..0000000 --- a/lib/ApplicationBindings.php +++ /dev/null @@ -1,26 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ICanBoogie\Binding\HTTP; - -use ICanBoogie\HTTP\Request; - -/** - * @property-read Request $initial_request The initial request. - * @property-read Request $request The current request. - * - * @see \ICanBoogie\Binding\HTTP\Hooks::app_get_initial_request() - * @see \ICanBoogie\Binding\HTTP\Hooks::app_get_request() - */ -trait ApplicationBindings -{ - -} diff --git a/lib/Hooks.php b/lib/Hooks.php deleted file mode 100644 index ac7d6f9..0000000 --- a/lib/Hooks.php +++ /dev/null @@ -1,121 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ICanBoogie\Binding\HTTP; - -use ICanBoogie\Application; -use ICanBoogie\HTTP; -use ICanBoogie\HTTP\Dispatcher; -use ICanBoogie\HTTP\DispatcherProvider; -use ICanBoogie\HTTP\Request; - -use function array_merge; -use function array_walk; -use function ICanBoogie\sort_by_weight; -use function is_string; -use function trigger_error; - -final class Hooks -{ - /* - * Autoconfig - */ - - static public function synthesize_dispatchers_config(array $fragments): array - { - trigger_error("OBSOLETE: Use the responder instead."); - - $config_array = []; - - foreach ($fragments as $fragment) - { - $config_array[] = $fragment['dispatchers'] ?? []; - } - - $config = array_merge(...$config_array); - - # - # Normalizing - # - - array_walk($config, function(&$config): void { - - if (is_string($config)) - { - $config = [ DispatcherConfig::CONSTRUCTOR => $config, ]; - } - - $config += [ DispatcherConfig::WEIGHT => 0 ]; - - }); - - # - # Ordering - # - - return sort_by_weight($config, function($config) { - - return $config[DispatcherConfig::WEIGHT]; - - }); - } - - /* - * Prototype - */ - - /** - * Returns the initial request object. - * - * @return Request - */ - static public function app_get_initial_request(): Request - { - return HTTP\get_initial_request(); - } - - /** - * Returns the current request. - */ - static public function app_get_request(Application $app): Request - { - return Request::get_current_request() ?: $app->initial_request; - } - - /** - * Returns the request dispatcher. - */ - static public function app_get_dispatcher(): Dispatcher - { - trigger_error("OBSOLETE: Use the responder instead."); - - return HTTP\get_dispatcher(); - } - - /* - * Event - */ - - /** - * Defines the request dispatcher provider. - */ - static public function on_app_configure(Application\ConfigureEvent $event, Application $app): void - { - trigger_error("OBSOLETE: Use the responder instead."); - - if (DispatcherProvider::defined()) - { - return; - } - - DispatcherProvider::define(new ProvideDispatcher($app)); - } -} diff --git a/tests/lib/HooksTest.php b/tests/lib/HooksTest.php deleted file mode 100644 index d251a4a..0000000 --- a/tests/lib/HooksTest.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Test\ICanBoogie\Binding\HTTP; - -use ICanBoogie\Binding\HTTP\Hooks; -use ICanBoogie\HTTP\Request; -use PHPUnit\Framework\TestCase; - -use function ICanBoogie\app; - -final class HooksTest extends TestCase -{ - public function test_get_initial_request(): void - { - $initial_request = Hooks::app_get_initial_request(); - - $this->assertInstanceOf(Request::class, $initial_request); - $this->assertSame($initial_request, app()->initial_request); - } - - public function test_get_request(): void - { - $request = Hooks::app_get_request(app()); - - $this->assertInstanceOf(Request::class, $request); - $this->assertSame($request, app()->request); - } -}