wikimedia/mediawiki-extensions-Wikibase

View on GitHub
repo/rest-api/src/Domain/ReadModel/Aliases.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php declare( strict_types = 1 );

namespace Wikibase\Repo\RestApi\Domain\ReadModel;

use ArrayObject;
use Wikibase\DataModel\Term\AliasGroup;
use Wikibase\DataModel\Term\AliasGroupList;

/**
 * @license GPL-2.0-or-later
 */
class Aliases extends ArrayObject {

    public function __construct( AliasesInLanguage ...$aliases ) {
        parent::__construct(
            array_combine(
                array_map( fn( AliasesInLanguage $a ) => $a->getLanguageCode(), $aliases ),
                $aliases
            )
        );
    }

    public static function fromAliasGroupList( AliasGroupList $aliasGroupList ): self {
        return new Aliases(
            ...array_map(
                fn( AliasGroup $a ) => new AliasesInLanguage( $a->getLanguageCode(), $a->getAliases() ),
                array_values( $aliasGroupList->toArray() )
            )
        );
    }
}