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

if (strpos(__DIR__, 'vendor') === false) {
    require __DIR__ . '/../vendor/autoload.php';
} else {
    // assume vendor to be on include_path if installed
    require 'vendor/autoload.php';
}

use Graviton\ImportExport\Command\ImportCommand;
use Graviton\ImportExport\Command\CoreExportCommand;
use Graviton\ImportExport\Command\CoreImportCommand;
use Graviton\ImportExport\Command\CorePurgeCommand;
use Graviton\ImportExport\Command\ValidationCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper as Dumper;
use Graviton\ImportExport\Service\HttpClient;
use Webuni\FrontMatter\FrontMatter;
use Symfony\Component\Filesystem\Filesystem;
use Graviton\ImportExport\Util\JsonSerializer;

$application = new Application();
$application->setCatchExceptions(false);
$application->add(
    new ImportCommand(
        new HttpClient(),
        new Finder(),
        new FrontMatter(),
        new Parser(),
        new VarCloner(),
        new Dumper()
    )
);

if (class_exists('\MongoClient')) {
    $application->add(
        new CoreImportCommand(
            new FrontMatter(),
            new JsonSerializer(),
            new Finder()
        )
    );
    $application->add(
        new CoreExportCommand(
            new Filesystem(),
            new JsonSerializer(),
            new FrontMatter()
        )
    );
    $application->add(
        new CorePurgeCommand()
    );
    $application->add(
        new ValidationCommand(
            new FrontMatter(),
            new Parser()
        )
    );
}
$application->run();
