Skip to content

Commit e6fcb46

Browse files
author
=
committed
Initial commit
0 parents  commit e6fcb46

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed

AndrewCarterUKSpeedfonyBundle.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace PHPFastCGI\SpeedfonyBundle;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
7+
class AndrewCarterUKSpeedfonyBundle extends Bundle
8+
{
9+
}

Command/DaemonRunCommand.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace PHPFastCGI\SpeedfonyBundle\Command;
4+
5+
use PHPFastCGI\FastCGIDaemon\SocketDaemon;
6+
use PHPFastCGI\FastCGIDaemon\StreamSocketDaemon;
7+
use Symfony\Component\Console\Command\Command;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
use Symfony\Component\HttpFoundation\Request;
12+
use Symfony\Component\HttpKernel\Kernel;
13+
14+
class DaemonRunCommand extends Command
15+
{
16+
private $kernel;
17+
18+
public function __construct(Kernel $kernel)
19+
{
20+
$this->kernel = $kernel;
21+
22+
parent::__construct();
23+
}
24+
25+
protected function configure()
26+
{
27+
$this
28+
->setName('speedfony:daemon:run')
29+
->setDescription('Execute the FCGI daemon')
30+
->addArgument('socket', InputArgument::OPTIONAL, 'The socket stream to listen on')
31+
->addArgument('port', InputArgument::OPTIONAL, 'Port to listen on')
32+
->addArgument('cycles', InputArgument::OPTIONAL, 'Request cycles to live for, 0 means infinite', 0);
33+
}
34+
35+
protected function execute(InputInterface $input, OutputInterface $output)
36+
{
37+
$getIntegerArgument = function ($argument, $minimumValue) use ($input) {
38+
$value = (string) $input->getArgument($argument);
39+
$intValue = (int) $value;
40+
41+
if ((string) $intValue !== $value) {
42+
throw new \Exception('The ' . $argument . ' argument must be an integer');
43+
} elseif ($value < $minimumValue) {
44+
throw new \Exception('The ' . $argument . ' argument must be at least ' . $minimumValue);
45+
}
46+
47+
return $value;
48+
};
49+
50+
if ($input->hasArgument('socket')) {
51+
$daemon = new StreamSocketDaemon($input->getArgument('socket'));
52+
} elseif ($input->hasArgument('port')) {
53+
$daemon = new SocketDaemon($getIntegerArgument('port', 0));
54+
} else {
55+
throw new \Exception('You must specify either the socket or port argument');
56+
}
57+
58+
$maximumCycles = $getIntegerArgument('cycles', 0);
59+
60+
for($cycles = 0; ($maximumCycles == 0) || $cycles < $maximumCycles; $cycles++) {
61+
$request = $daemon->getRequest();
62+
63+
$httpRequest = new Request(array(), array(), array(), array(),
64+
array(), $request->getServer(), $request->getContent());
65+
66+
$response = str_replace(
67+
array('HTTP/1.1 ', 'HTTP/1.0 '),
68+
array('Status: ', 'Status: '),
69+
(string) $this->kernel->handle($httpRequest)
70+
);
71+
72+
$request->respond($response);
73+
}
74+
}
75+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace PHPFastCGI\SpeedfonyBundle\DependencyInjection;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\Config\FileLocator;
7+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
8+
use Symfony\Component\DependencyInjection\Loader;
9+
10+
/**
11+
* This is the class that loads and manages your bundle configuration
12+
*
13+
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
14+
*/
15+
class AndrewCarterUKSpeedfonyExtension extends Extension
16+
{
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public function load(array $configs, ContainerBuilder $container)
21+
{
22+
$configuration = new Configuration();
23+
$config = $this->processConfiguration($configuration, $configs);
24+
25+
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26+
$loader->load('services.yml');
27+
}
28+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace PHPFastCGI\SpeedfonyBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6+
use Symfony\Component\Config\Definition\ConfigurationInterface;
7+
8+
/**
9+
* This is the class that validates and merges configuration from your app/config files
10+
*
11+
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
12+
*/
13+
class Configuration implements ConfigurationInterface
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
public function getConfigTreeBuilder()
19+
{
20+
$treeBuilder = new TreeBuilder();
21+
$rootNode = $treeBuilder->root('andrew_carter_uk_speedfony');
22+
23+
// Here you should define the parameters that are allowed to
24+
// configure your bundle. See the documentation linked above for
25+
// more information on that topic.
26+
27+
return $treeBuilder;
28+
}
29+
}

Resources/config/services.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
andrew_carter_uk_speedfony.daemon_run_command:
3+
class: PHPFastCGI\SpeedfonyBundle\Command\DaemonRunCommand
4+
arguments: [@kernel]
5+
tags:
6+
- { name: console.command }

0 commit comments

Comments
 (0)