@@ -485,39 +485,26 @@ protected function decode($variable)
485485 */
486486 public function __get ($ property )
487487 {
488- $ isBuildVar = in_array ($ property , array_keys ($ this ->directVariables ));
489- $ isRuntimeVar = in_array ($ property , array_keys ($ this ->directVariablesRuntime ));
490488 // For now, all unprefixed variables are also runtime variables. If that ever changes this
491489 // logic will change with it.
490+ $ isBuildVar = in_array ($ property , array_keys ($ this ->directVariables ));
491+ $ isRuntimeVar = in_array ($ property , array_keys ($ this ->directVariablesRuntime ));
492492 $ isUnprefixedVar = in_array ($ property , array_keys ($ this ->unPrefixedVariablesRuntime ));
493493
494- if ($ this -> inBuild () && $ isRuntimeVar ) {
495- throw new BuildTimeVariableAccessException (sprintf ('The %s variable is not available during build time. ' , $ property ));
494+ if (!( $ isBuildVar || $ isUnprefixedVar || $ isRuntimeVar) ) {
495+ throw new \ InvalidArgumentException (sprintf ('No such variable defined: %s ' , $ property ));
496496 }
497497
498- if ($ isBuildVar ) {
499- $ value = $ this ->getValue ($ this ->directVariables [$ property ]);
500- if (is_null ($ value )) {
501- throw new NotValidPlatformException (sprintf ('The %s variable is not defined. Are you sure you \'re running on Platform.sh? ' , $ property ));
502- }
503- return $ value ;
504- }
505- if ($ isUnprefixedVar ) {
506- $ value = $ this ->environmentVariables [$ this ->unPrefixedVariablesRuntime [$ property ]] ?? null ;
507- if (is_null ($ value )) {
508- throw new NotValidPlatformException (sprintf ('The %s variable is not defined. Are you sure you \'re running on Platform.sh? ' , $ property ));
509- }
510- return $ value ;
511- }
512- if ($ isRuntimeVar ) {
513- $ value = $ this ->getValue ($ this ->directVariablesRuntime [$ property ]);
514- if (is_null ($ value )) {
515- throw new NotValidPlatformException (sprintf ('The %s variable is not defined. Are you sure you \'re running on Platform.sh? ' , $ property ));
498+ $ value = $ this ->getPropertyValue ($ property );
499+
500+ if (is_null ($ value )) {
501+ if ($ this ->inBuild () && !$ isBuildVar ) {
502+ throw new BuildTimeVariableAccessException (sprintf ('The %s variable is not available during build time. ' , $ property ));
516503 }
517- return $ value ;
504+ throw new NotValidPlatformException ( sprintf ( ' The %s variable is not defined. Are you sure you \' re running on Platform.sh? ' , $ property )) ;
518505 }
519506
520- throw new \ InvalidArgumentException ( sprintf ( ' No such variable defined: %s ' , $ property )) ;
507+ return $ value ;
521508 }
522509
523510 /**
@@ -531,21 +518,40 @@ public function __get($property)
531518 */
532519 public function __isset ($ property )
533520 {
534- $ isBuildVar = in_array ($ property , array_keys ($ this ->directVariables ));
535- $ isRuntimeVar = in_array ($ property , array_keys ($ this ->directVariablesRuntime ));
521+ $ value = $ this ->getPropertyValue ($ property );
522+
523+ return !is_null ($ value );
524+ }
525+
526+ /**
527+ * Returns the value of a dynamic property, whatever it's configuration.
528+ *
529+ * @param string $property
530+ * The property value to get.
531+ * @return string|null
532+ */
533+ protected function getPropertyValue (string $ property ) : ?string
534+ {
536535 // For now, all unprefixed variables are also runtime variables. If that ever changes this
537536 // logic will change with it.
537+ $ isBuildVar = in_array ($ property , array_keys ($ this ->directVariables ));
538+ $ isRuntimeVar = in_array ($ property , array_keys ($ this ->directVariablesRuntime ));
538539 $ isUnprefixedVar = in_array ($ property , array_keys ($ this ->unPrefixedVariablesRuntime ));
539540
540- if ($ this -> inBuild () ) {
541- return $ isBuildVar && ! is_null ($ this ->$ property );
541+ if ($ isBuildVar ) {
542+ $ value = $ this -> getValue ($ this ->directVariables [ $ property] );
542543 }
543-
544- if ($ isBuildVar || $ isRuntimeVar || $ isUnprefixedVar ) {
545- return !is_null ($ this ->$ property );
544+ else if ($ isUnprefixedVar ) {
545+ $ value = $ this ->environmentVariables [$ this ->unPrefixedVariablesRuntime [$ property ]] ?? null ;
546+ }
547+ else if ($ isRuntimeVar ) {
548+ $ value = $ this ->getValue ($ this ->directVariablesRuntime [$ property ]);
549+ }
550+ else {
551+ $ value = null ;
546552 }
547553
548- return false ;
554+ return $ value ;
549555 }
550556
551557 /**
0 commit comments