Skip to content

Commit a5ef59a

Browse files
Nyholmsagikazarmark
authored andcommitted
Refactor the HttplugExtension (#97)
* Refactor the HttplugExtension * minor refactor * style fix * typo * Minor fixes * Merge Profiling back to main extension Separating profiling into a separate class does not make the code cleaner or more readable. In this commit: - Profiling moved back to main extension - Toolbar (profiling) defaults to kernel.debug * added note about plugin client
1 parent 119f887 commit a5ef59a

File tree

8 files changed

+208
-133
lines changed

8 files changed

+208
-133
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Change Log
22

33

4+
## UNRELEASED
5+
6+
### Changed
7+
8+
- All clients are registered with the PluginClient. (even in production)
9+
10+
### Deprecated
11+
12+
- `auto` value in `toolbar.enabled` config
13+
414
## 1.2.2 - 2016-07-19
515

616
### Fixed

ClientFactory/PluginClientFactory.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@
1313
final class PluginClientFactory
1414
{
1515
/**
16-
* @param Plugin[] $plugins
17-
* @param ClientFactory $factory
18-
* @param array $config config to the client factory
19-
* @param array $pluginClientOptions config forwarded to the PluginClient
16+
* @param Plugin[] $plugins
17+
* @param ClientFactory|callable $factory
18+
* @param array $config config to the client factory
19+
* @param array $pluginClientOptions config forwarded to the PluginClient
2020
*
2121
* @return PluginClient
2222
*/
23-
public static function createPluginClient(array $plugins, ClientFactory $factory, array $config, array $pluginClientOptions = [])
23+
public static function createPluginClient(array $plugins, $factory, array $config, array $pluginClientOptions = [])
2424
{
25-
return new PluginClient($factory->createClient($config), $plugins, $pluginClientOptions);
25+
if ($factory instanceof ClientFactory) {
26+
$client = $factory->createClient($config);
27+
} elseif (is_callable($factory)) {
28+
$client = $factory($config);
29+
} else {
30+
throw new \RuntimeException(sprintf('Second argument to PluginClientFactory::createPluginClient must be a "%s" or a callable.', ClientFactory::class));
31+
}
32+
33+
return new PluginClient($client, $plugins, $pluginClientOptions);
2634
}
2735
}

DependencyInjection/Configuration.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@
1919
*/
2020
class Configuration implements ConfigurationInterface
2121
{
22+
/**
23+
* Whether to use the debug mode.
24+
*
25+
* @see https://github.com/doctrine/DoctrineBundle/blob/v1.5.2/DependencyInjection/Configuration.php#L31-L41
26+
*
27+
* @var bool
28+
*/
29+
private $debug;
30+
31+
/**
32+
* @param bool $debug
33+
*/
34+
public function __construct($debug)
35+
{
36+
$this->debug = (bool) $debug;
37+
}
38+
2239
/**
2340
* {@inheritdoc}
2441
*/
@@ -75,12 +92,17 @@ public function getConfigTreeBuilder()
7592
->end()
7693
->arrayNode('toolbar')
7794
->addDefaultsIfNotSet()
78-
->info('Extend the debug profiler with inforation about requests.')
95+
->info('Extend the debug profiler with information about requests.')
7996
->children()
80-
->enumNode('enabled')
81-
->info('If "auto" (default), the toolbar is activated when kernel.debug is true. You can force the toolbar on and off by changing this option.')
82-
->values([true, false, 'auto'])
83-
->defaultValue('auto')
97+
->booleanNode('enabled') // @deprecated value auto in 1.3.0
98+
->beforeNormalization()
99+
->ifString()
100+
->then(function ($v) {
101+
return 'auto' === $v ? $this->debug : $v;
102+
})
103+
->end()
104+
->info('Turn the toolbar on or off. Defaults to kernel debug mode.')
105+
->defaultValue($this->debug)
84106
->end()
85107
->scalarNode('formatter')->defaultNull()->end()
86108
->scalarNode('captured_body_length')

0 commit comments

Comments
 (0)