#!/usr/bin/env php
<?php

error_reporting(-1);
ini_set('display_errors', 1);


/**
 * This file is part of Bldr.io.
 *
 * (c) Aaron Scherer <aequasi@gmail.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

function glob_r($pattern, $flags = 0)
{
    $files = glob($pattern, $flags);

    foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
        $files = array_merge($files, glob_r($dir . '/' . basename($pattern), $flags));
    }
    return $files;
}

function glob_recursive($pattern, $flags = 0)
{
    if (strpos($pattern, '**') !== false) {
        return glob_r($pattern, $flags);
    }

    return glob($pattern, $flags);
}

if (__DIR__ !== getcwd()) {
    $paths[] = getcwd() . '/vendor';
}

$paths[] = __DIR__ . '/../vendor';
$paths[] = __DIR__ . '/../../..';

$autoloader = false;
$loaded = [];
foreach ($paths as $path) {
    $filePath = $path . '/autoload.php';
    if (file_exists($filePath)) {
        $fileHash = sha1_file($filePath);
        if(!in_array($fileHash, $loaded)) {
            $autoloader = true;
            require $filePath;
            $loaded[] = $fileHash;
        }
    }
}

if (false === $autoloader) {
    echo "Cannot find an autoload.php file, have you executed composer install command?\n";
    exit(1);
}

Bldr\Application::create();
