Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit81fa28a

Browse files
author
Julien Neuhart
committed
Symfony 4.2 support + various improvements
1 parent5877b3c commit81fa28a

File tree

47 files changed

+4402
-2914
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4402
-2914
lines changed

‎app/.env.dist‎renamed to ‎app/.env‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
# This file is a "template" of which env vars need to be defined for your application
2-
# Copy this file to .env file for development, create environment variables when deploying to production
1+
# This file defines all environment variables that the application needs.
2+
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE.
3+
# Use ".env.local" for local overrides during development.
4+
# Use real environment variables when deploying to production.
35
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
46

57
###> symfony/framework-bundle ###
68
APP_ENV=dev
7-
APP_SECRET=8d2a5c935d8ef1c0e2b751147382bc75
9+
APP_SECRET=9bb5629914a418a2267cda32d336ded5
810
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
9-
#TRUSTED_HOSTS=localhost,example.com
11+
#TRUSTED_HOSTS='^localhost|example\.com$'
1012
###< symfony/framework-bundle ###
1113

1214
###> doctrine/doctrine-bundle ###

‎app/.env.test‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# define your env variables for the test env here
2+
KERNEL_CLASS='App\Kernel'
3+
APP_SECRET='s$cretf0rt3st'
4+
SYMFONY_DEPRECATIONS_HELPER=999999

‎app/.gitignore‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
###> symfony/framework-bundle ###
3-
/.env
3+
/.env.local
4+
/.env.*.local
45
/public/bundles/
56
/var/
67
/vendor/
@@ -15,14 +16,14 @@
1516
/.web-server-pid
1617
###< symfony/web-server-bundle ###
1718

18-
###> symfony/webpack-encore-pack ###
19-
/node_modules/
20-
/public/build/
21-
npm-debug.log
22-
yarn-error.log
23-
###< symfony/webpack-encore-pack ###
24-
2519
###> squizlabs/php_codesniffer ###
2620
/.phpcs-cache
2721
/phpcs.xml
2822
###< squizlabs/php_codesniffer ###
23+
24+
###> symfony/webpack-encore-bundle ###
25+
/node_modules/
26+
/public/build/
27+
npm-debug.log
28+
yarn-error.log
29+
###< symfony/webpack-encore-bundle ###

‎app/assets/vue/App.vue‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,24 @@
2626

