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

$memoryLimit = getenv('DAEMONIZE_MEMORY_LIMIT');
if (!empty($memoryLimit)) {
    ini_set('memory_limit', $memoryLimit);
} else {
    ini_set('memory_limit', '-1');
}

$autoload = realpath(__DIR__."/../vendor/autoload.php");
if (!file_exists($autoload)) {
    $autoload = realpath(__DIR__."/../../../autoload.php");
    if (!file_exists($autoload)) {
        throw new Exception('Autoload not found. Did you run `composer dump-autload`?');
    }
}
require_once($autoload);

use ByJG\Daemon\Console\CallCommand;
use ByJG\Daemon\Console\InstallCommand;
use ByJG\Daemon\Console\RunCommand;
use ByJG\Daemon\Console\ServicesCommand;
use ByJG\Daemon\Console\UninstallCommand;
use Symfony\Component\Console\Application;

$application = new Application('PHP Daemonize by JG', '4.9.1');
$application->add(new InstallCommand());
$application->add(new UninstallCommand());
$application->add(new RunCommand());
$application->add(new CallCommand());
$application->add(new ServicesCommand());
$application->run();