Skip to content

Commit 28411ad

Browse files
authored
chore: Make AppInstance available as mixing (#134)
* _ * _ * _
1 parent 713f544 commit 28411ad

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

packages/pharaoh/lib/src/_next/core.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ part '_core/reflector.dart';
2424

2525
typedef RoutesResolver = List<RouteDefinition> Function();
2626

27-
/// This should really be a mixin but due to a bug in reflectable.dart#324
28-
/// TODO:(codekeyz) make this a mixin when reflectable.dart#324 is fixed
29-
abstract class AppInstance {
30-
Application get app => Application.instance;
27+
mixin class AppInstance {
28+
Application get app => Application._instance;
29+
30+
AppConfig get config => app.config;
3131
}
3232

3333
/// Use this to override the application exceptiosn handler
@@ -39,7 +39,7 @@ typedef ApplicationExceptionsHandler = FutureOr<Response> Function(
3939
abstract interface class Application {
4040
Application(AppConfig config);
4141

42-
static late final Application instance;
42+
static late final Application _instance;
4343

4444
String get name;
4545

@@ -101,7 +101,7 @@ abstract class ApplicationFactory {
101101
}
102102

103103
Future<void> startServer() async {
104-
final app = Application.instance as _PharaohNextImpl;
104+
final app = Application._instance as _PharaohNextImpl;
105105

106106
await app
107107
._createPharaohInstance(onException: onApplicationException)
@@ -110,7 +110,7 @@ abstract class ApplicationFactory {
110110

111111
Future<void> _bootstrapComponents(AppConfig config) async {
112112
final spanner = Spanner()..addMiddleware('/', bodyParser);
113-
Application.instance = _PharaohNextImpl(config, spanner);
113+
Application._instance = _PharaohNextImpl(config, spanner);
114114

115115
final providerInstances = providers.map(createNewInstance<ServiceProvider>);
116116

@@ -185,7 +185,7 @@ abstract class ApplicationFactory {
185185

186186
@visibleForTesting
187187
Future<spookie.Spookie> get tester {
188-
final app = (Application.instance as _PharaohNextImpl);
188+
final app = (Application._instance as _PharaohNextImpl);
189189
return spookie.request(
190190
app._createPharaohInstance(onException: onApplicationException));
191191
}

packages/pharaoh/lib/src/_next/http.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import '../router/router_handler.dart';
99
import 'core.dart';
1010

1111
@inject
12-
abstract class ClassMiddleware extends AppInstance {
12+
abstract class ClassMiddleware with AppInstance {
1313
handle(Request req, Response res, NextFunction next) {
1414
next();
1515
}
@@ -18,7 +18,7 @@ abstract class ClassMiddleware extends AppInstance {
1818
}
1919

2020
@inject
21-
abstract class ServiceProvider extends AppInstance {
21+
abstract class ServiceProvider with AppInstance {
2222
static List<Type> get defaultProviders => [];
2323

2424
void boot() {}
@@ -27,7 +27,7 @@ abstract class ServiceProvider extends AppInstance {
2727
}
2828

2929
@inject
30-
abstract class HTTPController extends AppInstance {
30+
abstract class HTTPController with AppInstance {
3131
late final Request request;
3232

3333
late final Response response;

packages/pharaoh/lib/src/core_impl.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class $PharaohImpl extends RouterContract
5757
..autoCompress = true;
5858
_server.listen(handleRequest);
5959

60-
print(
61-
'Server start on PORT: ${_server.port} -> ${uri.scheme}://localhost:${_server.port}');
60+
stdout.writeln(
61+
'Server started on PORT: ${_server.port} -> ${uri.scheme}://localhost:${_server.port}');
6262
return this;
6363
}
6464

@@ -162,6 +162,7 @@ class $PharaohImpl extends RouterContract
162162
if (!responseHeaders.containsKey(_XPoweredByHeader)) {
163163
request.response.headers.add(_XPoweredByHeader, 'Pharaoh');
164164
}
165+
165166
if (!responseHeaders.containsKey(HttpHeaders.dateHeader)) {
166167
request.response.headers.add(
167168
HttpHeaders.dateHeader,

packages/pharaoh/pubspec.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@ dependencies:
1919
shelf: ^1.4.1
2020

2121
# framework
22-
reflectable: 4.0.6
23-
get_it: ^7.6.7
22+
reflectable: ^4.0.12
23+
get_it: ^8.0.2
2424
grammer: ^1.0.3
2525
dotenv: ^4.2.0
2626
ez_validator_dart: ^0.3.1
2727
spookie: ^1.0.2+3
2828

2929
dev_dependencies:
3030
lints: ^3.0.0
31-
32-
dependency_overrides:
33-
analyzer: 6.4.0

0 commit comments

Comments
 (0)