Skip to content

Commit

Permalink
Merge 602ebca into 7008101
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Aug 26, 2018
2 parents 7008101 + 602ebca commit e69b595
Show file tree
Hide file tree
Showing 17 changed files with 285 additions and 56 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ uploads/test.jpg
bootstrap/cache/*.html
bootstrap/cache/*.txt
/uploads/
.coverage
.coverage
.idea/
150 changes: 150 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Sentimental Versioning](http://sentimentalversioning.org/).

## [2.0.16](https://github.com/MasoniteFramework/core/releases/tag/v2.0.16) - 2018-08-22
### Added
- Added docstrings to nearly all classes
- Added container hooks
- Added strict and override options to the container
- Added a validator command
- Added middleware groups
- Added change log
- Added route compilers

## [2.0.15](https://github.com/MasoniteFramework/core/releases/tag/v2.0.15) - 2018-08-12

### Fixed
- Fixed an issue where the craft info command was calling the masonite-cli command prematurely.

## [2.0.14](https://github.com/MasoniteFramework/core/releases/tag/v2.0.14) - 2018-08-08

### Added
- Added casting for validations and added a validation helper
- Added ability to set a dictionary in the session and be able to automatically JSON encode and decode.

### Fixed
- Fixed cryptography dependency
- Fixed issue where URL endpoints could not have - or . in them.

## [2.0.13](https://github.com/MasoniteFramework/core/releases/tag/v2.0.13) - 2018-07-28

### Fixed
- Fixed seed files not being able to import user models
- Fixed models not being able to be created in deeper directories

## [2.0.12](https://github.com/MasoniteFramework/core/releases/tag/v2.0.12) - 2018-07-19

### Fixed
- Fixed exception thrown when a route inside a group route did not have a name but the route did

## [2.0.11](https://github.com/MasoniteFramework/core/releases/tag/v2.0.11) - 2018-07-14

### Fixed
- Made a hot fix for the .env file not being found on some systems

## [2.0.10](https://github.com/MasoniteFramework/core/releases/tag/v2.0.10) - 2018-07-10

### Added

- Added back method to request class
- Added ability to add custom filters
- Added better route groups

## [2.0.9](https://github.com/MasoniteFramework/core/releases/tag/v2.0.9) - 2018-07-06

### Added

- Added a possible default value to the request input
- Added a way to do multiple values in the request.has() method
- Added request route #203
- Added a pop method to request to remove inputs
- Added a url_from_controller method to request
- Added a contain method to request to request
- Added a is named route method to request

## [2.0.8](https://github.com/MasoniteFramework/core/releases/tag/v2.0.8) - 2018-06-26

### Added
- Added craft info command
- Added the ability to add environments to the container and View Class

### Changed
- Moved the route middleware to the top of the container so it can be appended onto by packages.

### Fixed
- Fixed what errors the status code provider is executed on (500 and 404)

## [2.0.7](https://github.com/MasoniteFramework/core/releases/tag/v2.0.7) - 2018-06-24

### Added
- Added warning message to craft serve command if applications are not correctly patched for 2.0

## [2.0.6](https://github.com/MasoniteFramework/core/releases/tag/v2.0.6) - 2018-06-22

### Fixed
- Fixed windows throwing bad exceptions in the exception view

## [2.0.5](https://github.com/MasoniteFramework/core/releases/tag/v2.0.5) - 2018-06-22

### Added
- Added better exception handling for Masonite encrypted key signing

## [2.0.4](https://github.com/MasoniteFramework/core/releases/tag/v2.0.4) - 2018-06-16

### Fixed
- Fixed circular cleo version.

## [2.0.3](https://github.com/MasoniteFramework/core/releases/tag/v2.0.3) - 2018-06-16

### Fixed
- Fixed controller constructors not being resolved by the container

## [2.0.2](https://github.com/MasoniteFramework/core/releases/tag/v2.0.2) - 2018-06-15

### Changed
- Bumped requests version

## [2.0.1](https://github.com/MasoniteFramework/core/releases/tag/v2.0.1) - 2018-06-14

### Added
- Added Tinker Command #116
- Added Show Routes Command #117
- Added Automatic Code Reloading to Serve Command #119
- Added autoloading support #146
- Adds a new get_request_method method to request class
- Adds a new parameter to the all() method to get all the inputs without the framework internals
- Added Masontite Scheduler
- Added Database Seeding Support #168
- Added static file helper #167
- Added Password helper
- Added dot notation to upload drivers
- Added Status Code provider and support #165
- Added support for making location dictionaries to upload drivers
- Adds better .env environment support #172
- Added activate subdomain #173
- Added class based drivers
- Added collect method the he autoload class and changes the return type of instance and collect as well as added an instantiate to the load method #178

### Changed

- Controller constructors are resolved by the container
- Updated all dependencies to latest version.
- Providers now need to be imported into a provider.py file and removed from the application.py file. #177
- Renamed Request.redirectTo to Request.redirect_to #152
- Changed the csrf middleware accordingly.

### Removed
- Removed all duplicated import class names
- Removed need for providers list to also have duplicated class names
- Removed redirection provider completely
- Removed database specific dependencies

### Notes
- Need documentation for the new Request.only() method.

## [Older Releases](https://github.com/MasoniteFramework/core/releases?after=v2.0.1)


2 changes: 2 additions & 0 deletions config/application.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

DEBUG = 'True'

KEY = 'NCTpkICMlTXie5te9nJniMj9aVbPM6lsjeq5iDZ0dqY='

BASE_DIRECTORY = os.getcwd()
Expand Down
5 changes: 5 additions & 0 deletions config/middleware.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from app.http.middleware.MiddlewareTest import MiddlewareTest
from masonite.middleware import JsonResponseMiddleware
from app.http.middleware.AddAttributeMiddleware import AddAttributeMiddleware


Expand All @@ -9,3 +10,7 @@
AddAttributeMiddleware,
]
}

HTTP_MIDDLEWARE = [
JsonResponseMiddleware
]
Binary file removed masonite/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion masonite/exception_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _render(self):
self._app.make('HookHandler').fire('*ExceptionHook')

# Check if DEBUG is False
if not self._app.make('Application').DEBUG or self._app.make('Application').DEBUG == 'False':
if not self._app.make('Application').DEBUG:
return

# return a view
Expand Down
4 changes: 4 additions & 0 deletions masonite/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ class InvalidSecretKey(Exception):

class StrictContainerException(Exception):
pass


class InvalidRouteCompileException(Exception):
pass
2 changes: 1 addition & 1 deletion masonite/info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Module for specifying the Masonite version in a central location.
"""

VERSION = '2.0.15'
VERSION = '2.1.0'
19 changes: 19 additions & 0 deletions masonite/middleware/JsonResponseMiddleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json

class JsonResponseMiddleware:

def __init__(self, Request):
self.request = Request

def after(self):
if not self.request.header('Content-Type'):
if isinstance(self.request.app().make('Response'), dict):
self.request.header(
'Content-Type', 'application/json; charset=utf-8', http_prefix=None)
self.request.app().bind(
'Response',
str(json.dumps(self.request.app().make('Response')))
)
else:
self.request.header(
'Content-Type', 'text/html; charset=utf-8', http_prefix=None)
2 changes: 2 additions & 0 deletions masonite/middleware/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .JsonResponseMiddleware import JsonResponseMiddleware
from .CsrfMiddleware import CsrfMiddleware
8 changes: 8 additions & 0 deletions masonite/providers/AppProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def register(self):
self.app.bind('Container', self.app)
self.app.bind('ExceptionHandler', ExceptionHandler(self.app))
self.app.bind('RouteMiddleware', middleware.ROUTE_MIDDLEWARE)
self.app.bind('HttpMiddleware', middleware.HTTP_MIDDLEWARE)

# Insert Commands
self.app.bind('MasoniteAuthCommand', AuthCommand())
Expand All @@ -59,6 +60,7 @@ def register(self):
self.app.bind('MasoniteValidatorCommand', ValidatorCommand())

self._autoload(application.AUTOLOAD)
self._set_application_debug_level()

def boot(self, Environ, Request, Route):
self.app.bind('Headers', [])
Expand All @@ -68,3 +70,9 @@ def boot(self, Environ, Request, Route):

def _autoload(self, directories):
Autoload(self.app).load(directories)

def _set_application_debug_level(self):
if self.app.make('Application').DEBUG == 'True':
self.app.make('Application').DEBUG == True
elif self.app.make('Application').DEBUG == 'False':
self.app.make('Application').DEBUG == False
61 changes: 21 additions & 40 deletions masonite/providers/RouteProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RouteProvider(ServiceProvider):
def register(self):
pass

def boot(self, WebRoutes, Route, Request, Environ, Headers):
def boot(self, WebRoutes, Route, Request, Environ, Headers, Application):
# All routes joined
for route in WebRoutes:
router = Route
Expand All @@ -38,20 +38,6 @@ def boot(self, WebRoutes, Route, Request, Environ, Headers):
else:
matchurl = re.compile(regex.replace(r'\/$', r'$'))

# This will create a dictionary of parameters given.
# This is sort of a short
# but complex way to retrieve the url parameters.
# This is the code used to
# convert /url/@firstname/@lastname to
# {'firstmane': 'joseph', 'lastname': 'mancuso'}
try:
parameter_dict = {}
for index, value in enumerate(matchurl.match(router.url).groups()):
parameter_dict[router.generated_url_list()[index]] = value
request.set_params(parameter_dict)
except AttributeError:
pass

"""
|--------------------------------------------------------------------------
| Houston, we've got a match
Expand All @@ -70,6 +56,21 @@ def boot(self, WebRoutes, Route, Request, Environ, Headers):
if not route.has_required_domain():
self.app.bind('Response', 'Route not found. Error 404')
continue

# This will create a dictionary of parameters given.
# This is sort of a short
# but complex way to retrieve the url parameters.
# This is the code used to
# convert /url/@firstname/@lastname to
# {'firstmane': 'joseph', 'lastname': 'mancuso'}
try:
parameter_dict = {}
for index, value in enumerate(matchurl.match(router.url).groups()):
parameter_dict[router.generated_url_list()[index]] = value
request.set_params(parameter_dict)
except AttributeError:
pass

"""
|--------------------------------------------------------------------------
| Execute Before Middleware
Expand All @@ -87,7 +88,8 @@ def boot(self, WebRoutes, Route, Request, Environ, Headers):
located_middleware.before()

# Show a helper in the terminal of which route has been visited
print(route.method_type + ' Route: ' + router.url)
if Application.DEBUG:
print(route.method_type + ' Route: ' + router.url)

# Loads the request in so the middleware
# specified is able to use the
Expand All @@ -99,35 +101,14 @@ def boot(self, WebRoutes, Route, Request, Environ, Headers):
# output of the controller method
if not request.redirect_url:
Request.status('200 OK')

# Resolve Controller Constructor
controller = self.app.resolve(route.controller)

# Resolve Controller Method
response = self.app.resolve(
getattr(controller, route.controller_method))

if isinstance(response, View):
response = response.rendered_template

response = route.get_response()

self.app.bind(
'Response',
router.get(route.route, response)
)

# If the Content-Type was not set in the view or before this
if not Request.header('Content-Type'):
if isinstance(response, dict):
Request.header(
'Content-Type', 'application/json; charset=utf-8', http_prefix=None)
self.app.bind(
'Response',
str(json.dumps(response))
)
else:
Request.header(
'Content-Type', 'text/html; charset=utf-8', http_prefix=None)

# Loads the request in so the middleware
# specified is able to use the
# request object. This is after middleware
Expand All @@ -142,7 +123,7 @@ def boot(self, WebRoutes, Route, Request, Environ, Headers):
| This is middleware with an after method.
|
"""

for http_middleware in self.app.make('HttpMiddleware'):
located_middleware = self.app.resolve(
http_middleware
Expand Down
4 changes: 2 additions & 2 deletions masonite/providers/StatusCodeProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
class ServerErrorExceptionHook:

def load(self, app):
if app.make('Application').DEBUG == 'True' or app.make('Application').DEBUG == True:
if app.make('Application').DEBUG:
return

request = app.make('Request').status('500 Internal Server Error')
app.make('Request').status('500 Internal Server Error')
if app.make('ViewClass').exists('errors/500'):
rendered_view = app.make('View')('errors/500').rendered_template
else:
Expand Down
Loading

0 comments on commit e69b595

Please sign in to comment.