HookListCommand.php 1.43 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
<?php

/*
 * This file is part of StaticReview
 *
 * Copyright (c) 2014 Samuel Parkinson <@samparkinson_>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @see http://github.com/sjparkinson/static-review/blob/master/LICENSE.md
 */

namespace StaticReview\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class HookListCommand extends Command
{
    protected function configure()
    {
        $this->setName('hook:list');

        $this->setDescription('Lists all the included hooks.');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $hooksPath = realpath(__DIR__ . '/../../hooks/');

        $output->writeln("<info>Avaliable hooks:</info>");

        if ($handle = opendir($hooksPath)) {
            while (false !== ($entry = readdir($handle))) {
                if (pathinfo($entry, PATHINFO_EXTENSION) === 'php') {
                    if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
                        $output->writeln($hooksPath . DIRECTORY_SEPARATOR . $entry);
                    } else {
                        $output->writeln(pathinfo($entry, PATHINFO_FILENAME));
                    }
                }
            }

            closedir($handle);
        }
    }
}