Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit a413ba6

Browse files
author
Andrey Helldar
committed
Prepared to override the configuration of the Symfony console command
1 parent 0c69f05 commit a413ba6

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,28 @@ Now you can change the file `config/env-sync.php`.
7676

7777
### Symfony Framework
7878

79-
> Coming soon...
79+
Just execute the `php bin/console env:sync` command.
80+
81+
You can also specify the invocation when executing the `composer update` command in `composer.json` file:
82+
83+
```json
84+
{
85+
"scripts": {
86+
"post-update-cmd": [
87+
"php bin/console env:sync"
88+
]
89+
}
90+
}
91+
```
92+
93+
Now, every time you run the `composer update` command, the environment settings file will be synchronized.
94+
95+
If you want to change the default configuration, configure the `env-sync` keys in your `config.yml`:
96+
97+
```
98+
env-sync:
99+
forces: []
100+
```
80101

81102
### Native using
82103

src/Frameworks/Symfony/Console/Sync.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public function __construct(Config $config, Syncer $syncer)
2929

3030
$this->config = $config;
3131
$this->syncer = $syncer;
32+
33+
$this->setSyncerConfig();
3234
}
3335

3436
protected function configure()
@@ -39,11 +41,6 @@ protected function configure()
3941
->addOption('path', null, InputArgument::OPTIONAL, 'Gets the path to scan for files');
4042
}
4143

42-
protected function syncerConfig(): array
43-
{
44-
return [];
45-
}
46-
4744
protected function execute(InputInterface $input, OutputInterface $output): int
4845
{
4946
$this->input = $input;
@@ -101,4 +98,16 @@ protected function line(string $string, string $style = null)
10198

10299
$this->output->writeln($styled);
103100
}
101+
102+
protected function syncerConfig(): ?array
103+
{
104+
return null;
105+
}
106+
107+
protected function setSyncerConfig(): void
108+
{
109+
if ($config = $this->syncerConfig()) {
110+
$this->syncer->setConfig($config);
111+
}
112+
}
104113
}

src/Services/Compiler.php

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public function get(): string
4141
return $this->compile();
4242
}
4343

44+
public function setConfig(array $config): self
45+
{
46+
$this->config = $config;
47+
48+
return $this;
49+
}
50+
4451
protected function map(): void
4552
{
4653
foreach ($this->items as $key => &$value) {

src/Services/Syncer.php

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ public function store(): void
5757
File::store($this->storePath(), $this->content());
5858
}
5959

60+
public function setConfig(array $config): self
61+
{
62+
$this->compiler->setConfig($config);
63+
64+
return $this;
65+
}
66+
6067
protected function files(): array
6168
{
6269
return $this->finder->get($this->path);

0 commit comments

Comments
 (0)