<?php

function loadEarly($items) {
  foreach ($items as $path => $source) {
    if (!file_exists($path)) {
      if (!mkdir($path, 0777, TRUE) || !is_dir($path)) {
        throw new \RuntimeException(sprintf('Directory "%s" was not created', $path));
      }
      exec('git clone ' . $source . ' ' . $path);
    }
  }
}

if (file_exists('composer.json')) {
  $composer = json_decode(file_get_contents('composer.json'), TRUE);
  if (isset($composer['extra']['l3d'])) {
    foreach ($composer['extra']['l3d'] as $type => $args) {
      if ($type === 'load-early') {
        loadEarly($args);
      }
    }
  }
}