|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* generate params array for various calls |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\GeneratorBundle\Generator\ResourceGenerator; |
|
7
|
|
|
|
|
8
|
|
|
use Symfony\Component\DependencyInjection\Container; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
12
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
13
|
|
|
* @link http://swisscom.ch |
|
14
|
|
|
*/ |
|
15
|
|
|
class ParameterBuilder |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var array |
|
19
|
|
|
*/ |
|
20
|
|
|
private $parameters; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param string $name parameter name |
|
24
|
|
|
* @param mixed $value parameter to set |
|
25
|
|
|
* |
|
26
|
|
|
* @return self |
|
27
|
|
|
*/ |
|
28
|
18 |
|
public function setParameter($name, $value) |
|
29
|
|
|
{ |
|
30
|
18 |
|
if ($name === 'basename') { |
|
31
|
4 |
|
$this->parameters['bundle_basename'] = $value; |
|
32
|
4 |
|
$this->parameters['extension_alias'] = Container::underscore($value); |
|
33
|
16 |
|
} elseif ($name === 'json') { |
|
34
|
6 |
|
$this->parameters['json'] = $value; |
|
35
|
|
|
// if we have data for id field, pass it along |
|
36
|
6 |
|
$idField = $value->getField('id'); |
|
37
|
6 |
|
if (!is_null($idField)) { |
|
38
|
4 |
|
$this->parameters['idField'] = $idField->getDefAsArray(); |
|
39
|
2 |
|
} else { |
|
40
|
|
|
// if there is a json file and no id defined - so we don't do one here.. |
|
41
|
|
|
// we leave it in the document though but we don't wanna output it.. |
|
42
|
2 |
|
$this->parameters['noIdField'] = true; |
|
43
|
|
|
} |
|
44
|
6 |
|
$this->parameters['parent'] = $value->getParentService(); |
|
45
|
11 |
|
} elseif ($name === 'recordOriginModifiable' && $value !== null) { |
|
46
|
|
|
$this->parameters[$name] = ($value) ? 'true' : 'false'; |
|
47
|
|
|
} else { |
|
48
|
8 |
|
$this->parameters[$name] = $value; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
18 |
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return array |
|
56
|
|
|
*/ |
|
57
|
18 |
|
public function getParameters() |
|
58
|
|
|
{ |
|
59
|
18 |
|
return $this->parameters; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|