diff --git a/yaroo/lib/http/http.dart b/yaroo/lib/http/http.dart index 300a8f56..392ce671 100644 --- a/yaroo/lib/http/http.dart +++ b/yaroo/lib/http/http.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:io'; import 'package:yaroo/src/_reflector/reflector.dart'; import 'package:yaroo/src/core.dart'; @@ -7,20 +6,10 @@ import 'package:yaroo/src/core.dart'; import 'http.dart'; export 'package:pharaoh/pharaoh.dart' - show - Request, - Response, - Session, - Middleware, - HTTPMethod, - CookieOpts, - session, - cookieParser, - useRequestHandler, - useShelfMiddleware; + show Request, Response, Session, Middleware, HTTPMethod, CookieOpts, session, cookieParser, useRequestHandler; @inject -abstract class ApplicationController extends AppInstance { +abstract class HTTPController extends AppInstance { late final Request request; late final Response response; @@ -33,10 +22,6 @@ abstract class ApplicationController extends AppInstance { Session? get session => request.session; - List get cookies => request.cookies; - - List get signedCookies => request.signedCookies; - get body => request.body; Response badRequest([String? message]) { @@ -65,4 +50,6 @@ abstract class ServiceProvider extends AppInstance { static List get defaultProviders => [AppServiceProvider]; FutureOr boot(); + + bool isAugmentation = false; } diff --git a/yaroo/lib/src/_reflector/reflector.dart b/yaroo/lib/src/_reflector/reflector.dart index 803da1d2..e29dabe8 100644 --- a/yaroo/lib/src/_reflector/reflector.dart +++ b/yaroo/lib/src/_reflector/reflector.dart @@ -5,21 +5,29 @@ import '../../../http/http.dart'; import '../_container/container.dart'; import '../_router/definition.dart'; import '../_router/utils.dart'; -import '../core.dart'; + +class Injectable extends r.Reflectable { + const Injectable() + : super( + r.invokingCapability, + r.metadataCapability, + r.newInstanceCapability, + r.declarationsCapability, + r.reflectedTypeCapability, + r.typeRelationsCapability, + const r.InstanceInvokeCapability('^[^_]'), + r.subtypeQuantifyCapability, + ); +} const unnamedConstructor = ''; const inject = Injectable(); -List filteredDeclarationsOf( - r.ClassMirror cm, - predicate, -) { +List filteredDeclarationsOf(r.ClassMirror cm, predicate) { var result = []; cm.declarations.forEach((k, v) { - if (predicate(v)) { - result.add(v as X); - } + if (predicate(v)) result.add(v as X); }); return result; } @@ -64,7 +72,7 @@ ControllerMethod parseControllerMethod(ControllerMethodDefinition defn) { final method = defn.$2; final ctrlMirror = inject.reflectType(type) as r.ClassMirror; - if (ctrlMirror.superclass?.reflectedType != ApplicationController) { + if (ctrlMirror.superclass?.reflectedType != HTTPController) { throw ArgumentError('$type must extend BaseController'); } diff --git a/yaroo/lib/src/core.dart b/yaroo/lib/src/core.dart index f4c8706b..1ea5a6b5 100644 --- a/yaroo/lib/src/core.dart +++ b/yaroo/lib/src/core.dart @@ -4,7 +4,6 @@ import 'dart:async'; import 'package:meta/meta.dart'; import 'package:pharaoh/pharaoh.dart'; -import 'package:reflectable/reflectable.dart' as r; import 'package:spookie/spookie.dart'; import 'package:yaroo/db/db.dart'; @@ -18,22 +17,10 @@ import 'config/config.dart'; part './core_impl.dart'; -class Injectable extends r.Reflectable { - const Injectable() - : super( - r.invokingCapability, - r.metadataCapability, - r.newInstanceCapability, - r.declarationsCapability, - r.reflectedTypeCapability, - r.typeRelationsCapability, - r.instanceInvokeCapability, - r.subtypeQuantifyCapability, - ); -} - 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; } @@ -130,7 +117,7 @@ abstract class ApplicationFactory { static RequestHandler buildControllerMethod(ControllerMethod method) { return (req, res) async { final methodName = method.methodName; - final instance = createNewInstance(method.controller); + final instance = createNewInstance(method.controller); final mirror = inject.reflect(instance); mirror diff --git a/yaroo/test/router_test.dart b/yaroo/test/router_test.dart index decc7a60..8c47f0a6 100644 --- a/yaroo/test/router_test.dart +++ b/yaroo/test/router_test.dart @@ -4,7 +4,7 @@ import 'package:yaroo/yaroo.dart'; import './router_test.reflectable.dart'; -class TestController extends ApplicationController { +class TestController extends HTTPController { void create() {} void index() {}