@@ -36,57 +36,66 @@ final protected function execute(InputInterface $input, OutputInterface $output)
3636 return Command::INVALID ;
3737 }
3838
39- $ content = file_get_contents ($ input ->getArgument ('filepath ' ));
39+ try {
40+ $ content = file_get_contents ($ input ->getArgument ('filepath ' ));
4041
41- $ config = json_decode ($ content , true );
42+ if (!$ content ) {
43+ throw new \Exception ('Error reading file ' );
44+ }
4245
43- if ('admin ' === $ type ) {
44- $ io ->info ('Insert the following lines in .env.local: ' );
46+ $ config = json_decode ($ content , true , 512 , JSON_THROW_ON_ERROR );
47+ } catch (\Exception |\JsonException $ e ) {
48+ $ io ->error ($ e ->getMessage ());
4549
46- $ rejseplanenApiKey = $ config ['rejseplanenApiKey ' ] ?? '' ;
47- $ showScreenStatus = var_export ($ config ['showScreenStatus ' ] ?? false , true );
48- $ touchButtonRegions = var_export ($ config ['touchButtonRegions ' ] ?? false , true );
49- $ enhancedPreview = var_export (!empty ($ config ['previewClient ' ]), true );
50- $ loginMethods = $ config ['loginMethods ' ] ?? [];
50+ return Command::INVALID ;
51+ }
5152
52- // Remove enabled field since this is unused in v3.
53- foreach ($ loginMethods as &$ method ) {
54- unset($ method ['enabled ' ]);
53+ if ('admin ' === $ type ) {
54+ $ io ->success ('Insert the following lines in .env.local ' );
55+
56+ $ rejseplanenApiKey = $ config ['rejseplanenApiKey ' ] ?? null ;
57+ $ showScreenStatus = $ config ['showScreenStatus ' ] ?? null ;
58+ $ touchButtonRegions = $ config ['touchButtonRegions ' ] ?? null ;
59+ $ enhancedPreview = $ config ['previewClient ' ] ?? null ;
60+ $ loginMethods = $ config ['loginMethods ' ] ?? null ;
61+
62+ if (null !== $ loginMethods ) {
63+ // Remove enabled field since this is unused in v3.
64+ foreach ($ loginMethods as &$ method ) {
65+ unset($ method ['enabled ' ]);
66+ }
5567 }
5668
57- $ env = "###> Admin configuration ### \n" ;
58- $ env .= 'ADMIN_REJSEPLANEN_APIKEY=" ' .$ rejseplanenApiKey ."\"\n" ;
59- $ env .= 'ADMIN_SHOW_SCREEN_STATUS= ' .$ showScreenStatus ."\n" ;
60- $ env .= 'ADMIN_TOUCH_BUTTON_REGIONS= ' .$ touchButtonRegions ."\n" ;
61- $ env .= "ADMIN_LOGIN_METHODS=' " .json_encode ($ loginMethods )."' \n" ;
62- $ env .= 'ADMIN_ENHANCED_PREVIEW= ' .$ enhancedPreview ."\n" ;
63- $ env .= "###< Admin configuration ### \n" ;
64-
65- $ output ->writeln ($ env );
69+ $ io ->writeln ('###> Admin configuration ### ' );
70+ null !== $ rejseplanenApiKey && $ io ->writeln ('ADMIN_REJSEPLANEN_APIKEY=" ' .$ rejseplanenApiKey .'" ' );
71+ null !== $ showScreenStatus && $ io ->writeln ('ADMIN_SHOW_SCREEN_STATUS= ' .var_export ($ showScreenStatus , true ));
72+ null !== $ touchButtonRegions && $ io ->writeln ('ADMIN_TOUCH_BUTTON_REGIONS= ' .var_export ($ touchButtonRegions , true ));
73+ null !== $ loginMethods && $ io ->writeln ("ADMIN_LOGIN_METHODS=' " .json_encode ($ loginMethods )."' " );
74+ // This is a conversion from an url to boolean value. If the url is not empty, it is interpreted as true.
75+ !empty ($ enhancedPreview ) && $ io ->writeln ('ADMIN_ENHANCED_PREVIEW=true ' );
76+ $ io ->writeln ('###< Admin configuration ### ' );
6677 } elseif ('client ' === $ type ) {
67- $ env = " Insert the following lines in .env.local: \n\n\n" ;
78+ $ io -> success ( ' Insert the following lines in .env.local ' ) ;
6879
69- $ loginCheckTimeout = $ config ['loginCheckTimeout ' ] ?? 20000 ;
70- $ refreshTokenTimeout = $ config ['refreshTokenTimeout ' ] ?? 300000 ;
71- $ releaseTimestampIntervalTimeout = $ config ['releaseTimestampIntervalTimeout ' ] ?? 600000 ;
72- $ schedulingInterval = $ config ['schedulingInterval ' ] ?? 60000 ;
73- $ pullStrategyInterval = $ config ['dataStrategy ' ]['config ' ]['interval ' ] ?? 90000 ;
74- $ debug = var_export ( $ config ['debug ' ] ?? false , true ) ;
80+ $ loginCheckTimeout = $ config ['loginCheckTimeout ' ] ?? null ;
81+ $ refreshTokenTimeout = $ config ['refreshTokenTimeout ' ] ?? null ;
82+ $ releaseTimestampIntervalTimeout = $ config ['releaseTimestampIntervalTimeout ' ] ?? null ;
83+ $ schedulingInterval = $ config ['schedulingInterval ' ] ?? null ;
84+ $ pullStrategyInterval = $ config ['dataStrategy ' ]['config ' ]['interval ' ] ?? null ;
85+ $ debug = $ config ['debug ' ] ?? null ;
7586
7687 $ colorScheme = $ config ['colorScheme ' ] ?? null ;
77- $ colorSchemeValue = null !== $ colorScheme ? "' " .json_encode ($ colorScheme )."' " : '' ;
78-
79- $ env .= "###> Client configuration ### \n" ;
80- $ env .= 'CLIENT_LOGIN_CHECK_TIMEOUT= ' .$ loginCheckTimeout ."\n" ;
81- $ env .= 'CLIENT_REFRESH_TOKEN_TIMEOUT= ' .$ refreshTokenTimeout ."\n" ;
82- $ env .= 'CLIENT_RELEASE_TIMESTAMP_INTERVAL_TIMEOUT= ' .$ releaseTimestampIntervalTimeout ."\n" ;
83- $ env .= 'CLIENT_SCHEDULING_INTERVAL= ' .$ schedulingInterval ."\n" ;
84- $ env .= 'CLIENT_PULL_STRATEGY_INTERVAL= ' .$ pullStrategyInterval ."\n" ;
85- $ env .= 'CLIENT_COLOR_SCHEME= ' .$ colorSchemeValue ."\n" ;
86- $ env .= 'CLIENT_DEBUG= ' .$ debug ."\n" ;
87- $ env .= "###< Client configuration ### \n" ;
88-
89- $ output ->writeln ($ env );
88+ $ colorSchemeValue = null !== $ colorScheme ? "' " .json_encode ($ colorScheme )."' " : null ;
89+
90+ $ io ->writeln ('###> Client configuration ### ' );
91+ null !== $ loginCheckTimeout && $ io ->writeln ('CLIENT_LOGIN_CHECK_TIMEOUT= ' .$ loginCheckTimeout );
92+ null !== $ refreshTokenTimeout && $ io ->writeln ('CLIENT_REFRESH_TOKEN_TIMEOUT= ' .$ refreshTokenTimeout );
93+ null !== $ releaseTimestampIntervalTimeout && $ io ->writeln ('CLIENT_RELEASE_TIMESTAMP_INTERVAL_TIMEOUT= ' .$ releaseTimestampIntervalTimeout );
94+ null !== $ schedulingInterval && $ io ->writeln ('CLIENT_SCHEDULING_INTERVAL= ' .$ schedulingInterval );
95+ null !== $ pullStrategyInterval && $ io ->writeln ('CLIENT_PULL_STRATEGY_INTERVAL= ' .$ pullStrategyInterval );
96+ null !== $ colorSchemeValue && $ io ->writeln ('CLIENT_COLOR_SCHEME= ' .$ colorSchemeValue );
97+ null !== $ debug && $ io ->writeln ('CLIENT_DEBUG=true ' );
98+ $ io ->writeln ('###< Client configuration ### ' );
9099 }
91100
92101 return Command::SUCCESS ;
0 commit comments