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

/*
 * This file is part of tsparse.
 * https://github.com/martin-helmich/ts-parse
 *
 * (C) 2014 Martin Helmich <kontakt@martin-helmich.de>
 *
 * For license information, view the LICENSE.md file.
 */

use Helmich\TypoScriptLint\Application;
use Helmich\TypoScriptParser\TypoScriptParserExtension;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\EventDispatcher\EventDispatcher;

if (file_exists(__DIR__ . '/vendor/autoload.php')) {
    require_once __DIR__ . '/vendor/autoload.php';
} else if (file_exists(__DIR__ . '/../../autoload.php')) {
    /** @noinspection PhpIncludeInspection */
    require_once __DIR__ . '/../../autoload.php';
} else {
    die('Could not find an autoload.php. Did you set up all dependencies?');
}

$dispatcher = new EventDispatcher();

$container = new ContainerBuilder();
$container->setParameter('dir.cwd', getcwd());
$container->setParameter('dir.tslint_root', __DIR__);
$container->setParameter('dir.typoscriptlint_root', __DIR__);
$container->registerExtension(new TypoScriptParserExtension());

$loader = new YamlFileLoader($container, new FileLocator(__DIR__));
$loader->load('services.yml');

$container->set('dispatcher', $dispatcher);
$container->loadFromExtension('typoscript_parser');
$container->compile();

$application = new Application($container);
$application->setDispatcher($dispatcher);
$application->run();
