chill-bundles/src/Bundle/ChillPersonBundle/Config/ConfigPersonAltNamesHelper.php
2022-01-04 15:29:17 +01:00

73 lines
1.6 KiB
PHP

<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Config;
/**
* Give help to interact with the config for alt names.
*/
class ConfigPersonAltNamesHelper
{
/**
* the raw config, directly from the container parameter.
*
* @var array
*/
private $config = [];
public function __construct($config)
{
$this->config = $config;
}
/**
* get the choices as key => values.
*/
public function getChoices(): array
{
$choices = [];
foreach ($this->config as $entry) {
$labels = $entry['labels'];
$lang = false;
$label = false;
$cur = reset($labels);
while ($cur) {
if (key($labels) === 'lang') {
$lang = current($labels);
}
if (key($labels) === 'label') {
$label = current($labels);
}
if (false !== $lang && false !== $label) {
$choices[$entry['key']][$lang] = $label;
$lang = false;
$label = false;
}
$cur = next($labels);
}
}
return $choices;
}
/**
* Return true if at least one alt name is configured.
*/
public function hasAltNames(): bool
{
return [] !== $this->config;
}
}