src/Repository/ZoneRepository.php
protected function createZoneFromDefinition(array $definition)
    {
        $zone = new Zone();
        // Bind the closure to the Zone object, giving it access to
        // its protected properties. Faster than both setters and reflection.
        $setValues = \Closure::bind(function ($definition) {
            $this->id = $definition['id'];
            $this->name = $definition['name'];
            if (isset($definition['scope'])) {
                $this->scope = $definition['scope'];
            }
            if (isset($definition['priority'])) {
                $this->priority = $definition['priority'];
            }
        }, $zone, '\CommerceGuys\Zone\Model\Zone');
        $setValues($definition);

        // Add the zone members.
        foreach ($definition['members'] as $memberDefinition) {
            if ($memberDefinition['type'] == 'country') {
                $zoneMember = $this->createZoneMemberCountryFromDefinition($memberDefinition);
                $zone->addMember($zoneMember);
            } elseif ($memberDefinition['type'] == 'zone') {
                $zoneMember = $this->createZoneMemberZoneFromDefinition($memberDefinition);
                $zone->addMember($zoneMember);
            }
        }

        return $zone;
    }
protected function createZoneFromDefinition(array $definition)
    {
        $zone = new Zone();
        // Bind the closure to the Zone object, giving it access to
        // its protected properties. Faster than both setters and reflection.
        $setValues = \Closure::bind(function ($definition) {
            $this->id = $definition['id'];
            $this->name = $definition['name'];
            if (isset($definition['scope'])) {
                $this->scope = $definition['scope'];
            }
            if (isset($definition['priority'])) {
                $this->priority = $definition['priority'];
            }
        }, $zone, '\CommerceGuys\Zone\Model\Zone');
        $setValues($definition);

        // Add the zone members.
        foreach ($definition['members'] as $memberDefinition) {
            if ($memberDefinition['type'] == 'country') {
                $zoneMember = $this->createZoneMemberCountryFromDefinition($memberDefinition);
                $zone->addMember($zoneMember);
            } elseif ($memberDefinition['type'] == 'zone') {
                $zoneMember = $this->createZoneMemberZoneFromDefinition($memberDefinition);
                $zone->addMember($zoneMember);
            }
        }

        return $zone;
    }
Creates a Zone instance from the provided definition.

@param array $definition The zone definition.

@return Zone