From eb0829a712a7f55b0c5a07d3a873f5d891193083 Mon Sep 17 00:00:00 2001 From: Chima Precious Date: Mon, 4 Nov 2024 11:54:25 +0300 Subject: [PATCH 1/3] _ --- packages/pharaoh/lib/src/_next/core.dart | 14 ++++++-------- packages/pharaoh/lib/src/_next/http.dart | 9 ++++----- packages/pharaoh/lib/src/core_impl.dart | 5 +++-- packages/pharaoh/pubspec.yaml | 7 ++----- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/packages/pharaoh/lib/src/_next/core.dart b/packages/pharaoh/lib/src/_next/core.dart index 6abc4241..a5fb93e0 100644 --- a/packages/pharaoh/lib/src/_next/core.dart +++ b/packages/pharaoh/lib/src/_next/core.dart @@ -24,10 +24,8 @@ part '_core/reflector.dart'; typedef RoutesResolver = List Function(); -/// This should really be a mixin but due to a bug in reflectable.dart#324 -/// TODO:(codekeyz) make this a mixin when reflectable.dart#324 is fixed -abstract class AppInstance { - Application get app => Application.instance; +mixin class AppInstance { + Application get app => Application._instance; } /// Use this to override the application exceptiosn handler @@ -39,7 +37,7 @@ typedef ApplicationExceptionsHandler = FutureOr Function( abstract interface class Application { Application(AppConfig config); - static late final Application instance; + static late final Application _instance; String get name; @@ -101,7 +99,7 @@ abstract class ApplicationFactory { } Future startServer() async { - final app = Application.instance as _PharaohNextImpl; + final app = Application._instance as _PharaohNextImpl; await app ._createPharaohInstance(onException: onApplicationException) @@ -110,7 +108,7 @@ abstract class ApplicationFactory { Future _bootstrapComponents(AppConfig config) async { final spanner = Spanner()..addMiddleware('/', bodyParser); - Application.instance = _PharaohNextImpl(config, spanner); + Application._instance = _PharaohNextImpl(config, spanner); final providerInstances = providers.map(createNewInstance); @@ -185,7 +183,7 @@ abstract class ApplicationFactory { @visibleForTesting Future get tester { - final app = (Application.instance as _PharaohNextImpl); + final app = (Application._instance as _PharaohNextImpl); return spookie.request( app._createPharaohInstance(onException: onApplicationException)); } diff --git a/packages/pharaoh/lib/src/_next/http.dart b/packages/pharaoh/lib/src/_next/http.dart index ccc32dd6..fc5b0df1 100644 --- a/packages/pharaoh/lib/src/_next/http.dart +++ b/packages/pharaoh/lib/src/_next/http.dart @@ -9,7 +9,7 @@ import '../router/router_handler.dart'; import 'core.dart'; @inject -abstract class ClassMiddleware extends AppInstance { +abstract class ClassMiddleware with AppInstance { handle(Request req, Response res, NextFunction next) { next(); } @@ -18,7 +18,7 @@ abstract class ClassMiddleware extends AppInstance { } @inject -abstract class ServiceProvider extends AppInstance { +abstract class ServiceProvider with AppInstance { static List get defaultProviders => []; void boot() {} @@ -27,7 +27,7 @@ abstract class ServiceProvider extends AppInstance { } @inject -abstract class HTTPController extends AppInstance { +abstract class HTTPController with AppInstance { late final Request request; late final Response response; @@ -43,8 +43,7 @@ abstract class HTTPController extends AppInstance { get requestBody => request.body; bool get expectsJson { - final headerValue = - request.headers[HttpHeaders.acceptEncodingHeader]?.toString(); + final headerValue = request.headers[HttpHeaders.acceptEncodingHeader]?.toString(); return headerValue != null && headerValue.contains('application/json'); } diff --git a/packages/pharaoh/lib/src/core_impl.dart b/packages/pharaoh/lib/src/core_impl.dart index 95fe7b94..5770b61c 100644 --- a/packages/pharaoh/lib/src/core_impl.dart +++ b/packages/pharaoh/lib/src/core_impl.dart @@ -57,8 +57,8 @@ class $PharaohImpl extends RouterContract ..autoCompress = true; _server.listen(handleRequest); - print( - 'Server start on PORT: ${_server.port} -> ${uri.scheme}://localhost:${_server.port}'); + stdout.writeln( + 'Server started on PORT: ${_server.port} -> ${uri.scheme}://localhost:${_server.port}'); return this; } @@ -162,6 +162,7 @@ class $PharaohImpl extends RouterContract if (!responseHeaders.containsKey(_XPoweredByHeader)) { request.response.headers.add(_XPoweredByHeader, 'Pharaoh'); } + if (!responseHeaders.containsKey(HttpHeaders.dateHeader)) { request.response.headers.add( HttpHeaders.dateHeader, diff --git a/packages/pharaoh/pubspec.yaml b/packages/pharaoh/pubspec.yaml index b78bbf7d..891efc04 100644 --- a/packages/pharaoh/pubspec.yaml +++ b/packages/pharaoh/pubspec.yaml @@ -19,8 +19,8 @@ dependencies: shelf: ^1.4.1 # framework - reflectable: 4.0.6 - get_it: ^7.6.7 + reflectable: ^4.0.12 + get_it: ^8.0.2 grammer: ^1.0.3 dotenv: ^4.2.0 ez_validator_dart: ^0.3.1 @@ -28,6 +28,3 @@ dependencies: dev_dependencies: lints: ^3.0.0 - -dependency_overrides: - analyzer: 6.4.0 From d72e680dfcee47b5486c7f872b8254e688f02279 Mon Sep 17 00:00:00 2001 From: Chima Precious Date: Mon, 4 Nov 2024 11:57:18 +0300 Subject: [PATCH 2/3] _ --- packages/pharaoh/lib/src/_next/http.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/pharaoh/lib/src/_next/http.dart b/packages/pharaoh/lib/src/_next/http.dart index fc5b0df1..3387c7ab 100644 --- a/packages/pharaoh/lib/src/_next/http.dart +++ b/packages/pharaoh/lib/src/_next/http.dart @@ -43,7 +43,8 @@ abstract class HTTPController with AppInstance { get requestBody => request.body; bool get expectsJson { - final headerValue = request.headers[HttpHeaders.acceptEncodingHeader]?.toString(); + final headerValue = + request.headers[HttpHeaders.acceptEncodingHeader]?.toString(); return headerValue != null && headerValue.contains('application/json'); } From 277b3258705b0d2d0ccaf782d15b72d8ea66cd52 Mon Sep 17 00:00:00 2001 From: Chima Precious Date: Mon, 4 Nov 2024 12:02:49 +0300 Subject: [PATCH 3/3] _ --- packages/pharaoh/lib/src/_next/core.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/pharaoh/lib/src/_next/core.dart b/packages/pharaoh/lib/src/_next/core.dart index a5fb93e0..c857ae3a 100644 --- a/packages/pharaoh/lib/src/_next/core.dart +++ b/packages/pharaoh/lib/src/_next/core.dart @@ -26,6 +26,8 @@ typedef RoutesResolver = List Function(); mixin class AppInstance { Application get app => Application._instance; + + AppConfig get config => app.config; } /// Use this to override the application exceptiosn handler