Skip to content

Commit

Permalink
test application from documention and fixed missing feature and bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrojs committed Dec 26, 2021
1 parent 14b741a commit 7c7a7f7
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 156 deletions.
8 changes: 2 additions & 6 deletions console/eventGenerateCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ const Command = require('@ostro/console/command')
const EventServiceProvider = require('@ostro/event/eventServiceProvider')
class EventGenerateCommand extends Command {

get $signature() {
return 'event:generate'
};
$signature = 'event:generate';

get $description() {
return 'Generate the missing events and listeners based on registration';
}
$description = 'Generate the missing events and listeners based on registration';

async handle() {

Expand Down
12 changes: 3 additions & 9 deletions console/eventMakeCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ const GeneratorCommand = require('@ostro/console/generatorCommand')

class EventMakeCommand extends GeneratorCommand {

get $signature() {
return 'make:event';
}
$signature = 'make:event';

get $description() {
return 'Create a new event class';
}
$description = 'Create a new event class';

get $type() {
return 'Event';
}
$type = 'Event';

alreadyExists($rawName) {
return this.$file.exists(this.getPath(this.qualifyClass($rawName)));
Expand Down
18 changes: 6 additions & 12 deletions console/keyGenerateCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@ const Command = require('@ostro/console/command')
const Crypto = require('crypto')
class KeyGenerateCommand extends Command {

get $signature() {
return 'key:generate';
}
$signature = 'key:generate';

get $description() {
return 'Set the application key'
};
$description = 'Set the application key';

get $options() {
return [
this.createOption('--show [command] ', 'Display the key instead of modifying files'),
this.createOption('--force [command] ', 'Force the operation to run when in production'),
]
}
$options = [
this.createOption('--show [command] ', 'Display the key instead of modifying files'),
this.createOption('--force [command] ', 'Force the operation to run when in production'),
];

constructor(file) {
super()
Expand Down
40 changes: 16 additions & 24 deletions console/modelMakeCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,24 @@ const GeneratorCommand = require('@ostro/console/generatorCommand')

class ModelMakeCommand extends GeneratorCommand {

get $signature() {
return 'make:model';
}
$signature = 'make:model';

get $description() {
return 'Create a new Eloquent model class'
};

get $options() {
return [
this.createOption('-a, --all', 'Generate a migration, seeder, factory, and resource controller for the model'),
this.createOption('-c, --controller', 'Create a new controller for the model'),
this.createOption('-f, --factory', 'Create a new factory for the model'),
this.createOption('--force', 'Create the class even if the model already exists'),
this.createOption('-m, --migration', 'Create a new migration file for the model'),
this.createOption('-s, --seed', 'Create a new seeder file for the model'),
this.createOption('-p, --pivot', 'Indicates if the generated model should be a custom intermediate table model'),
this.createOption('-r, --resource', 'Indicates if the generated controller should be a resource controller'),
this.createOption('--api', 'Indicates if the generated controller should be an API controller'),

]
}
$description = 'Create a new Eloquent model class';

get $type() {
return 'Model';
}
$options = [
this.createOption('-a, --all', 'Generate a migration, seeder, factory, and resource controller for the model'),
this.createOption('-c, --controller', 'Create a new controller for the model'),
this.createOption('-f, --factory', 'Create a new factory for the model'),
this.createOption('--force', 'Create the class even if the model already exists'),
this.createOption('-m, --migration', 'Create a new migration file for the model'),
this.createOption('-s, --seed', 'Create a new seeder file for the model'),
this.createOption('-p, --pivot', 'Indicates if the generated model should be a custom intermediate table model'),
this.createOption('-r, --resource', 'Indicates if the generated controller should be a resource controller'),
this.createOption('--api', 'Indicates if the generated controller should be an API controller'),

];

$type = 'Model';

get $dirname() {
return __dirname
Expand Down
18 changes: 6 additions & 12 deletions console/resourceMakeCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@ const GeneratorCommand = require('@ostro/console/generatorCommand')

class ResourceMakeCommand extends GeneratorCommand {

get $signature() {
return 'make:resource';
}
$signature = 'make:resource';

get $description() {
return 'Create a new resource';
}
$description = 'Create a new resource';

get $type() {
return 'Resource';
}
$type = 'Resource';

get $options() {
return [this.createOption('-c, --collection', 'Create a resource collection')]
}
$options = [
this.createOption('-c, --collection', 'Create a resource collection')
];

async handle() {
if (this.collection()) {
Expand Down
28 changes: 10 additions & 18 deletions console/serveCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@ const Command = require('@ostro/console/command')

class ServeCommand extends Command {

get $portOffset() {
return 0
};
$portOffset = 0;

get $signature() {
return 'serve';
}
$signature = 'serve';

get $description() {
return 'Serve the application on the nodejs development server'
};

get $options() {
return [
this.createOption('--host <host> ', 'The host address to serve the application on').default('127.1.0.0', 'localhost ip'),
this.createOption('--port [port] ', 'The port to serve the application on').default(8000, 'Recomanded port'),
this.createOption('--tries [tries] ', 'The max number of ports to attempt to serve from'),
this.createOption('--no-reload [no-reload] ', 'Do not reload the development server on .env file changes'),
]
}
$description = 'Serve the application on the nodejs development server';

$options = [
this.createOption('--host <host> ', 'The host address to serve the application on').default('127.1.0.0', 'localhost ip'),
this.createOption('--port [port] ', 'The port to serve the application on').default(8000, 'Recomanded port'),
this.createOption('--tries [tries] ', 'The max number of ports to attempt to serve from'),
this.createOption('--no-reload [no-reload] ', 'Do not reload the development server on .env file changes'),
];

constructor(server, file) {
super()
Expand Down
22 changes: 9 additions & 13 deletions console/storageLinkCommand.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
const Command = require('@ostro/console/command')
class StorageLinkCommand extends Command {

get $signature() {
return 'storage:link'
}
$signature = 'storage:link';

get $description() {
return 'Create the symbolic links configured for the application'
};
$description = 'Create the symbolic links configured for the application';

get $options() {
return [
this.createOption('--relative', 'The host address to serve the application on'),
this.createOption('--force', 'The port to serve the application on')
]
}
$options = [
this.createOption('--relative', 'The host address to serve the application on'),
this.createOption('--force', 'The port to serve the application on')
];

constructor($file) {
super()
this.$file = $file
Expand Down Expand Up @@ -48,7 +43,8 @@ class StorageLinkCommand extends Command {

links() {
return this.$app['config']['filesystems.links'] || {
[public_path('storage')]: storage_path('app/public') };
[public_path('storage')]: storage_path('app/public')
};
}

isRemovableSymlink($link, $force) {
Expand Down
53 changes: 29 additions & 24 deletions exception/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const kHandle = Symbol('handle')
const kLogger = Symbol('logger')

class Handler {
$dontReport = [
$dontReport = [
validationException,
JsonException,
Redirect,
TokenMismatchException
];

$dontFlash = [];
$dontFlash = [];

constructor(handler) {
this[kHandle] = handler
Expand All @@ -35,52 +35,57 @@ class Handler {

render(request, response, $e = {}) {
if ($e instanceof PageNotFoundException) {
return this.pageNotFoundException(request, response, $e)
this.pageNotFoundException(request, response, $e)
} else if ($e instanceof validationException) {
return this.convertValidationExceptionToResponse(request, response, $e);
this.convertValidationExceptionToResponse(request, response, $e);
} else if ($e instanceof TokenMismatchException) {
return this.tokenMismatchException(request, response, $e)
this.tokenMismatchException(request, response, $e)
} else if ($e instanceof AuthenticationException) {
return this.unauthenticated(request, response, $e);
this.unauthenticated(request, response, $e);
} else if ($e instanceof Redirect) {
return this.redirect(response, $e)
this.redirect(response, $e)
} else if ($e instanceof FileNotFoundException) {
return response.send({
response.send({
name: $e.name,
message: $e.message
}, $e.statusCode)
} else if ($e instanceof FileUploadException) {
return response.send({
response.send({
name: $e.name,
message: $e.message
}, $e.statusCode)
} else if ($e instanceof JsonException) {
return this.send({
response.send({
name: $e.name,
message: $e.message,
errors: $e.errors
}, $e.statusCode)
} else if (typeof $e.message == 'object') {
$e = $e.message
this[kHandle].render(
request,
response,
$e
)
} else {
this[kHandle].render(
request,
response,
$e
)
}
this.report($e)
this[kHandle].render(
request,
response,
$e
)


}

unauthenticated($request, $response, $exception)
{
return $request.expectsJson()
? $response.json({'message' : $exception.message}, 401)
: $response.redirect().to($exception.redirectTo() || route('login'));
unauthenticated($request, $response, $exception) {
return $request.expectsJson() ?
$response.json({ 'message': $exception.message }, 401) :
$response.redirect().to($exception.redirectTo() || route('login'));
}

redirect(response, $e) {
response.with($e.getFlash()).withErrors($e.getErrors()).withInput($e.wantedInput()).redirect($e.getUrl());
response.with(...$e.getFlash()).withErrors(...$e.getErrors()).withInput($e.wantedInput()).redirect($e.getUrl());
}

jsonException(response, $e) {
Expand All @@ -91,7 +96,7 @@ class Handler {
this.report($e)
response.send($e)
}

convertValidationExceptionToResponse(request, response, $e) {
if ($e.response) {
return $e.response;
Expand All @@ -111,7 +116,7 @@ class Handler {

invalid(request, response, $exception) {

if(request.session instanceof Session){
if (request.session instanceof Session) {
response.withInput(Object.except(request.input(), this.$dontFlash))
.withErrors($exception.all())
}
Expand Down
49 changes: 19 additions & 30 deletions http/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,38 @@ const KernelContract = require('@ostro/contracts/http/kernel')
const HttpContext = require('./httpContext')
const kCachedMiddleware = Symbol('cachedMiddleware')
class Kernel extends KernelContract {

get $bootstrappers() {
return [
'@ostro/foundation/bootstrap/loadEnvironmentVariables',
'@ostro/foundation/bootstrap/loadConfiguration',
'@ostro/foundation/bootstrap/registerFacades',
'@ostro/foundation/bootstrap/registerProviders',
'@ostro/foundation/bootstrap/bootProviders',
'@ostro/foundation/bootstrap/handleSystemError',
];
}

get $defaultMiddlewares() {
return []
}
$bootstrappers = [
'@ostro/foundation/bootstrap/loadEnvironmentVariables',
'@ostro/foundation/bootstrap/loadConfiguration',
'@ostro/foundation/bootstrap/registerFacades',
'@ostro/foundation/bootstrap/registerProviders',
'@ostro/foundation/bootstrap/bootProviders',
'@ostro/foundation/bootstrap/handleSystemError',
];

get $middlewareGroups() {
return {}
}
$defaultMiddlewares = [];

get $namedMiddlewares() {
return {}
}
$middlewareGroups = {};

get $middlewarePriority() {
return [
require('@ostro/foundation/exception/middleware/exceptionHandler'),
require('@ostro/foundation/view/middleware/BindViewOnResponse'),
$namedMiddlewares = {};

];
}
$middlewarePriority = [
require('@ostro/foundation/exception/middleware/exceptionHandler'),
require('@ostro/foundation/view/middleware/BindViewOnResponse'),
];

constructor() {
super()

this.bootstrap()
this.$router = this.$app['router']
this.syncMiddlewareToRouter();
this.PrepareRouter()

}

handle() {
return this.$router.handle()
this.syncMiddlewareToRouter();
this.PrepareRouter()
return this.$router.handle()
}

syncMiddlewareToRouter() {
Expand Down
Loading

0 comments on commit 7c7a7f7

Please sign in to comment.