#!/usr/bin/env php
<?php
/**
 * This file is part of the php-resque package.
 *
 * (c) Michael Haynes <mike@mjphaynes.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * The main point of entry for the php-resque commands
 */
if (!ini_get('date.timezone') or ! date_default_timezone_get()) {
    date_default_timezone_set('UTC');
}

define('RESQUE_BIN_DIR', realpath(__DIR__));
define('RESQUE_DIR', realpath(RESQUE_BIN_DIR . '/../'));

$files = array(
    RESQUE_DIR . '/vendor/autoload.php',
    RESQUE_DIR . '/../../autoload.php'
);

$loaded = false;

foreach ($files as $file) {
    if (file_exists($file)) {
        require_once $file;
        $loaded = true;
        break;
    }
}

if (!$loaded) {
    echo '<pre>You need to set up the project dependencies using the following commands:' . PHP_EOL .
    "\t" . '$ curl -s http://getcomposer.org/installer | php' . PHP_EOL .
    "\t" . '$ php composer.phar install</pre>' . PHP_EOL;
    exit(1);
}

$application = new Symfony\Component\Console\Application('php-resque', Resque::VERSION);

$application->add(new Resque\Commands\Clear);
$application->add(new Resque\Commands\Hosts);
$application->add(new Resque\Commands\Queues);
$application->add(new Resque\Commands\Cleanup);
$application->add(new Resque\Commands\Workers);

$application->add(new Resque\Commands\Job\Queue);

$application->add(new Resque\Commands\Socket\Send);
$application->add(new Resque\Commands\Socket\Receive);
$application->add(new Resque\Commands\Socket\Connect);

$application->add(new Resque\Commands\Worker\Start);
$application->add(new Resque\Commands\Worker\Stop);
$application->add(new Resque\Commands\Worker\Restart);
$application->add(new Resque\Commands\Worker\Pause);
$application->add(new Resque\Commands\Worker\Resume);
$application->add(new Resque\Commands\Worker\Cancel);

$application->add(new Resque\Commands\SpeedTest);

$application->run();
