PHPSpec2\Console\Command\DescribeCommand::execute PHP Method

execute() protected method

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->setFormatter(new Console\Formatter($output->isDecorated()));
        $this->io = new Console\IO($input, $output, $this->getHelperSet());
        $spec = $input->getArgument('spec');
        if (!is_dir($specsPath = $input->getOption('spec-path'))) {
            mkdir($specsPath, 0777, true);
        }
        if ($srcPath = $input->getOption('src-path')) {
            $spec = preg_replace('#^' . preg_quote($srcPath, '#') . '/#', '', $spec);
        }
        $spec = preg_replace('#\\.php$#', '', $spec);
        $spec = str_replace('/', '\\', $spec);
        $specsPath = realpath($specsPath) . DIRECTORY_SEPARATOR;
        $subject = str_replace('/', '\\', $spec);
        $classname = $input->getOption('namespace') . $subject;
        $filepath = $specsPath . str_replace('\\', DIRECTORY_SEPARATOR, $spec) . '.php';
        $namespace = str_replace('/', '\\', dirname(str_replace('\\', DIRECTORY_SEPARATOR, $classname)));
        $class = basename(str_replace('\\', DIRECTORY_SEPARATOR, $classname));
        if (file_exists($filepath)) {
            $overwrite = $this->io->askConfirmation(sprintf('File "%s" already exists. Overwrite?', basename($filepath)), false);
            if (!$overwrite) {
                return 1;
            }
            $this->io->writeln();
        }
        $dirpath = dirname($filepath);
        if (!is_dir($dirpath)) {
            mkdir($dirpath, 0777, true);
        }
        file_put_contents($filepath, $this->getSpecContentFor(array('%classname%' => $classname, '%namespace%' => $namespace, '%filepath%' => $filepath, '%class%' => $class, '%subject%' => $subject)));
        $output->writeln(sprintf("<info>Specification for <value>%s</value> created in <value>%s</value>.</info>\n", $subject, $this->relativizePath($filepath)));
    }