From 37cb76c6735fcb5838e488a792edcfbe132a007f Mon Sep 17 00:00:00 2001 From: Patrick Stewart Date: Sat, 15 Jun 2024 10:36:26 -0700 Subject: [PATCH] update: updating files with ported code --- .../lib/src/broadcasting/broadcaster.dart | 36 ++++ .../lib/src/broadcasting/factory.dart | 10 + .../broadcasting/has_broadcast_channel.dart | 12 ++ .../src/broadcasting/should_be_unique.dart | 4 + .../src/broadcasting/should_broadcast.dart | 6 + .../broadcasting/should_broadcast_now.dart | 5 + .../contracts/lib/src/bus/dispatcher.dart | 47 +++++ .../lib/src/bus/queueing_dispatcher.dart | 25 +++ packages/contracts/lib/src/cache/factory.dart | 9 + packages/contracts/lib/src/cache/lock.dart | 29 +++ .../lib/src/cache/lock_provider.dart | 20 ++ .../lib/src/cache/lock_timeout_exception.dart | 11 ++ .../contracts/lib/src/cache/repository.dart | 96 +++++++++ packages/contracts/lib/src/cache/store.dart | 67 +++++++ .../contracts/lib/src/config/repository.dart | 40 ++++ .../lib/src/console/application.dart | 17 ++ .../contracts/lib/src/console/isolatable.dart | 4 + .../contracts/lib/src/console/kernel.dart | 51 +++++ .../console/prompts_for_missing_input.dart | 3 + .../binding_resolution_exception.dart | 12 ++ .../circular_dependency_exception.dart | 12 ++ .../lib/src/container/container.dart | 183 ++++++++++++++++++ .../container/contextual_binding_builder.dart | 23 +++ 23 files changed, 722 insertions(+) diff --git a/packages/contracts/lib/src/broadcasting/broadcaster.dart b/packages/contracts/lib/src/broadcasting/broadcaster.dart index e69de29..1bccc69 100644 --- a/packages/contracts/lib/src/broadcasting/broadcaster.dart +++ b/packages/contracts/lib/src/broadcasting/broadcaster.dart @@ -0,0 +1,36 @@ +//import 'package:some_http_package/some_http_package.dart'; // Replace with actual HTTP package + +abstract class Broadcaster { + /// Authenticate the incoming request for a given channel. + /// + /// @param Request request + /// @return mixed + Future auth(Request request); + + /// Return the valid authentication response. + /// + /// @param Request request + /// @param mixed result + /// @return mixed + Future validAuthenticationResponse(Request request, dynamic result); + + /// Broadcast the given event. + /// + /// @param List channels + /// @param String event + /// @param Map payload + /// @return void + /// + /// @throws BroadcastException + Future broadcast(List channels, String event, {Map payload = const {}}); +} + +class BroadcastException implements Exception { + final String message; + BroadcastException(this.message); + + @override + String toString() => 'BroadcastException: $message'; +} + +// TODO: Find dart library to replace symfony for Request Class. \ No newline at end of file diff --git a/packages/contracts/lib/src/broadcasting/factory.dart b/packages/contracts/lib/src/broadcasting/factory.dart index e69de29..3d8c3d0 100644 --- a/packages/contracts/lib/src/broadcasting/factory.dart +++ b/packages/contracts/lib/src/broadcasting/factory.dart @@ -0,0 +1,10 @@ + +import 'broadcaster.dart'; + +abstract class Factory { + /// Get a broadcaster implementation by name. + /// + /// @param [name] The name of the broadcaster. + /// @return A [Broadcaster] implementation. + Broadcaster connection([String? name]); +} diff --git a/packages/contracts/lib/src/broadcasting/has_broadcast_channel.dart b/packages/contracts/lib/src/broadcasting/has_broadcast_channel.dart index e69de29..6f1c201 100644 --- a/packages/contracts/lib/src/broadcasting/has_broadcast_channel.dart +++ b/packages/contracts/lib/src/broadcasting/has_broadcast_channel.dart @@ -0,0 +1,12 @@ + +abstract class HasBroadcastChannel { + /// Get the broadcast channel route definition that is associated with the given entity. + /// + /// @return string + String broadcastChannelRoute(); + + /// Get the broadcast channel name that is associated with the given entity. + /// + /// @return string + String broadcastChannel(); +} diff --git a/packages/contracts/lib/src/broadcasting/should_be_unique.dart b/packages/contracts/lib/src/broadcasting/should_be_unique.dart index e69de29..2361d18 100644 --- a/packages/contracts/lib/src/broadcasting/should_be_unique.dart +++ b/packages/contracts/lib/src/broadcasting/should_be_unique.dart @@ -0,0 +1,4 @@ + +abstract class ShouldBeUnique { + // No methods or properties defined; serves as a marker interface +} diff --git a/packages/contracts/lib/src/broadcasting/should_broadcast.dart b/packages/contracts/lib/src/broadcasting/should_broadcast.dart index e69de29..0133c7c 100644 --- a/packages/contracts/lib/src/broadcasting/should_broadcast.dart +++ b/packages/contracts/lib/src/broadcasting/should_broadcast.dart @@ -0,0 +1,6 @@ +abstract class ShouldBroadcast { + /// Get the channels the event should broadcast on. + /// + /// Returns either a single channel or a list of channels. + dynamic broadcastOn(); +} diff --git a/packages/contracts/lib/src/broadcasting/should_broadcast_now.dart b/packages/contracts/lib/src/broadcasting/should_broadcast_now.dart index e69de29..7b45ccf 100644 --- a/packages/contracts/lib/src/broadcasting/should_broadcast_now.dart +++ b/packages/contracts/lib/src/broadcasting/should_broadcast_now.dart @@ -0,0 +1,5 @@ +import 'should_broadcast.dart'; + +abstract class ShouldBroadcastNow implements ShouldBroadcast { + // Additional methods and properties can be added here if needed. +} diff --git a/packages/contracts/lib/src/bus/dispatcher.dart b/packages/contracts/lib/src/bus/dispatcher.dart index e69de29..b847a49 100644 --- a/packages/contracts/lib/src/bus/dispatcher.dart +++ b/packages/contracts/lib/src/bus/dispatcher.dart @@ -0,0 +1,47 @@ +abstract class Dispatcher { + /// Dispatch a command to its appropriate handler. + /// + /// @param dynamic command + /// @return dynamic + dynamic dispatch(dynamic command); + + /// Dispatch a command to its appropriate handler in the current process. + /// + /// Queueable jobs will be dispatched to the "sync" queue. + /// + /// @param dynamic command + /// @param dynamic handler + /// @return dynamic + dynamic dispatchSync(dynamic command, [dynamic handler]); + + /// Dispatch a command to its appropriate handler in the current process. + /// + /// @param dynamic command + /// @param dynamic handler + /// @return dynamic + dynamic dispatchNow(dynamic command, [dynamic handler]); + + /// Determine if the given command has a handler. + /// + /// @param dynamic command + /// @return bool + bool hasCommandHandler(dynamic command); + + /// Retrieve the handler for a command. + /// + /// @param dynamic command + /// @return bool|dynamic + dynamic getCommandHandler(dynamic command); + + /// Set the pipes commands should be piped through before dispatching. + /// + /// @param List pipes + /// @return this + Dispatcher pipeThrough(List pipes); + + /// Map a command to a handler. + /// + /// @param Map map + /// @return this + Dispatcher map(Map map); +} diff --git a/packages/contracts/lib/src/bus/queueing_dispatcher.dart b/packages/contracts/lib/src/bus/queueing_dispatcher.dart index e69de29..b83683a 100644 --- a/packages/contracts/lib/src/bus/queueing_dispatcher.dart +++ b/packages/contracts/lib/src/bus/queueing_dispatcher.dart @@ -0,0 +1,25 @@ +import 'dispatcher.dart'; +import 'batch.dart'; +import 'pending_batch.dart'; + +// TODO: Missing imports will come from other ports refer to original PHP file. + +abstract class QueueingDispatcher implements Dispatcher { + /// Attempt to find the batch with the given ID. + /// + /// @param String batchId + /// @return Batch|null + Future findBatch(String batchId); + + /// Create a new batch of queueable jobs. + /// + /// @param List jobs + /// @return PendingBatch + PendingBatch batch(List jobs); + + /// Dispatch a command to its appropriate handler behind a queue. + /// + /// @param dynamic command + /// @return dynamic + Future dispatchToQueue(dynamic command); +} diff --git a/packages/contracts/lib/src/cache/factory.dart b/packages/contracts/lib/src/cache/factory.dart index e69de29..23c22b7 100644 --- a/packages/contracts/lib/src/cache/factory.dart +++ b/packages/contracts/lib/src/cache/factory.dart @@ -0,0 +1,9 @@ +import 'repository.dart'; + +abstract class Factory { + /// Get a cache store instance by name. + /// + /// @param String? name + /// @return Repository + Repository store([String? name]); +} diff --git a/packages/contracts/lib/src/cache/lock.dart b/packages/contracts/lib/src/cache/lock.dart index e69de29..be1e14e 100644 --- a/packages/contracts/lib/src/cache/lock.dart +++ b/packages/contracts/lib/src/cache/lock.dart @@ -0,0 +1,29 @@ +abstract class Lock { + /// Attempt to acquire the lock. + /// + /// @param Function? callback + /// @return dynamic + Future get([Function? callback]); + + /// Attempt to acquire the lock for the given number of seconds. + /// + /// @param int seconds + /// @param Function? callback + /// @return dynamic + Future block(int seconds, [Function? callback]); + + /// Release the lock. + /// + /// @return bool + Future release(); + + /// Returns the current owner of the lock. + /// + /// @return String + Future owner(); + + /// Releases this lock in disregard of ownership. + /// + /// @return void + Future forceRelease(); +} diff --git a/packages/contracts/lib/src/cache/lock_provider.dart b/packages/contracts/lib/src/cache/lock_provider.dart index e69de29..a87d964 100644 --- a/packages/contracts/lib/src/cache/lock_provider.dart +++ b/packages/contracts/lib/src/cache/lock_provider.dart @@ -0,0 +1,20 @@ +abstract class LockProvider { + /// Get a lock instance. + /// + /// @param String name + /// @param int seconds + /// @param String|null owner + /// @return Lock + Lock lock(String name, {int seconds = 0, String? owner}); + + /// Restore a lock instance using the owner identifier. + /// + /// @param String name + /// @param String owner + /// @return Lock + Lock restoreLock(String name, String owner); +} + +abstract class Lock { + // Define the methods and properties that the Lock class should have +} diff --git a/packages/contracts/lib/src/cache/lock_timeout_exception.dart b/packages/contracts/lib/src/cache/lock_timeout_exception.dart index e69de29..50e8245 100644 --- a/packages/contracts/lib/src/cache/lock_timeout_exception.dart +++ b/packages/contracts/lib/src/cache/lock_timeout_exception.dart @@ -0,0 +1,11 @@ + +class LockTimeoutException implements Exception { + final String message; + + LockTimeoutException([this.message = '']); + + @override + String toString() { + return 'LockTimeoutException: $message'; + } +} diff --git a/packages/contracts/lib/src/cache/repository.dart b/packages/contracts/lib/src/cache/repository.dart index e69de29..2207cd7 100644 --- a/packages/contracts/lib/src/cache/repository.dart +++ b/packages/contracts/lib/src/cache/repository.dart @@ -0,0 +1,96 @@ +import 'package:meta/meta.dart'; +import 'package:psr/simple_cache.dart'; +import 'dart:async'; + +// TODO: Find dart replacements for missing imports. + +abstract class Repository implements CacheInterface { + /// Retrieve an item from the cache and delete it. + /// + /// @template TCacheValue + /// + /// @param List|String key + /// @param TCacheValue|Future Function() default + /// @return Future + Future pull(dynamic key, [dynamic defaultValue]); + + /// Store an item in the cache. + /// + /// @param String key + /// @param dynamic value + /// @param DateTime|Duration|int|null ttl + /// @return Future + Future put(String key, dynamic value, [dynamic ttl]); + + /// Store an item in the cache if the key does not exist. + /// + /// @param String key + /// @param dynamic value + /// @param DateTime|Duration|int|null ttl + /// @return Future + Future add(String key, dynamic value, [dynamic ttl]); + + /// Increment the value of an item in the cache. + /// + /// @param String key + /// @param dynamic value + /// @return Future + Future increment(String key, [int value = 1]); + + /// Decrement the value of an item in the cache. + /// + /// @param String key + /// @param dynamic value + /// @return Future + Future decrement(String key, [int value = 1]); + + /// Store an item in the cache indefinitely. + /// + /// @param String key + /// @param dynamic value + /// @return Future + Future forever(String key, dynamic value); + + /// Get an item from the cache, or execute the given Closure and store the result. + /// + /// @template TCacheValue + /// + /// @param String key + /// @param DateTime|Duration|Future Function()|int|null ttl + /// @param Future Function() callback + /// @return Future + Future remember(String key, dynamic ttl, Future Function() callback); + + /// Get an item from the cache, or execute the given Closure and store the result forever. + /// + /// @template TCacheValue + /// + /// @param String key + /// @param Future Function() callback + /// @return Future + Future sear(String key, Future Function() callback); + + /// Get an item from the cache, or execute the given Closure and store the result forever. + /// + /// @template TCacheValue + /// + /// @param String key + /// @param Future Function() callback + /// @return Future + Future rememberForever(String key, Future Function() callback); + + /// Remove an item from the cache. + /// + /// @param String key + /// @return Future + Future forget(String key); + + /// Get the cache store implementation. + /// + /// @return CacheStore + CacheStore getStore(); +} + +abstract class CacheStore { + // Define methods that a CacheStore should have. +} diff --git a/packages/contracts/lib/src/cache/store.dart b/packages/contracts/lib/src/cache/store.dart index e69de29..ebd5f3b 100644 --- a/packages/contracts/lib/src/cache/store.dart +++ b/packages/contracts/lib/src/cache/store.dart @@ -0,0 +1,67 @@ +abstract class Store { + /// Retrieve an item from the cache by key. + /// + /// @param String key + /// @return dynamic + dynamic get(String key); + + /// Retrieve multiple items from the cache by key. + /// + /// Items not found in the cache will have a null value. + /// + /// @param List keys + /// @return Map + Map many(List keys); + + /// Store an item in the cache for a given number of seconds. + /// + /// @param String key + /// @param dynamic value + /// @param int seconds + /// @return bool + bool put(String key, dynamic value, int seconds); + + /// Store multiple items in the cache for a given number of seconds. + /// + /// @param Map values + /// @param int seconds + /// @return bool + bool putMany(Map values, int seconds); + + /// Increment the value of an item in the cache. + /// + /// @param String key + /// @param dynamic value + /// @return int|bool + dynamic increment(String key, {dynamic value = 1}); + + /// Decrement the value of an item in the cache. + /// + /// @param String key + /// @param dynamic value + /// @return int|bool + dynamic decrement(String key, {dynamic value = 1}); + + /// Store an item in the cache indefinitely. + /// + /// @param String key + /// @param dynamic value + /// @return bool + bool forever(String key, dynamic value); + + /// Remove an item from the cache. + /// + /// @param String key + /// @return bool + bool forget(String key); + + /// Remove all items from the cache. + /// + /// @return bool + bool flush(); + + /// Get the cache key prefix. + /// + /// @return String + String getPrefix(); +} diff --git a/packages/contracts/lib/src/config/repository.dart b/packages/contracts/lib/src/config/repository.dart index e69de29..1765bee 100644 --- a/packages/contracts/lib/src/config/repository.dart +++ b/packages/contracts/lib/src/config/repository.dart @@ -0,0 +1,40 @@ +abstract class Repository { + /// Determine if the given configuration value exists. + /// + /// @param String key + /// @return bool + bool has(String key); + + /// Get the specified configuration value. + /// + /// @param String key + /// @param dynamic defaultValue + /// @return dynamic + dynamic get(String key, [dynamic defaultValue]); + + /// Get all of the configuration items for the application. + /// + /// @return Map + Map all(); + + /// Set a given configuration value. + /// + /// @param String key + /// @param dynamic value + /// @return void + void set(String key, [dynamic value]); + + /// Prepend a value onto an array configuration value. + /// + /// @param String key + /// @param dynamic value + /// @return void + void prepend(String key, dynamic value); + + /// Push a value onto an array configuration value. + /// + /// @param String key + /// @param dynamic value + /// @return void + void push(String key, dynamic value); +} diff --git a/packages/contracts/lib/src/console/application.dart b/packages/contracts/lib/src/console/application.dart index e69de29..2618481 100644 --- a/packages/contracts/lib/src/console/application.dart +++ b/packages/contracts/lib/src/console/application.dart @@ -0,0 +1,17 @@ +// TODO: Find dart replacements for missing imports. +class ConsoleApplication implements Application { + String _lastOutput = ''; + + @override + int call(String command, {List parameters = const [], OutputInterface? outputBuffer}) { + // Implementation of the command execution + // Set _lastOutput with the command output for demonstration + _lastOutput = 'Command executed: $command'; + return 0; // Return appropriate exit code + } + + @override + String output() { + return _lastOutput; + } +} diff --git a/packages/contracts/lib/src/console/isolatable.dart b/packages/contracts/lib/src/console/isolatable.dart index e69de29..e3f5284 100644 --- a/packages/contracts/lib/src/console/isolatable.dart +++ b/packages/contracts/lib/src/console/isolatable.dart @@ -0,0 +1,4 @@ + +abstract class Isolatable { + // Abstract class with no methods +} diff --git a/packages/contracts/lib/src/console/kernel.dart b/packages/contracts/lib/src/console/kernel.dart index e69de29..ae7b550 100644 --- a/packages/contracts/lib/src/console/kernel.dart +++ b/packages/contracts/lib/src/console/kernel.dart @@ -0,0 +1,51 @@ +import 'package:symfony_console/symfony_console.dart'; + +// TODO: Replace missing imports with dart equivalents. + +abstract class Kernel { + /// Bootstrap the application for artisan commands. + void bootstrap(); + + /// Handle an incoming console command. + /// + /// @param InputInterface input + /// @param OutputInterface? output + /// @return int + int handle(InputInterface input, [OutputInterface? output]); + + /// Run an Artisan console command by name. + /// + /// @param String command + /// @param List parameters + /// @param OutputInterface? outputBuffer + /// @return int + int call(String command, [List parameters = const [], OutputInterface? outputBuffer]); + + /// Queue an Artisan console command by name. + /// + /// @param String command + /// @param List parameters + /// @return PendingDispatch + PendingDispatch queue(String command, [List parameters = const []]); + + /// Get all of the commands registered with the console. + /// + /// @return List + List all(); + + /// Get the output for the last run command. + /// + /// @return String + String output(); + + /// Terminate the application. + /// + /// @param InputInterface input + /// @param int status + /// @return void + void terminate(InputInterface input, int status); +} + +class PendingDispatch { + // Implement the PendingDispatch class here +} diff --git a/packages/contracts/lib/src/console/prompts_for_missing_input.dart b/packages/contracts/lib/src/console/prompts_for_missing_input.dart index e69de29..71f318c 100644 --- a/packages/contracts/lib/src/console/prompts_for_missing_input.dart +++ b/packages/contracts/lib/src/console/prompts_for_missing_input.dart @@ -0,0 +1,3 @@ +abstract class PromptsForMissingInput { + // This is a placeholder for future methods. +} diff --git a/packages/contracts/lib/src/container/binding_resolution_exception.dart b/packages/contracts/lib/src/container/binding_resolution_exception.dart index e69de29..7798bbb 100644 --- a/packages/contracts/lib/src/container/binding_resolution_exception.dart +++ b/packages/contracts/lib/src/container/binding_resolution_exception.dart @@ -0,0 +1,12 @@ +import 'package:psr_container/psr_container.dart'; + +// TODO: find packages to replace missing imports. + +class BindingResolutionException implements Exception, ContainerException { + final String message; + + BindingResolutionException([this.message = '']); + + @override + String toString() => 'BindingResolutionException: $message'; +} diff --git a/packages/contracts/lib/src/container/circular_dependency_exception.dart b/packages/contracts/lib/src/container/circular_dependency_exception.dart index e69de29..adeefd1 100644 --- a/packages/contracts/lib/src/container/circular_dependency_exception.dart +++ b/packages/contracts/lib/src/container/circular_dependency_exception.dart @@ -0,0 +1,12 @@ +import 'package:psr/psr.dart'; + +// TODO: Find packages to replace missing imports. + +class CircularDependencyException implements Exception, ContainerExceptionInterface { + final String message; + + CircularDependencyException([this.message = '']); + + @override + String toString() => 'CircularDependencyException: $message'; +} diff --git a/packages/contracts/lib/src/container/container.dart b/packages/contracts/lib/src/container/container.dart index e69de29..c632c95 100644 --- a/packages/contracts/lib/src/container/container.dart +++ b/packages/contracts/lib/src/container/container.dart @@ -0,0 +1,183 @@ +import 'package:meta/meta.dart'; + +abstract class Container { + /// Determine if the given abstract type has been bound. + /// + /// @param String abstract + /// @return bool + bool bound(String abstract); + + /// Alias a type to a different name. + /// + /// @param String abstract + /// @param String alias + /// @return void + /// + /// @throws LogicException + void alias(String abstract, String alias); + + /// Assign a set of tags to a given binding. + /// + /// @param List|String abstracts + /// @param List|dynamic tags + /// @return void + void tag(dynamic abstracts, dynamic tags); + + /// Resolve all of the bindings for a given tag. + /// + /// @param String tag + /// @return Iterable + Iterable tagged(String tag); + + /// Register a binding with the container. + /// + /// @param String abstract + /// @param Function|String|null concrete + /// @param bool shared + /// @return void + void bind(String abstract, [dynamic concrete, bool shared = false]); + + /// Bind a callback to resolve with Container::call. + /// + /// @param List|String method + /// @param Function callback + /// @return void + void bindMethod(dynamic method, Function callback); + + /// Register a binding if it hasn't already been registered. + /// + /// @param String abstract + /// @param Function|String|null concrete + /// @param bool shared + /// @return void + void bindIf(String abstract, [dynamic concrete, bool shared = false]); + + /// Register a shared binding in the container. + /// + /// @param String abstract + /// @param Function|String|null concrete + /// @return void + void singleton(String abstract, [dynamic concrete]); + + /// Register a shared binding if it hasn't already been registered. + /// + /// @param String abstract + /// @param Function|String|null concrete + /// @return void + void singletonIf(String abstract, [dynamic concrete]); + + /// Register a scoped binding in the container. + /// + /// @param String abstract + /// @param Function|String|null concrete + /// @return void + void scoped(String abstract, [dynamic concrete]); + + /// Register a scoped binding if it hasn't already been registered. + /// + /// @param String abstract + /// @param Function|String|null concrete + /// @return void + void scopedIf(String abstract, [dynamic concrete]); + + /// "Extend" an abstract type in the container. + /// + /// @param String abstract + /// @param Function closure + /// @return void + /// + /// @throws InvalidArgumentException + void extend(String abstract, Function closure); + + /// Register an existing instance as shared in the container. + /// + /// @param String abstract + /// @param dynamic instance + /// @return dynamic + dynamic instance(String abstract, dynamic instance); + + /// Add a contextual binding to the container. + /// + /// @param String concrete + /// @param String abstract + /// @param Function|String implementation + /// @return void + void addContextualBinding(String concrete, String abstract, dynamic implementation); + + /// Define a contextual binding. + /// + /// @param String|List concrete + /// @return ContextualBindingBuilder + ContextualBindingBuilder when(dynamic concrete); + + /// Get a closure to resolve the given type from the container. + /// + /// @param String abstract + /// @return Function + Function factory(String abstract); + + /// Flush the container of all bindings and resolved instances. + /// + /// @return void + void flush(); + + /// Resolve the given type from the container. + /// + /// @param String abstract + /// @param Map parameters + /// @return dynamic + /// + /// @throws BindingResolutionException + dynamic make(String abstract, [Map parameters = const {}]); + + /// Call the given Function / class@method and inject its dependencies. + /// + /// @param dynamic callback + /// @param Map parameters + /// @param String|null defaultMethod + /// @return dynamic + dynamic call(dynamic callback, [Map parameters = const {}, String defaultMethod]); + + /// Determine if the given abstract type has been resolved. + /// + /// @param String abstract + /// @return bool + bool resolved(String abstract); + + /// Register a new before resolving callback. + /// + /// @param String|Function abstract + /// @param Function|null callback + /// @return void + void beforeResolving(dynamic abstract, [Function? callback]); + + /// Register a new resolving callback. + /// + /// @param String|Function abstract + /// @param Function|null callback + /// @return void + void resolving(dynamic abstract, [Function? callback]); + + /// Register a new after resolving callback. + /// + /// @param String|Function abstract + /// @param Function|null callback + /// @return void + void afterResolving(dynamic abstract, [Function? callback]); +} + +class ContextualBindingBuilder { + // Implementation for ContextualBindingBuilder +} + +class BindingResolutionException implements Exception { + // Implementation for BindingResolutionException +} + +class InvalidArgumentException implements Exception { + // Implementation for InvalidArgumentException +} + +class LogicException implements Exception { + // Implementation for LogicException +} diff --git a/packages/contracts/lib/src/container/contextual_binding_builder.dart b/packages/contracts/lib/src/container/contextual_binding_builder.dart index e69de29..376bdb4 100644 --- a/packages/contracts/lib/src/container/contextual_binding_builder.dart +++ b/packages/contracts/lib/src/container/contextual_binding_builder.dart @@ -0,0 +1,23 @@ +abstract class ContextualBindingBuilder { + /// Define the abstract target that depends on the context. + /// + /// [abstract] The abstract target. + /// Returns the current instance. + ContextualBindingBuilder needs(String abstract); + + /// Define the implementation for the contextual binding. + /// + /// [implementation] The implementation which can be a Closure, String, or List. + void give(dynamic implementation); + + /// Define tagged services to be used as the implementation for the contextual binding. + /// + /// [tag] The tag to use. + void giveTagged(String tag); + + /// Specify the configuration item to bind as a primitive. + /// + /// [key] The configuration key. + /// [defaultValue] The default value. + void giveConfig(String key, [dynamic defaultValue]); +}