Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2016-09-03 12:08:58 +0100
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
ec17bd86085fb5ac94f3bd4c2fe216fb3b45c6dd
ec17bd86
1 parent
0dbb8bab
Improved Exception handling, Removed npm requirement for testing
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
30 deletions
.travis.yml
app/Exceptions/Handler.php
app/Exceptions/PrettyException.php
app/Providers/AppServiceProvider.php
app/Services/SocialAuthService.php
app/helpers.php
phpunit.xml
.travis.yml
View file @
ec17bd8
...
...
@@ -6,7 +6,6 @@ php:
cache
:
directories
:
-
node_modules
-
$HOME/.composer/cache
addons
:
...
...
@@ -16,9 +15,6 @@ addons:
-
mysql-client-core-5.6
-
mysql-client-5.6
before_install
:
-
npm install -g npm@latest
before_script
:
-
mysql -u root -e 'create database `bookstack-test`;'
-
composer config -g github-oauth.github.com $GITHUB_ACCESS_TOKEN
...
...
@@ -26,8 +22,6 @@ before_script:
-
composer self-update
-
composer dump-autoload --no-interaction
-
composer install --prefer-dist --no-interaction
-
npm install
-
./node_modules/.bin/gulp
-
php artisan clear-compiled -n
-
php artisan optimize -n
-
php artisan migrate --force -n --database=mysql_testing
...
...
app/Exceptions/Handler.php
View file @
ec17bd8
...
...
@@ -47,19 +47,44 @@ class Handler extends ExceptionHandler
{
// Handle notify exceptions which will redirect to the
// specified location then show a notification message.
if
(
$
e
instanceof
NotifyException
)
{
session
()
->
flash
(
'error'
,
$
e
->
message
);
if
(
$
this
->
isExceptionType
(
$e
,
NotifyException
::
class
)
)
{
session
()
->
flash
(
'error'
,
$
this
->
getOriginalMessage
(
$e
)
);
return
redirect
(
$e
->
redirectLocation
);
}
// Handle pretty exceptions which will show a friendly application-fitting page
// Which will include the basic message to point the user roughly to the cause.
if
(
(
$e
instanceof
PrettyException
||
$e
->
getPrevious
()
instanceof
PrettyException
)
&&
!
config
(
'app.debug'
))
{
$message
=
(
$e
instanceof
PrettyException
)
?
$e
->
getMessage
()
:
$e
->
getPrevious
()
->
getMessage
(
);
if
(
$this
->
isExceptionType
(
$e
,
PrettyException
::
class
)
&&
!
config
(
'app.debug'
))
{
$message
=
$this
->
getOriginalMessage
(
$e
);
$code
=
(
$e
->
getCode
()
===
0
)
?
500
:
$e
->
getCode
();
return
response
()
->
view
(
'errors/'
.
$code
,
[
'message'
=>
$message
],
$code
);
}
return
parent
::
render
(
$request
,
$e
);
}
/**
* Check the exception chain to compare against the original exception type.
* @param Exception $e
* @param $type
* @return bool
*/
protected
function
isExceptionType
(
Exception
$e
,
$type
)
{
do
{
if
(
is_a
(
$e
,
$type
))
return
true
;
}
while
(
$e
=
$e
->
getPrevious
());
return
false
;
}
/**
* Get original exception message.
* @param Exception $e
* @return string
*/
protected
function
getOriginalMessage
(
Exception
$e
)
{
do
{
$message
=
$e
->
getMessage
();
}
while
(
$e
=
$e
->
getPrevious
());
return
$message
;
}
}
...
...
app/Exceptions/PrettyException.php
View file @
ec17bd8
<?php
namespace
BookStack\Exceptions
;
use
Exception
;
class
PrettyException
extends
Exception
{}
\ No newline at end of file
class
PrettyException
extends
\Exception
{}
\ No newline at end of file
...
...
app/Providers/AppServiceProvider.php
View file @
ec17bd8
<?php
<?php
namespace
BookStack\Providers
;
namespace
BookStack\Providers
;
use
Illuminate\Support\Facades\Auth
;
use
Illuminate\Support\ServiceProvider
;
use
BookStack\User
;
class
AppServiceProvider
extends
ServiceProvider
{
...
...
app/Services/SocialAuthService.php
View file @
ec17bd8
...
...
@@ -158,7 +158,7 @@ class SocialAuthService
$driver
=
trim
(
strtolower
(
$socialDriver
));
if
(
!
in_array
(
$driver
,
$this
->
validSocialDrivers
))
abort
(
404
,
'Social Driver Not Found'
);
if
(
!
$this
->
checkDriverConfigured
(
$driver
))
throw
new
SocialDriverNotConfigured
;
if
(
!
$this
->
checkDriverConfigured
(
$driver
))
throw
new
SocialDriverNotConfigured
(
"Your
{
$driver
}
social settings are not configured correctly."
)
;
return
$driver
;
}
...
...
app/helpers.php
View file @
ec17bd8
...
...
@@ -7,25 +7,32 @@ use BookStack\Ownable;
*
* @param string $file
* @return string
*
* @throws \InvalidArgumentException
* @throws Exception
*/
function
versioned_asset
(
$file
)
function
versioned_asset
(
$file
=
''
)
{
static
$manifest
=
null
;
// Don't require css and JS assets for testing
if
(
config
(
'app.env'
)
===
'testing'
)
return
''
;
if
(
is_null
(
$manifest
))
{
$manifest
=
json_decode
(
file_get_contents
(
public_path
(
'build/manifest.json'
)),
true
);
static
$manifest
=
null
;
$manifestPath
=
'build/manifest.json'
;
if
(
is_null
(
$manifest
)
&&
file_exists
(
$manifestPath
))
{
$manifest
=
json_decode
(
file_get_contents
(
public_path
(
$manifestPath
)),
true
);
}
else
if
(
!
file_exists
(
$manifestPath
))
{
if
(
config
(
'app.env'
)
!==
'production'
)
{
$path
=
public_path
(
$manifestPath
);
$error
=
"No
{
$path
}
file found, Ensure you have built the css/js assets using gulp."
;
}
else
{
$error
=
"No
{
$manifestPath
}
file found, Ensure you are using the release version of BookStack"
;
}
throw
new
\Exception
(
$error
);
}
if
(
isset
(
$manifest
[
$file
]))
{
return
baseUrl
(
$manifest
[
$file
]);
}
if
(
file_exists
(
public_path
(
$file
)))
{
return
baseUrl
(
$file
);
}
throw
new
InvalidArgumentException
(
"File
{
$file
}
not defined in asset manifest."
);
}
...
...
phpunit.xml
View file @
ec17bd8
...
...
@@ -28,7 +28,7 @@
<env
name=
"DB_CONNECTION"
value=
"mysql_testing"
/>
<env
name=
"MAIL_DRIVER"
value=
"log"
/>
<env
name=
"AUTH_METHOD"
value=
"standard"
/>
<env
name=
"DISABLE_EXTERNAL_SERVICES"
value=
"
fals
e"
/>
<env
name=
"DISABLE_EXTERNAL_SERVICES"
value=
"
tru
e"
/>
<env
name=
"LDAP_VERSION"
value=
"3"
/>
<env
name=
"GITHUB_APP_ID"
value=
"aaaaaaaaaaaaaa"
/>
<env
name=
"GITHUB_APP_SECRET"
value=
"aaaaaaaaaaaaaa"
/>
...
...
Please
register
or
sign in
to post a comment