Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First thoughts on ApplicationFactory class
- Loading branch information
1 parent
c959b2a
commit 202e5bc
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |