Hydrate elements of a country.

@param $country
@param $elements
@return mixed
332274
private function hydrateCountry($country, $elements)
    {
        $countryCode = $country['cca3'];

        $this->addCountry($countryCode, $country);

        foreach ($elements as $element => $enabled) {
            $this->hydrateCountryElement($countryCode, $element, $enabled);
        }

        return $this->getCountry($countryCode);
    }
159634
public function hydrate(array $items)
    {
        $instance = $this->model->newInstance();

        return $instance->newCollection(array_map(function ($item) use ($instance) {
            return $instance->newFromBuilder($item);
        }, $items));
    }
1220530
public static function hydrateCollection(array $parts)
    {
        $hydrated = [];

        foreach ($parts as $part) {
            $hydrated[] = self::hydrate($part);
        }

        return $hydrated;
    }
583745
public function recognize($nameOrNames, $country = null, $language = null, $hydration = self::HYDRATE_OBJECT)
    {
        if ($country !== null && ! isset($this->validCountries[strtoupper($country)])) {
            throw new CountryNotValidException(sprintf('Country %s is not valid', strtoupper($country)));
        }

        if ($language !== null && ! isset($this->validLanguages[strtolower($language)])) {
            throw new LanguageNotValidException(sprintf('Language %s is not valid', strtolower($language)));
        }

        $query = [
            'name' => $nameOrNames,
        ];
        
        if ($this->apiKey !== null) {
            $query['apikey'] = $this->apiKey;
        }

        if ($country !== null) {
            $query['country_id'] = $country;
        }

        if ($language !== null) {
            $query['language_id'] = $language;
        }

        $data = $this->genderizeClient->genderize($query);

        if ($hydration == self::HYDRATE_OBJECT) {
            if (is_array($nameOrNames)) {
                $collection = [];
                foreach ($data as $nameData) {
                    $collection[] = Name::factory($nameData);
                }
                // multiple query
                return $collection;
            } else {
                // single query
                return Name::factory($data);
            }
        } else {
            // multiple or single query
            return $data;
        }
    }
391189
protected function checkHydrationElements($elements)
    {
        $elements = countriesCollect($elements)->mapWithKeys(function ($value, $key) {
            if (is_numeric($key)) {
                $key = $value;
                $value = true;
            }

            return [$key => $value];
        })->filter(function ($element) {
            return $element;
        });

        return $elements;
    }
270154
public static function hydrate( array $items, $connection = null )
	{
		$instance = ( new static )->setConnection( $connection );

		$items = array_map( function ( $item ) use ( $instance )
		{
			return $instance->newFromBuilder( $item );
		}, $items );

		return $instance->newCollection( $items );
	}
145911
public function getAreaForCountry(Country $country)
    {
        $area = null;

        if (null !== $areaDeliveryModule = AreaDeliveryModuleQuery::create()->findByCountryAndModule(
            $country,
            $this->getModuleModel()
        )) {
            $area = $areaDeliveryModule->getArea();
        }

        return $area;
    }
647845
public function setCountry($country)
    {
        $this->set('country', $country);

        $vat = $this->getService('repos:subscriptions.vat')->find(array('country' => $country));

        if ($vat) {
            $this->setVat($vat);
        }

        return $this;
    }
970929
public function where($key, $operator, $value = null)
    {
        if (func_num_args() == 2) {
            $value = $operator;

            $operator = '=';
        }

        $countries = method_exists($this, 'where'.ucfirst($key))
            ? $this->{'where'.ucfirst($key)}($value)
            : parent::where($key, $operator, $value);

        return $this->hydrateDefaultElements($countries);
    }
482400
public function removeCountry($country)
    {
        if (in_array($country, $this->countries)) {
            unset($this->countries[array_search($country, $this->countries)]);
        }

        return $this;
    }
1228471
private function createCountry(DOMElement $element)
    {
        if ($element->hasAttribute('common_name')) {
            $short = $element->getAttribute('common_name');
        } else {
            $short = $element->getAttribute('name');
        }

        if ($element->hasAttribute('official_name')) {
            $long = $element->getAttribute('official_name');
        } else {
            $long = null;
        }

        return new Country(
            $element->getAttribute('alpha_2_code'),
            $element->getAttribute('alpha_3_code'),
            $long,
            $element->getAttribute('numeric_code'),
            $short
        );
    }
546275
public function hydrateCountryElement($countryCode, $element, $enabled)
    {
        if ($this->needsHydration($countryCode, $element, $enabled)) {
            $this->repository->countries[$countryCode] = $this->{'hydrate'.Str::studly($element)}($this->repository->countries[$countryCode]);
        }
    }
1226050
protected function canHydrate($element, $enabled, $countryCode)
    {
        return ($enabled || $this->config->get('hydrate.elements.'.$element)) &&
                ! isset($this->repository->countries[$countryCode]['hydrated'][$element]);
    }
328637
protected function buildElementsByBlock($elements)
    {
        if (empty($elements)) {
            return $elements;
        }

        $output = [];
        foreach ($elements as $element) {
            $output[$element->block_key][] = $element;
        }

        return $output;
    }
46103
public function hydrateSet($key, $element)
    {
        $this->collection->set($key, $element);

        // If _backRefFieldName is set, then the association is bidirectional
        // and we need to set the back reference.
        if ($this->backRefFieldName && $this->association instanceof OneToManyAssociationMetadata) {
            $inversedAssociation = $this->typeClass->getProperty($this->backRefFieldName);

            // Set back reference to owner
            $inversedAssociation->setValue($element, $this->owner);

            $this->em->getUnitOfWork()->setOriginalEntityProperty(
                spl_object_id($element),
                $this->backRefFieldName,
                $this->owner
            );
        }
    }
673624
public static function country($code, $hydrate = true)
    {
        $code = mb_strtolower($code);

        if (! isset(static::$countries[$code])) {
            static::$countries[$code] = json_decode(static::getFile(__DIR__.'/../resources/data/'.$code.'.json'), true);
        }

        return $hydrate ? new Country(static::$countries[$code]) : static::$countries[$code];
    }
890343
public static function hydrateRaw( $query, $bindings = [], $connection = null )
	{
		$instance = ( new static )->setConnection( $connection );

		$items = $instance->getConnection()->select( $query, $bindings );

		return static::hydrate( $items, $connection );
	}