2727
<script>
2828
importaxiosfrom'axios';
29-
importrouterfrom'./router';
3029
3130
exportdefault {
3231
name:'app',
33-
beforeMount () {
34-
let vueRouting=this.$parent.$el.attributes['data-vue-routing'].value,
35-
queryParameters=JSON.parse(this.$parent.$el.attributes['data-query-parameters'].value);
36-
37-
router.push({path: vueRouting, query: queryParameters});
38-
},
3932
created () {
33+
let isAuthenticated=JSON.parse(this.$parent.$el.attributes['data-is-authenticated'].value),
34+
roles=JSON.parse(this.$parent.$el.attributes['data-roles'].value);
35+
36+
let payload= { isAuthenticated: isAuthenticated, roles: roles };
37+
this.$store.dispatch('security/onRefresh', payload);
38+
4039
axios.interceptors.response.use(undefined, (err)=> {
4140
returnnewPromise(()=> {
4241
if (err.response.status===403) {
4342
this.$router.push({path:'/login'})
43+
}elseif (err.response.status===500) {
44+
document.open();
45+
document.write(err.response.data);
46+
document.close();
4447
}
4548
throw err;
4649
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template>
2+
<divclass="alert alert-danger"role="alert">
3+
{{ error.response.data.error }}
4+
</div>
5+
</template>
6+
7+
<script>
8+
exportdefault {
9+
name:'errorMessage',
10+
props: ['error'],
11+
}
12+
</script>

‎app/assets/vue/store/security.js‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default {
66
isLoading:false,
77
error:null,
88
isAuthenticated:false,
9+
roles:[],
910
},
1011
getters:{
1112
isLoading(state){
@@ -18,33 +19,49 @@ export default {
1819
returnstate.error;
1920
},
2021
isAuthenticated(state){
21-
state.isAuthenticated=document.cookie.indexOf('authenticated')!==-1;
2222
returnstate.isAuthenticated;
2323
},
24+
hasRole(state){
25+
returnrole=>{
26+
returnstate.roles.indexOf(role)!==-1;
27+
}
28+
},
2429
},
2530
mutations:{
2631
['AUTHENTICATING'](state){
2732
state.isLoading=true;
2833
state.error=null;
2934
state.isAuthenticated=false;
35+
state.roles=[];
3036
},
31-
['AUTHENTICATING_SUCCESS'](state){
37+
['AUTHENTICATING_SUCCESS'](state,roles){
3238
state.isLoading=false;
3339
state.error=null;
3440
state.isAuthenticated=true;
41+
state.roles=roles;
3542
},
3643
['AUTHENTICATING_ERROR'](state,error){
3744
state.isLoading=false;
3845
state.error=error;
3946
state.isAuthenticated=false;
47+
state.roles=[];
48+
},
49+
['PROVIDING_DATA_ON_REFRESH_SUCCESS'](state,payload){
50+
state.isLoading=false;
51+
state.error=null;
52+
state.isAuthenticated=payload.isAuthenticated;
53+
state.roles=payload.roles;
4054
},
4155
},
4256
actions:{
4357
login({commit},payload){
4458
commit('AUTHENTICATING');
4559
returnSecurityAPI.login(payload.login,payload.password)
46-
.then(()=>commit('AUTHENTICATING_SUCCESS'))
60+
.then(res=>commit('AUTHENTICATING_SUCCESS',res.data))
4761
.catch(err=>commit('AUTHENTICATING_ERROR',err));
4862
},
63+
onRefresh({commit},payload){
64+
commit('PROVIDING_DATA_ON_REFRESH_SUCCESS',payload);
65+
},
4966
},
5067
}

‎app/assets/vue/views/Login.vue‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,36 @@
2525
</div>
2626

2727
<divv-else-if="hasError"class="row col">
28-
<divclass="alert alert-danger"role="alert">
29-
{{ error }}
30-
</div>
28+
<error-message:error="error"></error-message>
3129
</div>
3230
</div>
3331
</template>
3432

3533
<script>
34+
importErrorMessagefrom'../components/ErrorMessage';
35+
3636
exportdefault {
3737
name:'login',
38+
components: {
39+
ErrorMessage,
40+
},
3841
data () {
3942
return {
4043
login:'',
4144
password:'',
4245
};
4346
},
47+
created () {
48+
let redirect=this.$route.query.redirect;
49+
50+
if (this.$store.getters['security/isAuthenticated']) {
51+
if (typeof redirect!=='undefined') {
52+
this.$router.push({path: redirect});
53+
}else {
54+
this.$router.push({path:'/home'});
55+
}
56+
}
57+
},
4458
computed: {
4559
isLoading () {
4660
returnthis.$store.getters['security/isLoading'];
@@ -60,9 +74,9 @@
6074
this.$store.dispatch('security/login', payload)
6175
.then(()=> {
6276
if (typeof redirect!=='undefined') {
63-
this.$router.push({path: redirect});
77+
this.$router.push({path: redirect});
6478
}else {
65-
this.$router.push({path:'/home'});
79+
this.$router.push({path:'/home'});
6680
}
6781
});
6882
},

‎app/assets/vue/views/Posts.vue‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<h1>Posts</h1>
55
</div>
66

7-
<divclass="row col">
7+
<divclass="row col"v-if="canCreatePost">
88
<form>
99
<divclass="form-row">
1010
<divclass="col-8">
@@ -23,7 +23,7 @@
2323

2424
<divv-else-if="hasError"class="row col">
2525
<divclass="alert alert-danger"role="alert">
26-
{{error }}
26+
<error-message:error="error"></error-message>
2727
</div>
2828
</div>
2929

@@ -39,11 +39,13 @@
3939

4040
<script>
4141
importPostfrom'../components/Post';
42+
importErrorMessagefrom'../components/ErrorMessage';
4243
4344
exportdefault {
4445
name:'posts',
4546
components: {
46-
Post
47+
Post,
48+
ErrorMessage,
4749
},
4850
data () {
4951
return {
@@ -69,6 +71,9 @@
6971
posts () {
7072
returnthis.$store.getters['post/posts'];
7173
},
74+
canCreatePost () {
75+
returnthis.$store.getters['security/hasRole']('ROLE_FOO');
76+
}
7277
},
7378
methods: {
7479
createPost () {

‎app/bin/console‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,36 @@ use App\Kernel;
55
useSymfony\Bundle\FrameworkBundle\Console\Application;
66
useSymfony\Component\Console\Input\ArgvInput;
77
useSymfony\Component\Debug\Debug;
8-
useSymfony\Component\Dotenv\Dotenv;
98

109
set_time_limit(0);
1110

12-
require__DIR__.'/../vendor/autoload.php';
11+
requiredirname(__DIR__).'/vendor/autoload.php';
1312

1413
if (!class_exists(Application::class)) {
15-
thrownew\RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
14+
thrownewRuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
1615
}
1716

18-
if (!isset($_SERVER['APP_ENV'])) {
19-
if (!class_exists(Dotenv::class)) {
20-
thrownew \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
21-
}
22-
(newDotenv())->load(__DIR__.'/../.env');
17+
$input =newArgvInput();
18+
if (null !==$_ENV['APP_ENV'] =$input->getParameterOption(['--env','-e'],null,true)) {
19+
putenv('APP_ENV='.$_ENV['APP_ENV']);
20+
// force loading .env files when --env is defined
21+
$_SERVER['APP_ENV'] =null;
2322
}
2423

25-
$input =newArgvInput();
26-
$env =$input->getParameterOption(['--env','-e'],$_SERVER['APP_ENV'] ??'dev',true);
27-
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !==$env)) && !$input->hasParameterOption('--no-debug',true);
24+
if ($input->hasParameterOption('--no-debug',true)) {
25+
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] =$_ENV['APP_DEBUG'] ='0');
26+
}
27+
28+
requiredirname(__DIR__).'/config/bootstrap.php';
2829

29-
if ($debug) {
30+
if ($_SERVER['APP_DEBUG']) {
3031
umask(0000);
3132

3233
if (class_exists(Debug::class)) {
3334
Debug::enable();
3435
}
3536
}
3637

37-
$kernel =newKernel($env,$debug);
38+
$kernel =newKernel($_SERVER['APP_ENV'], (bool)$_SERVER['APP_DEBUG']);
3839
$application =newApplication($kernel);
3940
$application->run($input);

‎app/bin/phpunit‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-php
55
echo"Unable to find the `simple-phpunit` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
66
exit(1);
77
}
8-
if (false ===getenv('SYMFONY_DEPRECATIONS_HELPER')) {
9-
// see https://symfony.com/doc/current/components/phpunit_bridge.html#making-tests-fail
10-
putenv('SYMFONY_DEPRECATIONS_HELPER=999999');
8+
9+
if (false ===getenv('SYMFONY_PHPUNIT_VERSION')) {
10+
putenv('SYMFONY_PHPUNIT_VERSION=6.5');
1111
}
1212
if (false ===getenv('SYMFONY_PHPUNIT_REMOVE')) {
1313
putenv('SYMFONY_PHPUNIT_REMOVE=');
1414
}
15-
if (false ===getenv('SYMFONY_PHPUNIT_VERSION')) {
16-
putenv('SYMFONY_PHPUNIT_VERSION=6.5');
17-
}
1815
if (false ===getenv('SYMFONY_PHPUNIT_DIR')) {
1916
putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
2017
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp