33namespace Sentry \Laravel ;
44
55use Illuminate \Console \Command ;
6+ use Sentry \Dsn ;
67
78class PublishConfigCommand extends Command
89{
@@ -18,7 +19,7 @@ class PublishConfigCommand extends Command
1819 *
1920 * @var string
2021 */
21- protected $ signature = 'sentry:publish ' ;
22+ protected $ signature = 'sentry:publish {--dsn=} ' ;
2223
2324 /**
2425 * The console command description.
@@ -39,23 +40,53 @@ public function handle()
3940 '--provider ' => 'Sentry\Laravel\ServiceProvider '
4041 ]);
4142
43+ $ args = [];
44+
45+ $ dsn = $ this ->option ('dsn ' );
46+
47+ if (!$ this ->isKeySet ('SENTRY_LARAVEL_DSN ' )) {
48+ while (empty ($ dsn )) {
49+ $ this ->info ('' );
50+ $ this ->question ('[Sentry] Please paste the DSN here ' );
51+ $ dsn = $ this ->ask ('DSN ' );
52+ // In case someone copies it with SENTRY_LARAVEL_DSN=
53+ $ dsn = str_replace ('SENTRY_LARAVEL_DSN= ' , '' , $ dsn );
54+ try {
55+ $ dsnObj = Dsn::createFromString ($ dsn );
56+ } catch (\Exception $ e ) {
57+ // Not a valid DSN do it again
58+ $ this ->error ('[Sentry] The DSN is not valid, please make sure to paste a valid DSN ' );
59+ $ dsn = '' ;
60+ continue ;
61+ }
62+ };
63+
64+ $ this ->setEnvironmentValue (['SENTRY_LARAVEL_DSN ' => $ dsn ]);
65+ $ args = array_merge ($ args , ['--dsn ' => $ dsn ]);
66+ }
67+
4268 if ($ this ->confirm ('Enable Performance Monitoring? ' , true )) {
4369 $ this ->setEnvironmentValue (['SENTRY_TRACES_SAMPLE_RATE ' => 1.0 ]);
4470
4571 $ this ->info ('[Sentry] Added `SENTRY_TRACES_SAMPLE_RATE=1` to your .env file. ' );
4672
4773 $ testCommandPrompt = 'Want to send a test Event & Transaction? ' ;
48- $ args = ['--transaction ' => true ];
74+ $ args = array_merge ( $ args , ['--transaction ' => true ]) ;
4975 } else {
5076 $ testCommandPrompt = 'Want to send a test Event? ' ;
51- $ args = [];
5277 }
5378
5479 if ($ this ->confirm ($ testCommandPrompt , true )) {
5580 $ this ->call ('sentry:test ' , $ args );
5681 }
5782 }
5883
84+ public function isKeySet (string $ key )
85+ {
86+ $ envFile = app ()->environmentFilePath ();
87+ return strpos (file_get_contents ($ envFile ), $ key ) !== false ;
88+ }
89+
5990 public function setEnvironmentValue (array $ values )
6091 {
6192 $ envFile = app ()->environmentFilePath ();
0 commit comments