-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
services: | ||
Drupal\os2forms_selvbetjening\Commands\LookupCommands: | ||
arguments: | ||
- '@plugin.manager.os2web_datalookup' | ||
tags: | ||
- { name: drush.command } |
98 changes: 98 additions & 0 deletions
98
web/modules/custom/os2forms_selvbetjening/src/Commands/LookupCommands.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
namespace Drupal\os2forms_selvbetjening\Commands; | ||
|
||
use Drupal\os2web_datalookup\Plugin\DataLookupManager; | ||
use Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DatafordelerCVR; | ||
use Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterfaceCpr; | ||
use Drush\Commands\DrushCommands; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
/** | ||
* Lookup commands. | ||
*/ | ||
class LookupCommands extends DrushCommands { | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct( | ||
private readonly DataLookupManager $dataLookupManager | ||
) { | ||
} | ||
|
||
/** | ||
* Look up CPR. | ||
* | ||
* @param string $cpr | ||
* The cpr. | ||
* @param array $options | ||
* The command options. | ||
* | ||
* @command os2forms-selvbetjening:look-up:cpr | ||
* @usage os2forms-selvbetjening:look-up:cpr --help | ||
*/ | ||
public function lookUpCpr(string $cpr, array $options = [ | ||
'dump-configuration' => FALSE, | ||
]) { | ||
try { | ||
$instance = $this->dataLookupManager->createDefaultInstanceByGroup('cpr_lookup'); | ||
assert($instance instanceof DataLookupInterfaceCpr); | ||
|
||
if ($options['dump-configuration']) { | ||
$this->output()->writeln([ | ||
Yaml::dump($instance->getConfiguration()), | ||
]); | ||
} | ||
$result = $instance->lookup($cpr); | ||
|
||
if (!$result->isSuccessful()) { | ||
$this->output()->writeln($result->getErrorMessage()); | ||
} | ||
else { | ||
$this->output()->write($result->getName()); | ||
} | ||
} | ||
catch (\Exception $exception) { | ||
$this->output()->writeln($exception->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Look up CVR. | ||
* | ||
* @param string $cvr | ||
* The cvr. | ||
* @param array $options | ||
* The command options. | ||
* | ||
* @command os2forms-selvbetjening:look-up:cvr | ||
* @usage os2forms-selvbetjening:look-up:cvr --help | ||
*/ | ||
public function lookUpCvr(string $cvr, array $options = [ | ||
'dump-configuration' => FALSE, | ||
]) { | ||
try { | ||
$instance = $this->dataLookupManager->createDefaultInstanceByGroup('cvr_lookup'); | ||
assert($instance instanceof DatafordelerCVR); | ||
|
||
if ($options['dump-configuration']) { | ||
$this->output()->writeln([ | ||
Yaml::dump($instance->getConfiguration()), | ||
]); | ||
} | ||
$result = $instance->lookup($cvr); | ||
|
||
if (!$result->isSuccessful()) { | ||
$this->output()->writeln($result->getErrorMessage()); | ||
} | ||
else { | ||
$this->output()->write($result->getName()); | ||
} | ||
} | ||
catch (\Exception $exception) { | ||
$this->output()->writeln($exception->getMessage()); | ||
} | ||
} | ||
|
||
} |