Skip to content

Commit

Permalink
Merge pull request #75 from josephmancuso/develop
Browse files Browse the repository at this point in the history
Service Container Support
  • Loading branch information
josephmancuso committed Feb 1, 2018
2 parents e6896f8 + b6450ba commit 4ed1e16
Show file tree
Hide file tree
Showing 39 changed files with 41 additions and 1,913 deletions.
2 changes: 1 addition & 1 deletion app/http/controllers/WelcomeController.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class WelcomeController(object):
def __init__(self):
pass

def show(self, request):
def show(self):
''' Show Welcome Template '''
return view('welcome', {'app': application})
11 changes: 11 additions & 0 deletions app/providers/UserModelProvider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from masonite.provider import ServiceProvider
from app.User import User

class UserModelProvider(ServiceProvider):
''' Binds the User model into the Service Container '''

def register(self):
self.app.bind('User', User)

def boot(self):
pass
31 changes: 24 additions & 7 deletions bootstrap/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
from masonite.request import Request
from masonite.routes import Route
from masonite.storage import Storage
from config import middleware
from masonite.app import App
from config import middleware, application
from pydoc import locate



# Run once and only once the server is ran
# This will not actually compile if the libsass module in not installed
Storage().compile_sass()
Expand All @@ -23,6 +23,27 @@ def app(environ, start_response):
os.environ.setdefault('REQUEST_METHOD', environ['REQUEST_METHOD'])
os.environ.setdefault('URI_PATH', environ['PATH_INFO'])

# Instantiate the Service Container
app = App()

# Instantiate the Request object.
# This is the `request` object passed into controller methods
request = Request(environ)

# Bind the Request object into the container
app.bind('Request', request)

# Execute all the register methods in all containers
for provider in application.PROVIDERS:
locate(provider)().load_app(app).register()

# Execute all the boot methods in all containers
for provider in application.PROVIDERS:
app.resolve(locate(provider)().boot)

# Load the container into the request
app.make('Request').load_app(app)

router = Route(environ)

if router.is_post():
Expand All @@ -37,10 +58,6 @@ def app(environ, start_response):
import routes.web
routes = routes.web.ROUTES

# Instantiate the Request object.
# This is the `request` object passed into controller methods
request = Request(environ)

# Check all http routes
for route in routes:
# Compiles the given route to regex
Expand Down Expand Up @@ -88,7 +105,7 @@ def app(environ, start_response):
# Get the data from the route. This data is typically the output
# of the controller method
if not request.redirect_url:
data = router.get(route.route, route.output(request))
data = router.get(route.route, app.resolve(route.output))

# Loads the request in so the middleware specified is able to use the
# request object. This is after middleware and is ran after the request
Expand Down
6 changes: 4 additions & 2 deletions config/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
|
'''

KEY = os.environ.get('key')
KEY = os.environ.get('KEY')

'''
|--------------------------------------------------------------------------
Expand All @@ -64,7 +64,9 @@
|
'''

PROVIDERS = []
PROVIDERS = [
'app.providers.UserModelProvider.UserModelProvider'
]

'''
|--------------------------------------------------------------------------
Expand Down
41 changes: 0 additions & 41 deletions docs/1.-Installation.md

This file was deleted.

23 changes: 0 additions & 23 deletions docs/1.1-Configuration.md

This file was deleted.

110 changes: 0 additions & 110 deletions docs/1.2-Directory-Structure.md

This file was deleted.

41 changes: 0 additions & 41 deletions docs/1.3-Deployment.md

This file was deleted.

Loading

0 comments on commit 4ed1e16

Please sign in to comment.