diff --git a/php/blocks/main/sites.php b/php/blocks/main/sites.php index 5cb8a82..34a0b8f 100644 --- a/php/blocks/main/sites.php +++ b/php/blocks/main/sites.php @@ -120,31 +120,53 @@ function display_site( $name, array $site ) : void { } function display_sites() : void { - $yaml = new Alchemy\Component\Yaml\Yaml(); - - $config_file = '/vagrant/config.yml'; - if ( file_exists( '/vagrant/config.yml' ) ) { - $config_file = '/vagrant/config.yml'; - } elseif ( file_exists( '/vagrant/vvv-custom.yml' ) ) { - $config_file = '/vagrant/vvv-custom.yml'; + + $config_locations = [ + '/srv/vvv/config.yml', + '/vagrant/config.yml', + '/vagrant/vvv-custom.yml', + ]; + + $config_file = false; + foreach ( $config_locations as $location ) { + if ( is_readable( $location ) ) { + $config_file = $location; + break; + } } + if ( false === $config_file ) { + echo '

No config file was found.

'; + return; + } + + $yaml = new Alchemy\Component\Yaml\Yaml(); $data = $yaml->load( $config_file ); + $provisioned_sites = []; $skipped_sites = []; - foreach ( $data['sites'] as $name => $site ) { - if ( - isset( $site['skip_provisioning'] ) - && ( $site['skip_provisioning'] == true ) - ) { - $skipped_sites[ $name ] = $site; - } else { - $provisioned_sites[ $name ] = $site; + + if ( ! empty( $data['sites'] ) && is_array( $data['sites'] ) ) { + foreach ( $data['sites'] as $name => $site ) { + if ( + isset( $site['skip_provisioning'] ) + && ( $site['skip_provisioning'] == true ) + ) { + $skipped_sites[ $name ] = $site; + } else { + $provisioned_sites[ $name ] = $site; + } } + } else { + echo '

No sites were found.

'; } - foreach ( $provisioned_sites as $name => $site ) { - display_site( $name, $site ); + if ( ! empty( $provisioned_sites ) ) { + foreach ( $provisioned_sites as $name => $site ) { + display_site( $name, $site ); + } + } else { + echo '

There are no provisioned sites.

'; } if ( ! empty( $skipped_sites ) ) {