update: updating files with ported code
This commit is contained in:
parent
4cc3734f96
commit
37cb76c673
23 changed files with 722 additions and 0 deletions
|
@ -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<dynamic> auth(Request request);
|
||||||
|
|
||||||
|
/// Return the valid authentication response.
|
||||||
|
///
|
||||||
|
/// @param Request request
|
||||||
|
/// @param mixed result
|
||||||
|
/// @return mixed
|
||||||
|
Future<dynamic> validAuthenticationResponse(Request request, dynamic result);
|
||||||
|
|
||||||
|
/// Broadcast the given event.
|
||||||
|
///
|
||||||
|
/// @param List<String> channels
|
||||||
|
/// @param String event
|
||||||
|
/// @param Map<String, dynamic> payload
|
||||||
|
/// @return void
|
||||||
|
///
|
||||||
|
/// @throws BroadcastException
|
||||||
|
Future<void> broadcast(List<String> channels, String event, {Map<String, dynamic> 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.
|
|
@ -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]);
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
abstract class ShouldBeUnique {
|
||||||
|
// No methods or properties defined; serves as a marker interface
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
import 'should_broadcast.dart';
|
||||||
|
|
||||||
|
abstract class ShouldBroadcastNow implements ShouldBroadcast {
|
||||||
|
// Additional methods and properties can be added here if needed.
|
||||||
|
}
|
|
@ -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<dynamic> pipes
|
||||||
|
/// @return this
|
||||||
|
Dispatcher pipeThrough(List<dynamic> pipes);
|
||||||
|
|
||||||
|
/// Map a command to a handler.
|
||||||
|
///
|
||||||
|
/// @param Map<dynamic, dynamic> map
|
||||||
|
/// @return this
|
||||||
|
Dispatcher map(Map<dynamic, dynamic> map);
|
||||||
|
}
|
|
@ -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<Batch?> findBatch(String batchId);
|
||||||
|
|
||||||
|
/// Create a new batch of queueable jobs.
|
||||||
|
///
|
||||||
|
/// @param List<dynamic> jobs
|
||||||
|
/// @return PendingBatch
|
||||||
|
PendingBatch batch(List<dynamic> jobs);
|
||||||
|
|
||||||
|
/// Dispatch a command to its appropriate handler behind a queue.
|
||||||
|
///
|
||||||
|
/// @param dynamic command
|
||||||
|
/// @return dynamic
|
||||||
|
Future<dynamic> dispatchToQueue(dynamic command);
|
||||||
|
}
|
|
@ -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]);
|
||||||
|
}
|
29
packages/contracts/lib/src/cache/lock.dart
vendored
29
packages/contracts/lib/src/cache/lock.dart
vendored
|
@ -0,0 +1,29 @@
|
||||||
|
abstract class Lock {
|
||||||
|
/// Attempt to acquire the lock.
|
||||||
|
///
|
||||||
|
/// @param Function? callback
|
||||||
|
/// @return dynamic
|
||||||
|
Future<dynamic> get([Function? callback]);
|
||||||
|
|
||||||
|
/// Attempt to acquire the lock for the given number of seconds.
|
||||||
|
///
|
||||||
|
/// @param int seconds
|
||||||
|
/// @param Function? callback
|
||||||
|
/// @return dynamic
|
||||||
|
Future<dynamic> block(int seconds, [Function? callback]);
|
||||||
|
|
||||||
|
/// Release the lock.
|
||||||
|
///
|
||||||
|
/// @return bool
|
||||||
|
Future<bool> release();
|
||||||
|
|
||||||
|
/// Returns the current owner of the lock.
|
||||||
|
///
|
||||||
|
/// @return String
|
||||||
|
Future<String> owner();
|
||||||
|
|
||||||
|
/// Releases this lock in disregard of ownership.
|
||||||
|
///
|
||||||
|
/// @return void
|
||||||
|
Future<void> forceRelease();
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
class LockTimeoutException implements Exception {
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
LockTimeoutException([this.message = '']);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'LockTimeoutException: $message';
|
||||||
|
}
|
||||||
|
}
|
96
packages/contracts/lib/src/cache/repository.dart
vendored
96
packages/contracts/lib/src/cache/repository.dart
vendored
|
@ -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>|String key
|
||||||
|
/// @param TCacheValue|Future<TCacheValue> Function() default
|
||||||
|
/// @return Future<TCacheValue>
|
||||||
|
Future<dynamic> 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<bool>
|
||||||
|
Future<bool> 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<bool>
|
||||||
|
Future<bool> add(String key, dynamic value, [dynamic ttl]);
|
||||||
|
|
||||||
|
/// Increment the value of an item in the cache.
|
||||||
|
///
|
||||||
|
/// @param String key
|
||||||
|
/// @param dynamic value
|
||||||
|
/// @return Future<int|bool>
|
||||||
|
Future<dynamic> increment(String key, [int value = 1]);
|
||||||
|
|
||||||
|
/// Decrement the value of an item in the cache.
|
||||||
|
///
|
||||||
|
/// @param String key
|
||||||
|
/// @param dynamic value
|
||||||
|
/// @return Future<int|bool>
|
||||||
|
Future<dynamic> decrement(String key, [int value = 1]);
|
||||||
|
|
||||||
|
/// Store an item in the cache indefinitely.
|
||||||
|
///
|
||||||
|
/// @param String key
|
||||||
|
/// @param dynamic value
|
||||||
|
/// @return Future<bool>
|
||||||
|
Future<bool> 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<TCacheValue> Function()|int|null ttl
|
||||||
|
/// @param Future<TCacheValue> Function() callback
|
||||||
|
/// @return Future<TCacheValue>
|
||||||
|
Future<dynamic> remember(String key, dynamic ttl, Future<dynamic> 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<TCacheValue> Function() callback
|
||||||
|
/// @return Future<TCacheValue>
|
||||||
|
Future<dynamic> sear(String key, Future<dynamic> 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<TCacheValue> Function() callback
|
||||||
|
/// @return Future<TCacheValue>
|
||||||
|
Future<dynamic> rememberForever(String key, Future<dynamic> Function() callback);
|
||||||
|
|
||||||
|
/// Remove an item from the cache.
|
||||||
|
///
|
||||||
|
/// @param String key
|
||||||
|
/// @return Future<bool>
|
||||||
|
Future<bool> forget(String key);
|
||||||
|
|
||||||
|
/// Get the cache store implementation.
|
||||||
|
///
|
||||||
|
/// @return CacheStore
|
||||||
|
CacheStore getStore();
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class CacheStore {
|
||||||
|
// Define methods that a CacheStore should have.
|
||||||
|
}
|
67
packages/contracts/lib/src/cache/store.dart
vendored
67
packages/contracts/lib/src/cache/store.dart
vendored
|
@ -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<String> keys
|
||||||
|
/// @return Map<String, dynamic>
|
||||||
|
Map<String, dynamic> many(List<String> 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<String, dynamic> values
|
||||||
|
/// @param int seconds
|
||||||
|
/// @return bool
|
||||||
|
bool putMany(Map<String, dynamic> 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();
|
||||||
|
}
|
|
@ -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<String, dynamic>
|
||||||
|
Map<String, dynamic> 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);
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
// TODO: Find dart replacements for missing imports.
|
||||||
|
class ConsoleApplication implements Application {
|
||||||
|
String _lastOutput = '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
int call(String command, {List<String> 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
abstract class Isolatable {
|
||||||
|
// Abstract class with no methods
|
||||||
|
}
|
|
@ -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<dynamic> parameters
|
||||||
|
/// @param OutputInterface? outputBuffer
|
||||||
|
/// @return int
|
||||||
|
int call(String command, [List<dynamic> parameters = const [], OutputInterface? outputBuffer]);
|
||||||
|
|
||||||
|
/// Queue an Artisan console command by name.
|
||||||
|
///
|
||||||
|
/// @param String command
|
||||||
|
/// @param List<dynamic> parameters
|
||||||
|
/// @return PendingDispatch
|
||||||
|
PendingDispatch queue(String command, [List<dynamic> parameters = const []]);
|
||||||
|
|
||||||
|
/// Get all of the commands registered with the console.
|
||||||
|
///
|
||||||
|
/// @return List<dynamic>
|
||||||
|
List<dynamic> 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
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
abstract class PromptsForMissingInput {
|
||||||
|
// This is a placeholder for future methods.
|
||||||
|
}
|
|
@ -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';
|
||||||
|
}
|
|
@ -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';
|
||||||
|
}
|
|
@ -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>|String abstracts
|
||||||
|
/// @param List<dynamic>|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>|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<String> 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<String, dynamic> parameters
|
||||||
|
/// @return dynamic
|
||||||
|
///
|
||||||
|
/// @throws BindingResolutionException
|
||||||
|
dynamic make(String abstract, [Map<String, dynamic> parameters = const {}]);
|
||||||
|
|
||||||
|
/// Call the given Function / class@method and inject its dependencies.
|
||||||
|
///
|
||||||
|
/// @param dynamic callback
|
||||||
|
/// @param Map<String, dynamic> parameters
|
||||||
|
/// @param String|null defaultMethod
|
||||||
|
/// @return dynamic
|
||||||
|
dynamic call(dynamic callback, [Map<String, dynamic> 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
|
||||||
|
}
|
|
@ -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]);
|
||||||
|
}
|
Loading…
Reference in a new issue