Skip to content
This repository has been archived by the owner on Jan 27, 2020. It is now read-only.

Create Serve Command #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/Commands/ServeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Katana\Commands;

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

class ServeCommand extends Command
{
/**
* Configure the command.
*
* @return void
*/
protected function configure()
{
$this->setName('serve')
->setDescription('Serve local site with php built-in server.')
->addOption(
'port',
'p',
InputOption::VALUE_REQUIRED,
'What port should we use?',
8000
);
}

/**
* Execute the command.
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$port = $input->getOption('port');

$output->writeln("<info>Started listening on http://localhost:{$port}</info>");
passthru("php -S localhost:{$port} -t public");
}
}