Skip to content

Commit 2dd852b

Browse files
author
Krzysztof Chrapka
committed
Remove undocumented cruft from dev phase, add missing method support
Also switch Installation->name to method
1 parent 3e303a2 commit 2dd852b

5 files changed

Lines changed: 33 additions & 29 deletions

File tree

doc/examples/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
$request = Request::createFromGlobals();
1313
$requestedInstallation = $request->server->get('SYMFONY_INSTALLATION'); // might be set by http server based on domain
14-
$installation = new Installation($requestedInstallation, Installation::TYPE_PROD);
14+
$installation = new Installation($requestedInstallation);
1515
$kernel = new AppKernel($installation, 'live', false);
1616

1717
$response = $kernel->handle($request);

doc/examples/console.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev');
1212
$requestedInstallation = $input->getParameterOption(['--installation']);
1313

14-
$installation = new Installation($requestedInstallation, Installation::TYPE_PROD);
14+
$installation = new Installation($requestedInstallation);
1515
$kernel = new AppKernel($installation, $env);
1616
$application = new Application($kernel);
1717
$application->run($input);

src/Kernel/Installation.php

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,26 @@
22

33
namespace OJezu\DynamicParameterBundle\Kernel;
44

5-
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
6-
75
class Installation
86
{
9-
const TYPE_PROD = 'prod';
10-
const TYPE_NEXT = 'next';
11-
12-
const TYPES = [
13-
self::TYPE_PROD,
14-
self::TYPE_NEXT,
15-
];
7+
/**
8+
* @var string
9+
*/
10+
private $name;
1611

17-
public function __construct($name, $type)
12+
/**
13+
* @param $name
14+
*/
15+
public function __construct($name)
1816
{
19-
if (!in_array($type, self::TYPES)) {
20-
throw new InvalidConfigurationException('Unknown installation type: '.$type);
21-
}
22-
2317
$this->name = $name;
24-
$this->type = $type;
2518
}
2619

2720
/**
28-
* @var string
21+
* @return string
2922
*/
30-
public $name;
31-
32-
/**
33-
* @var string
34-
*/
35-
public $type;
23+
public function name()
24+
{
25+
return $this->name;
26+
}
3627
}

src/Service/DynamicParameterEnvVarProcessor.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ class DynamicParameterEnvVarProcessor implements EnvVarProcessorInterface
3232
* @param array $parameterMap
3333
* @param bool $loadConfiguration
3434
*/
35-
public function __construct(ParameterProviderInterface $parameterProvider, array $parameterMap, $loadConfiguration = true)
36-
{
35+
public function __construct(
36+
ParameterProviderInterface $parameterProvider,
37+
array $parameterMap,
38+
$loadConfiguration = true
39+
) {
3740
$this->parameterProvider = $parameterProvider;
3841
$this->parameterMap = $parameterMap;
3942
$this->cache = [];

src/Service/InstallationEnvVarProcessor.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,21 @@ public function __construct(Installation $installation)
3535
*/
3636
public function getEnv($prefix, $name, \Closure $getEnv)
3737
{
38-
if (!property_exists($this->installation, $name)) {
39-
throw new InvalidArgumentException(sprintf('Installation object does not have »%s« property', $name));
38+
$result = null;
39+
40+
if (is_callable([$this->installation, $name])) {
41+
$result = $this->installation->{$name}();
42+
} elseif (property_exists($this->installation, $name)) {
43+
//TODO: reflection maybe?
44+
$result = $this->installation->$name;
45+
} else {
46+
throw new InvalidArgumentException(sprintf(
47+
'Installation object does not have »%s« property or method',
48+
$name
49+
));
4050
}
4151

42-
return $this->installation->$name;
52+
return $result;
4353
}
4454

4555
/**

0 commit comments

Comments
 (0)