Skip to content

Commit d89534b

Browse files
authored
Merge pull request #86 from keboola/novakjiri-PST-1643
PST-1643 fix and update sample code
2 parents cf303a8 + 9c4a2fa commit d89534b

File tree

10 files changed

+31
-22
lines changed

10 files changed

+31
-22
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ RUN composer install $COMPOSER_FLAGS --no-scripts --no-autoloader
2626
COPY . .
2727
RUN composer install $COMPOSER_FLAGS
2828

29-
CMD composer ci
29+
CMD php ./example/run.php

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class Component extends \Keboola\Component\BaseComponent
2121
// get parameters
2222
$parameters = $this->getConfig()->getParameters();
2323

24-
// get value of customKey.customSubkey parameter and fail if missing
25-
$customParameter = $this->getConfig()->getValue(['parameters', 'customKey', 'customSubkey']);
24+
// get value of customKey.customSubKey parameter and fail if missing
25+
$customParameter = $this->getConfig()->getValue(['parameters', 'customKey', 'customSubKey']);
2626

2727
// get value with default value if not present
2828
$customParameterOrNull = $this->getConfig()->getValue(['parameters', 'customKey'], 'someDefaultValue');
@@ -109,17 +109,17 @@ To implement a sync action
109109

110110
### Custom getters in config
111111

112-
You might want to add getter methods for custom parameters in the config. That way you don't need to remember exact keys (`parameters.errorCount.maximumAllowed`), but instead use a method to retrieve the value (`$config->getMaximumAllowedErrorCount()`).
112+
You might want to add getter methods for custom parameters in the config. That way you don't need to remember exact keys (`parameters.customKey.customSubKey`), but instead use a method to retrieve the value (`$config->getCustomSubKey()`).
113113

114114
Simply create your own `Config` class, that extends `BaseConfig` and override `\Keboola\Component\BaseComponent::getConfigClass()` method to return your new class name.
115115

116116
```php
117117
class MyConfig extends \Keboola\Component\Config\BaseConfig
118118
{
119-
public function getMaximumAllowedErrorCount()
119+
public function getCustomSubKey()
120120
{
121121
$defaultValue = 0;
122-
return $this->getValue(['parameters', 'errorCount', 'maximumAllowed'], $defaultValue);
122+
return $this->getValue(['parameters', 'customKey', 'customSubKey'], $defaultValue);
123123
}
124124
}
125125
```
@@ -149,10 +149,10 @@ class MyConfigDefinition extends \Keboola\Component\Config\BaseConfigDefinition
149149
$parametersNode
150150
->isRequired()
151151
->children()
152-
->arrayNode('errorCount')
152+
->arrayNode('customKey')
153153
->isRequired()
154154
->children()
155-
->integerNode('maximumAllowed')
155+
->integerNode('customSubKey')
156156
->isRequired();
157157
return $parametersNode;
158158
}

example/Component.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ protected function run(): void
1515
// get parameters
1616
$parameters = $this->getConfig()->getParameters();
1717

18-
// get value of customKey.customSubkey parameter and fail if missing
19-
$customParameter = $this->getConfig()->getValue(['parameters', 'customKey', 'customSubkey']);
18+
// get value of customKey.customSubKey parameter and fail if missing
19+
$customParameter = $this->getConfig()->getValue(['parameters', 'customKey', 'customSubKey']);
2020

2121
// get value with default value if not present
22-
$customParameterOrNull = $this->getConfig()->getValue(['parameters', 'customKey'], 'someDefaultValue');
22+
$customParameterOrNull = $this->getConfig()->getValue(['parameters', 'anotherCustomKey'], 'someDefaultValue');
2323

2424
// get manifest for input file
2525
$fileManifest = $this->getManifestManager()->getFileManifest('input-file.csv');
@@ -53,4 +53,14 @@ protected function getSyncActions(): array
5353
{
5454
return ['custom' => 'customSyncAction'];
5555
}
56+
57+
protected function getConfigDefinitionClass(): string
58+
{
59+
return MyConfigDefinition::class;
60+
}
61+
62+
protected function getConfigClass(): string
63+
{
64+
return MyConfig::class;
65+
}
5666
}

example/MyConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
class MyConfig extends BaseConfig
1010
{
11-
public function getMaximumAllowedErrorCount(): int
11+
public function getCustomSubKey(): int
1212
{
1313
$defaultValue = 0;
14-
return $this->getIntValue(['parameters', 'errorCount', 'maximumAllowed'], $defaultValue);
14+
return $this->getIntValue(['parameters', 'customKey', 'customSubKey'], $defaultValue);
1515
}
1616
}

example/MyConfigDefinition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ protected function getParametersDefinition(): ArrayNodeDefinition
1515
$parametersNode
1616
->isRequired()
1717
->children()
18-
->arrayNode('errorCount')
18+
->arrayNode('customKey')
1919
->isRequired()
2020
->children()
21-
->integerNode('maximumAllowed')
21+
->integerNode('customSubKey')
2222
->isRequired();
2323
return $parametersNode;
2424
}

phpcs.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
55
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/>
66
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
7-
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
87
</rule>
98
<exclude-pattern>*/src/Kernel.php</exclude-pattern>
109
</ruleset>

src/Config/BaseConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class BaseConfig implements ConfigInterface
3131
*/
3232
public function __construct(
3333
array $config,
34-
?ConfigurationInterface $configDefinition = null
34+
?ConfigurationInterface $configDefinition = null,
3535
) {
3636
$this->setConfigDefinition($configDefinition);
3737
$this->setConfig($config);

src/Manifest/ManifestManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ManifestManager
2020
private string $dataDir;
2121

2222
public function __construct(
23-
string $dataDir
23+
string $dataDir,
2424
) {
2525
$this->dataDir = $dataDir;
2626
}
@@ -36,7 +36,7 @@ final public function getManifestFilename(string $fileName): string
3636

3737
public function writeFileManifest(
3838
string $fileName,
39-
OutFileManifestOptions $options
39+
OutFileManifestOptions $options,
4040
): void {
4141
$tableManifestName = $this->getManifestFilename($fileName);
4242
$this->internalWriteFileManifest($tableManifestName, $options->toArray());

src/Manifest/ManifestManager/Options/OutTable/ManifestOptionsSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(
3131
bool $nullable = true,
3232
bool $primaryKey = false,
3333
?string $description = null,
34-
?array $metadata = null
34+
?array $metadata = null,
3535
) {
3636
$this->setName($name);
3737
if ($dataTypes !== null) {

src/Manifest/ManifestManager/Options/OutTable/Serializer/LegacyManifestNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private function setTableMetadata(ManifestOptions $manifestOptions, array $data)
172172
private function setSchema(
173173
ManifestOptions $manifestOptions,
174174
array $data,
175-
?string $metadataBackend
175+
?string $metadataBackend,
176176
): void {
177177
$schema = [];
178178

@@ -226,7 +226,7 @@ private function setMetadata(
226226
array &$metadata,
227227
?string &$description,
228228
bool &$primaryKey,
229-
bool &$isNullable
229+
bool &$isNullable,
230230
): void {
231231
if ($meta['key'] === 'KBC.description') {
232232
$description = $meta['value'];

0 commit comments

Comments
 (0)