This repository has been archived by the owner on Jan 17, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create basic symfony bundle configuration
- Loading branch information
Showing
4 changed files
with
133 additions
and
12 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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Bundle\SwooleBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class Configuration implements ConfigurationInterface | ||
{ | ||
private $builder; | ||
|
||
public function __construct(TreeBuilder $builder) | ||
{ | ||
$this->builder = $builder; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws \InvalidArgumentException | ||
* @throws \RuntimeException | ||
*/ | ||
public function getConfigTreeBuilder(): TreeBuilder | ||
{ | ||
$rootNode = $this->builder->root('swoole'); | ||
|
||
$rootNode | ||
->children() | ||
->arrayNode('server') | ||
->children() | ||
->scalarNode('host') | ||
->defaultValue('127.0.0.1') | ||
->end() | ||
->integerNode('port') | ||
->min(0) | ||
->max(65535) | ||
->defaultValue(9501) | ||
->end() | ||
->end() | ||
->end() // server | ||
->end() | ||
; | ||
|
||
return $this->builder; | ||
} | ||
|
||
public static function fromTreeBuilder(): self | ||
{ | ||
return new self(new TreeBuilder()); | ||
} | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Bundle\SwooleBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
class SwooleExtension extends Extension implements PrependExtensionInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function prepend(ContainerBuilder $container): void | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container): void | ||
{ | ||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | ||
$loader->load('services.yaml'); | ||
|
||
$configuration = Configuration::fromTreeBuilder(); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAlias(): string | ||
{ | ||
return 'swoole'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getConfiguration(array $config, ContainerBuilder $container): Configuration | ||
{ | ||
return Configuration::fromTreeBuilder(); | ||
} | ||
} |
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,14 @@ | ||
services: | ||
|
||
# default configuration for services in *this* file | ||
_defaults: | ||
# automatically injects dependencies in your services | ||
autowire: true | ||
# automatically registers your services as commands, event subscribers, etc. | ||
autoconfigure: true | ||
# this means you cannot fetch services directly from the container via $container->get() | ||
# if you need to do this, you can override this setting on individual services | ||
public: false | ||
|
||
App\Bundle\SwooleBundle\Server\Counter: | ||
factory: [App\Bundle\SwooleBundle\Server\Counter, fromZero] |
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