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

$json = json_decode(file_get_contents(__DIR__ . '/../Functionals/composer.json'), true);

$json['repositories'] = array(
    array(
        'type' => 'vcs',
        'url' => realpath(__DIR__ . '/../../')
    )
);

$prefix = 'dev-';
if (preg_match('/^(?:\d+\.?)+/', $argv[1]) > 0) {
    $prefix = '';
}

$json['require']['hoathis/symfony-console-bundle'] = $prefix . (isset($argv[1]) ? $argv[1] : 'master');

$kernel = file(__DIR__ . '/../Functionals/app/AppKernel.php');

array_splice($kernel, 18, 0, 'new \Hoathis\Bundle\ConsoleBundle\HoathisConsoleBundle(),' . PHP_EOL);

file_put_contents(__DIR__ . '/../Functionals/composer.json', json_encode($json, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0));
file_put_contents(__DIR__ . '/../Functionals/app/AppKernel.php', implode('', $kernel));
