4141
4242use DCarbone \PHPFHIR \Builder ;
4343use DCarbone \PHPFHIR \Config ;
44- use JetBrains \PhpStorm \NoReturn ;
45- use Monolog \Formatter \LineFormatter ;
46- use Monolog \Handler \StreamHandler ;
47- use Monolog \Logger ;
48- use Monolog \Processor \PsrLogMessageProcessor ;
4944use Psr \Log \LogLevel ;
5045use Psr \Log \NullLogger ;
5146
5752const FLAG_FORCE_DELETE = '--forceDelete ' ;
5853const FLAG_USE_EXISTING = '--useExisting ' ;
5954const FLAG_CONFIG = '--config ' ;
55+ const FLAG_ONLY_CORE = '--onlyCore ' ;
6056const FLAG_ONLY_LIBRARY = '--onlyLibrary ' ;
6157const FLAG_ONLY_TESTS = '--onlyTests ' ;
6258const FLAG_VERSIONS = '--versions ' ;
7167$ config_location_env = getenv (ENV_GENERATE_CONFIG_FILE );
7268$ config_location_arg = '' ;
7369$ config_file = null ;
70+ $ only_core = false ;
7471$ only_library = false ;
7572$ only_tests = false ;
7673$ versions_to_generate = null ;
7774$ use_existing = false ;
7875$ log_level = LogLevel::WARNING ;
79- $ user_agent = 'Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0 ' ;
76+ $ user_agent_def = 'Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0 ' ;
77+ $ user_agent = $ user_agent_def ;
8078
8179// ----- functions
8280
8381/**
84- * @param bool $return
8582 * @return string
8683 */
87- function missing_config_text (bool $ return ): string
84+ function missing_config_text (): string
8885{
8986 global $ config_location_env , $ config_location_arg , $ config_location_def ;
9087 $ out = 'Unable to locate generate script configuration file. I looked in the following locations: ' . PHP_EOL ;
@@ -116,22 +113,17 @@ function missing_config_text(bool $return): string
116113
117114STRING ;
118115
119- if ($ return ) {
120- return $ out ;
121- }
122-
123- echo $ out ;
124- exit (1 );
116+ return $ out ;
125117}
126118
127119/**
128- * @param bool $err
120+ * @return string
129121 */
130- #[NoReturn] function exit_with_help ( bool $ err = false ): void
122+ function help_text ( ): string
131123{
132- global $ config_location_def ;
124+ global $ config_location_def, $ user_agent_def ;
133125
134- $ env_var = ENV_GENERATE_CONFIG_FILE ;
126+ $ config_env_var = ENV_GENERATE_CONFIG_FILE ;
135127 $ out = <<<STRING
136128
137129PHP-FHIR: Tools for creating PHP classes from the HL7 FHIR Specification
@@ -144,39 +136,39 @@ function missing_config_text(bool $return): string
144136 FHIR: https://hl7.org/fhir
145137
146138- Flags:
147- --help: Print this help text
139+ --help Print this help text
148140 ex: ./bin/generate.sh --help
149- --forceDelete: Forcibly delete all pre-existing FHIR schema files and output files without being prompted
141+ --forceDelete Forcibly delete all pre-existing FHIR schema files and output files without being prompted
150142 ex: ./bin/generate.sh --forceDelete
151- --useExisting: Do no prompt for any cleanup tasks. Mutually exclusive with --forceDelete
143+ --useExisting Do no prompt for any cleanup tasks. Mutually exclusive with --forceDelete
152144 ex: ./bin/generate.sh --useExisting
145+ --onlyCore Only gnerate Core classes. Mutually exclusive with --onlyLibrary and --onlyTests
146+ ex: ./bin/generate.sh --onlyCore
153147 --onlyLibrary Only generate Library classes. Mutually exclusive with --onlyTests
154148 ex: ./bin/generate.sh --onlyLibrary
155149 --onlyTests Only generate Test classes. Mutually exclusive with --onlyLibrary
156150 ex: ./bin/generate.sh --onlyTests
157- --config: Specify location of config [default: {$ config_location_def }]
151+ --config Specify location of config
152+ default: {$ config_location_def }
158153 ex: ./bin/generate.sh --config path/to/file
159- --versions: Comma-separated list of specific versions to parse from config
154+ --versions Comma-separated list of specific versions to parse from config
160155 ex: ./bin/generate.sh --versions STU3,R4
161- --userAgent: User-Agent string to use when downloading FHIR schema files
162- ex: ./bin/generate.sh --userAgent "Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0"
163- --logLevel: Level of verbosity during generation
156+ --userAgent User-Agent string to use when downloading FHIR schema files
157+ default: " {$ user_agent_def }"
158+ ex: ./bin/generate.sh --userAgent "your custom user agent string"
159+ --logLevel Level of verbosity during generation
164160 ex: ./bin/generate.sh --logLevel warning
165161
166162- Configuration:
167163 There are 3 possible ways to define a configuration file for this script to use:
168- 1. Define env var {$ env_var }
164+ 1. Define env var {$ config_env_var }
169165 2. Pass "--config" flag at run time
170166 3. Place "config.php" in dir {$ config_location_def }
171167
172168
173169STRING ;
174170
175- echo $ out ;
176- if ($ err ) {
177- exit (1 );
178- }
179- exit (0 );
171+ return $ out ;
180172}
181173
182174/**
@@ -250,6 +242,10 @@ function is_dir_empty(string $dir): bool
250242 $ found_equal = true ;
251243 }
252244 switch ($ arg ) {
245+ case '? ' ;
246+ case '-h ' :
247+ case '-help ' :
248+ case 'help ' :
253249 case FLAG_HELP :
254250 $ print_help = true ;
255251 break ;
@@ -300,7 +296,8 @@ function is_dir_empty(string $dir): bool
300296
301297 default :
302298 echo "Unknown argument \"{$ arg }\" passed at position {$ i }\n" ;
303- exit_with_help (true );
299+ echo help_text ();
300+ exit (1 );
304301 }
305302 }
306303}
@@ -311,7 +308,8 @@ function is_dir_empty(string $dir): bool
311308 FLAG_FORCE_DELETE ,
312309 FLAG_USE_EXISTING
313310 );
314- exit_with_help (true );
311+ echo help_text ();
312+ exit (1 );
315313}
316314
317315if ($ only_library && $ only_tests ) {
@@ -320,7 +318,8 @@ function is_dir_empty(string $dir): bool
320318 FLAG_ONLY_LIBRARY ,
321319 FLAG_ONLY_TESTS
322320 );
323- exit_with_help (true );
321+ echo help_text ();
322+ exit (1 );
324323}
325324
326325// try to determine which config file to use...
@@ -333,11 +332,13 @@ function is_dir_empty(string $dir): bool
333332}
334333
335334if ($ print_help ) {
336- exit_with_help (); // calls exit(0); at end
335+ echo help_text ();
336+ exit (0 );
337337}
338338
339339if (!file_exists ($ config_file )) {
340- missing_config_text (false );
340+ echo missing_config_text ();
341+ exit (1 );
341342}
342343
343344if (!is_readable ($ config_file )) {
@@ -350,11 +351,11 @@ function is_dir_empty(string $dir): bool
350351
351352// determine if monolog is present, otherwise use null logger
352353if (class_exists ('\\Monolog \\Logger ' )) {
353- $ formatter = new LineFormatter (LineFormatter::SIMPLE_FORMAT );
354- $ handler = new StreamHandler ('php://stdout ' , $ log_level );
354+ $ formatter = new \ Monolog \ Formatter \ LineFormatter (\ Monolog \ Formatter \ LineFormatter::SIMPLE_FORMAT );
355+ $ handler = new \ Monolog \ Handler \ StreamHandler ('php://stdout ' , $ log_level );
355356 $ handler ->setFormatter ($ formatter );
356- $ processor = new PsrLogMessageProcessor (\DateTimeInterface::W3C );
357- $ logger = new Logger (
357+ $ processor = new \ Monolog \ Processor \ PsrLogMessageProcessor (\DateTimeInterface::W3C );
358+ $ logger = new \ Monolog \ Logger (
358359 'php-fhir ' ,
359360 [$ handler ],
360361 [$ processor ]
0 commit comments