Skip to content

Commit

Permalink
First thoughts on ApplicationFactory class
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewCarterUK committed Aug 14, 2015
1 parent c959b2a commit 202e5bc
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/ApplicationFactory.php
@@ -0,0 +1,51 @@
<?php

namespace PHPFastCGI\FastCGIDaemon;

use PHPFastCGI\FastCGIDaemon\Command\DaemonRunCommand;
use Symfony\Component\Console\Application;
/**
* The default implementation of the ApplicationFactoryInterface.
*/
class ApplicationFactory implements ApplicationFactoryInterface
{
/**
* @var DaemonFactoryInterface
*/
protected $daemonFactory;

/**
* Constructor.
*
* @param DaemonFactoryInterface $daemonFactory The factory to use to create daemons
*/
public function __construct(DaemonFactoryInterface $daemonFactory = null)
{
if (null === $daemonFactory) {
$this->daemonFactory = new DaemonFactory;
} else {
$this->daemonFactory = $daemonFactory;
}
}

/**
* {@inheritdoc}
*/
public function createApplication($kernel, $commandName = 'run', $commandDescription = 'Run a FastCGI daemon')
{
$command = $this->createCommand($kernel, $commandName, $commandDescription);

$application = new Application;
$application->add($command);

return $application;
}

/**
* {@inheritdoc}
*/
public function createCommand($kernel, $commandName = 'run', $commandDescription = 'Run a FastCGI daemon')
{
return new DaemonRunCommand($commandName, $commandDescription, $this->daemonFactory, $kernel);
}
}
31 changes: 31 additions & 0 deletions src/ApplicationFactoryInterface.php
@@ -0,0 +1,31 @@
<?php

namespace PHPFastCGI\FastCGIDaemon;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;

/**
* Objects that implement the ApplicationFactoryInterface can be used to create
* Symfony console commands and applications.
*/
interface ApplicationFactoryInterface
{
/**
* Create a Symfony console application
*
* @param KernelInterface|callable $kernel The daemon's kernel
*
* @return Application The Symfony console application
*/
public function createApplication($kernel);

/**
* Create a Symfony console command
*
* @param KernelInterface|callable $kernel The daemon's kernel
*
* @return Command The Symfony console command
*/
public function createCommand($kernel);
}

0 comments on commit 202e5bc

Please sign in to comment.