vendor/shopware/core/System/Country/Aggregate/CountryState/CountryStateCollection.php line 10

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\System\Country\Aggregate\CountryState;
  3. use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
  4. /**
  5.  * @extends EntityCollection<CountryStateEntity>
  6.  */
  7. class CountryStateCollection extends EntityCollection
  8. {
  9.     public function getCountryIds(): array
  10.     {
  11.         return $this->fmap(function (CountryStateEntity $countryState) {
  12.             return $countryState->getCountryId();
  13.         });
  14.     }
  15.     public function filterByCountryId(string $id): self
  16.     {
  17.         return $this->filter(function (CountryStateEntity $countryState) use ($id) {
  18.             return $countryState->getCountryId() === $id;
  19.         });
  20.     }
  21.     public function sortByPositionAndName(): void
  22.     {
  23.         uasort($this->elements, function (CountryStateEntity $aCountryStateEntity $b) {
  24.             if ($a->getPosition() !== $b->getPosition()) {
  25.                 return $a->getPosition() <=> $b->getPosition();
  26.             }
  27.             if ($a->getTranslation('name') !== $b->getTranslation('name')) {
  28.                 return strnatcasecmp($a->getTranslation('name'), $b->getTranslation('name'));
  29.             }
  30.             return 0;
  31.         });
  32.     }
  33.     public function getApiAlias(): string
  34.     {
  35.         return 'country_state_collection';
  36.     }
  37.     protected function getExpectedClass(): string
  38.     {
  39.         return CountryStateEntity::class;
  40.     }
  41. }