Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve config loading #40

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions php/blocks/main/sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<p>No config file was found.</p>';
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 '<p>No sites were found.</p>';
}

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 '<p>There are no provisioned sites.</p>';
}

if ( ! empty( $skipped_sites ) ) {
Expand Down