Port to using angelEnv

This commit is contained in:
Tobe O 2019-04-08 19:03:35 -04:00
parent 05199ce342
commit a4fd32581b
3 changed files with 19 additions and 9 deletions

View file

@ -1,5 +1,8 @@
# 2.0.0-rc.0
* Log a warning when no `reflector` is provided.
* Add `AngelEnvironment` class.
* Add `Angel.environment`.
* Deprecated `app.isProduction` in favor of `app.environment.isProduction`.
# 2.0.0-alpha.24
* Add `AngelEnv` class to `core`.

View file

@ -113,7 +113,7 @@ abstract class Driver<
}
var cacheKey = req.method + path;
var tuple = app.isProduction
var tuple = app.environment.isProduction
? app.handlerCache.putIfAbsent(cacheKey, resolveTuple)
: resolveTuple();
var line = tuple.item4 as MiddlewarePipeline<RequestHandler>;
@ -129,7 +129,7 @@ abstract class Driver<
..registerSingleton<ParseResult<RouteResult>>(tuple.item3)
..registerSingleton<ParseResult>(tuple.item3);
if (!app.isProduction && app.logger != null) {
if (!app.environment.isProduction && app.logger != null) {
req.container
.registerSingleton<Stopwatch>(new Stopwatch()..start());
}
@ -279,7 +279,7 @@ abstract class Driver<
ResponseContext res,
{bool ignoreFinalizers = false}) {
void _cleanup(_) {
if (!app.isProduction && app.logger != null) {
if (!app.environment.isProduction && app.logger != null) {
var sw = req.container.make<Stopwatch>();
app.logger.info(
"${res.statusCode} ${req.method} ${req.uri} (${sw?.elapsedMilliseconds ?? 'unknown'} ms)");

View file

@ -72,7 +72,8 @@ class Angel extends Routable {
/// A set of [Controller] objects that have been loaded into the application.
Map<Pattern, Controller> get controllers => _controllers;
/// Now *deprecated*, in favor of [AngelEnv] and [angelEnv].
/// Now *deprecated*, in favor of [AngelEnv] and [angelEnv]. Use `app.environment.isProduction`
/// instead.
///
/// Indicates whether the application is running in a production environment.
///
@ -82,7 +83,12 @@ class Angel extends Routable {
/// This value is memoized the first time you call it, so do not change environment
/// configuration at runtime!
@deprecated
bool get isProduction => angelEnv.isProduction;
bool get isProduction => environment.isProduction;
/// The [AngelEnvironment] in which the application is running.
///
/// By default, it is automatically inferred.
final AngelEnvironment environment;
/// Returns the parent instance of this application, if any.
Angel get parent => _parent;
@ -213,14 +219,14 @@ class Angel extends Routable {
String header: 'Dumping route tree:',
String tab: ' ',
bool showMatchers: false}) {
if (isProduction) {
if (environment.isProduction) {
_flattened ??= flatten(this);
_flattened.dumpTree(
callback: callback,
header: header?.isNotEmpty == true
? header
: (isProduction
: (environment.isProduction
? 'Dumping flattened route tree:'
: 'Dumping route tree:'),
tab: tab ?? ' ');
@ -229,7 +235,7 @@ class Angel extends Routable {
callback: callback,
header: header?.isNotEmpty == true
? header
: (isProduction
: (environment.isProduction
? 'Dumping flattened route tree:'
: 'Dumping route tree:'),
tab: tab ?? ' ');
@ -287,7 +293,7 @@ class Angel extends Routable {
///
/// You may [force] the optimization to run, if you are not running in production.
void optimizeForProduction({bool force: false}) {
if (isProduction == true || force == true) {
if (environment.isProduction || force == true) {
_flattened ??= flatten(this);
logger?.info('Angel is running in production mode.');
}
@ -349,6 +355,7 @@ class Angel extends Routable {
Angel(
{Reflector reflector: const EmptyReflector(),
this.environment: angelEnv,
this.logger,
this.allowMethodOverrides: true,
this.serializer,