<?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);
    }
  }
}

print("a1");
if (file_exists('composer.json')) {
  print("a2");
  $composer = json_decode(file_get_contents('composer.json'), TRUE);
  print("a2n");
  if (isset($composer['extra']['l3d'])) {
    print("a3");
    foreach ($composer['extra']['l3d'] as $type => $args) {
      print("a4: " . $type);
      if ($type === 'load-early') {
        loadEarly($args);
      }
    }
  }
}