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

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. use Shopware\Core\Framework\Log\Package;
  5. /**
  6.  * @extends EntityCollection<CountryStateEntity>
  7.  */
  8. #[Package('system-settings')]
  9. class CountryStateCollection extends EntityCollection
  10. {
  11.     public function getCountryIds(): array
  12.     {
  13.         return $this->fmap(function (CountryStateEntity $countryState) {
  14.             return $countryState->getCountryId();
  15.         });
  16.     }
  17.     public function filterByCountryId(string $id): self
  18.     {
  19.         return $this->filter(function (CountryStateEntity $countryState) use ($id) {
  20.             return $countryState->getCountryId() === $id;
  21.         });
  22.     }
  23.     public function sortByPositionAndName(): void
  24.     {
  25.         uasort($this->elements, function (CountryStateEntity $aCountryStateEntity $b) {
  26.             if ($a->getPosition() !== $b->getPosition()) {
  27.                 return $a->getPosition() <=> $b->getPosition();
  28.             }
  29.             if ($a->getTranslation('name') !== $b->getTranslation('name')) {
  30.                 return strnatcasecmp($a->getTranslation('name'), $b->getTranslation('name'));
  31.             }
  32.             return 0;
  33.         });
  34.     }
  35.     public function getApiAlias(): string
  36.     {
  37.         return 'country_state_collection';
  38.     }
  39.     protected function getExpectedClass(): string
  40.     {
  41.         return CountryStateEntity::class;
  42.     }
  43. }