-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Kernel.py
107 lines (88 loc) · 4.04 KB
/
Kernel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from masonite.foundation import response_handler
from masonite.storage import StorageCapsule
from masonite.auth import Sign
from masonite.environment import LoadEnvironment
from masonite.utils.structures import load
from masonite.utils.location import base_path
from masonite.middleware import (
SessionMiddleware,
EncryptCookies,
LoadUserMiddleware,
MaintenanceModeMiddleware,
)
from masonite.routes import Route
from masonite.configuration.Configuration import Configuration
from masonite.configuration import config
from app.middlewares import VerifyCsrfToken, AuthenticationMiddleware
class Kernel:
http_middleware = [MaintenanceModeMiddleware, EncryptCookies]
route_middleware = {
"web": [SessionMiddleware, LoadUserMiddleware, VerifyCsrfToken],
"auth": [AuthenticationMiddleware],
}
def __init__(self, app):
self.application = app
def register(self):
# Register routes
self.load_environment()
self.register_configurations()
self.register_middleware()
self.register_routes()
self.register_database()
self.register_templates()
self.register_storage()
def load_environment(self):
LoadEnvironment()
def register_configurations(self):
# load configuration
self.application.bind("config.location", "config")
configuration = Configuration(self.application)
configuration.load()
self.application.bind("config", configuration)
key = config("application.key")
self.application.bind("key", key)
self.application.bind("sign", Sign(key))
# set locations
self.application.bind("resources.location", "resources/")
self.application.bind("controllers.location", "app/controllers")
self.application.bind("jobs.location", "app/jobs")
self.application.bind("providers.location", "app/providers")
self.application.bind("mailables.location", "app/mailables")
self.application.bind("listeners.location", "app/listeners")
self.application.bind("validation.location", "app/validation")
self.application.bind("notifications.location", "app/notifications")
self.application.bind("events.location", "app/events")
self.application.bind("tasks.location", "app/tasks")
self.application.bind("models.location", "app/models")
self.application.bind("observers.location", "app/models/observers")
self.application.bind("policies.location", "app/policies")
self.application.bind("commands.location", "app/commands")
self.application.bind("middlewares.location", "app/middlewares")
self.application.bind("server.runner", "masonite.commands.ServeCommand.main")
def register_middleware(self):
self.application.make("middleware").add(self.route_middleware).add(self.http_middleware)
def register_routes(self):
Route.set_controller_locations(self.application.make("controllers.location"))
self.application.bind("routes.location", "routes/web")
self.application.make("router").add(
Route.group(
load(self.application.make("routes.location"), "ROUTES"), middleware=["web"]
)
)
def register_database(self):
from masoniteorm.query import QueryBuilder
self.application.bind(
"builder",
QueryBuilder(connection_details=config("database.databases")),
)
self.application.bind("migrations.location", "databases/migrations")
self.application.bind("seeds.location", "databases/seeds")
self.application.bind("resolver", config("database.db"))
def register_templates(self):
self.application.bind("views.location", "templates/")
def register_storage(self):
storage = StorageCapsule()
storage.add_storage_assets(config("filesystem.staticfiles"))
self.application.bind("storage_capsule", storage)
self.application.set_response_handler(response_handler)
self.application.use_storage_path(base_path("storage"))