Creates a subdivision object from the provided definitions.

@param int    $code        The subdivision code.
@param array  $definitions The subdivision definitions.

@return Subdivision
502348
protected function createSubdivisionFromDefinitions($code, array $definitions)
    {
        if (!isset($definitions['subdivisions'][$code])) {
            // No matching definition found.
            return null;
        }

        $definition = $definitions['subdivisions'][$code];
        // The 'parents' key is omitted when it contains just the country code.
        $definitions += [
            'parents' => [$definitions['country_code']],
        ];
        $parents = $definitions['parents'];
        // Load the parent, if known.
        $definition['parent'] = null;
        if (count($parents) > 1) {
            $grandparents = $parents;
            $parentId = array_pop($grandparents);
            $parentGroup = $this->buildGroup($grandparents);
            if (!isset($this->parents[$parentGroup][$parentId])) {
                $this->parents[$parentGroup][$parentId] = $this->get($parentId, $grandparents);
            }
            $definition['parent'] = $this->parents[$parentGroup][$parentId];
        }
        // Prepare children.
        if (!empty($definition['has_children'])) {
            $childrenParents = array_merge($parents, [$code]);
            $children = new LazySubdivisionCollection($childrenParents);
            $children->setRepository($this);
            $definition['children'] = $children;
        }

        return new Subdivision($definition);
    }
1056239
public static function Create($code, $args = null, $_ = null)
  {
    if (!is_null($args)) {
      if (!is_array($args)) {
        $args = array_slice(func_get_args(), 1);
      }
    }

    $str = static::GetNameForCode($code, $args);

    return new static($str, $code);
  }
265087
public function createSubFormsCreator($countryIso2Code)
    {
        if (isset($this->subFormsCreators[$countryIso2Code])) {
            $subFormsCreator = $this->subFormsCreators[$countryIso2Code]();
        } else {
            $subFormsCreator = $this->subFormsCreators[self::DEFAULT_COUNTRY]();
        }

        return $subFormsCreator;
    }
1179160
function setCode( $code ) {
        $this->code = $code;
        $this->addHeader($this->getDefaultHeaderFromCode( $code ));
        return $this;
    }
1105190
public static function countryLocaleCode($countryCode)
    {
        $countryLocaleCodes = static::countryLocaleCodes($countryCode);
        if ($languageCode = Language::countryLanguageCode($countryCode)) {
            $languageLocaleCodes = static::languageLocaleCodes($languageCode);
            if ($localeCodes = array_intersect($languageLocaleCodes, $countryLocaleCodes)) {
                return reset($localeCodes);
            } elseif ($countryLocaleCodes) {
                return reset($countryLocaleCodes);
            } elseif ($languageLocaleCodes) {
                return reset($languageLocaleCodes);
            }

            return \Locale::composeLocale([
                'language' => $languageCode,
                'region' => $countryCode,
            ]);
        }

        if (!count($countryLocaleCodes)) {
            return null;
        } elseif (count($countryLocaleCodes) == 1) {
            return reset($countryLocaleCodes);
        }

        if ($localeCode = static::findMainCode($countryLocaleCodes)) {
            return $localeCode;
        }

        foreach ($countryLocaleCodes as $localeCode) {
            $languageCode = static::languageCode($localeCode);
            if (!strcasecmp($languageCode, $countryCode)) {
                return $localeCode;
            }
        }

        return reset($countryLocaleCodes);
    }
361185
protected function fromArray(array $definition)
    {
        $definition += $this->defaultDefinition;

        $refClass = new ReflectionClass($definition['class']);
        $instance = $refClass->newInstanceArgs(self::parseArguments($definition['arguments']));

        foreach ($definition['call'] as $methodName => $args) {
            $refMethod = new ReflectionMethod($instance, $methodName);
            $refMethod->invokeArgs($instance, self::parseArguments($args));
        }

        return $instance;
    }
1081004
protected function compress($code) {
        $compressor = new Compressor();
        $result = $compressor->setCode($code)
                             ->compress()
                             ->getCompressedCode();
        return $result;
    }
1336171
public static function countryContinentCode($countryCode)
    {
        foreach (static::CODES as $code => $countryCodes) {
            if (in_array($countryCode, $countryCodes)) {
                return $code;
            }
        }

        return null;
    }
491762
public function configure(...$definitions): ContainerConfiguration
    {
        $builder = new ContainerBuilder(ContainerConfiguration::class);

        $builder->useAutowiring(false)->useAnnotations(false)->ignorePhpDocErrors(false);

        $wiring = $this->config[WIRING] ?? null;
        if (fn\hasValue($wiring, [WIRING\REFLECTION, WIRING\AUTO])) {
            $builder->useAutowiring(true);
        } else if ($wiring === WIRING\STRICT) {
            $builder->useAnnotations(true)->ignorePhpDocErrors(false);
        } else if ($wiring === WIRING\TOLERANT) {
            $builder->useAnnotations(true)->ignorePhpDocErrors(true);
        }

        empty($this->config[CACHE]) || $builder->enableDefinitionCache();
        empty($this->config[PROXY]) || $builder->writeProxiesToFile(true, $this->config[PROXY]);
        empty($this->config[COMPILE]) || $builder->enableCompilation($this->config[COMPILE]);
        $this->container && $builder->wrapContainer($this->container);

        foreach ($definitions as $definition) {
            $builder->addDefinitions($definition);
        }

        /** @noinspection PhpUnhandledExceptionInspection */
        /** @noinspection PhpIncompatibleReturnTypeInspection */
        $built = $builder->build();
        return $built instanceof ContainerConfiguration
            ? $built
            : new ContainerConfiguration($built);
    }
153411
protected function createTaxTypeFromDefinition(array $definition)
    {
        // Load the referenced zone.
        $definition['zone'] = $this->zoneRepository->get($definition['zone']);
        // Provide defaults.
        if (!isset($definition['compound'])) {
            $definition['compound'] = false;
        }
        if (!isset($definition['display_inclusive'])) {
            $definition['display_inclusive'] = false;
        }
        if (!isset($definition['rounding_mode'])) {
            $definition['rounding_mode'] = PHP_ROUND_HALF_UP;
        }

        $type = new TaxType();
        // Bind the closure to the TaxType 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'];
            $this->compound = $definition['compound'];
            $this->displayInclusive = $definition['display_inclusive'];
            $this->roundingMode = $definition['rounding_mode'];
            $this->zone = $definition['zone'];
            if (isset($definition['generic_label'])) {
                $this->genericLabel = $definition['generic_label'];
            }
            if (isset($definition['tag'])) {
                $this->tag = $definition['tag'];
            }
        }, $type, '\CommerceGuys\Tax\Model\TaxType');
        $setValues($definition);

        foreach ($definition['rates'] as $rateDefinition) {
            $rate = $this->createTaxRateFromDefinition($rateDefinition);
            $type->addRate($rate);
        }

        return $type;
    }
759961
public function addDefinitions(array $definitions)
    {
        foreach ($definitions as $id => $definition) {
            $this->setDefinition($id, $definition);
        }
    }
1312377
public static function fromIso($code)
    {
        $countryCode = strtoupper($code);
        $table = self::isoCodes();

        if (!array_key_exists($countryCode, $table)) {
            return null;
        }

        return $table[$countryCode];
    }
874134
public static void addLazyDefinitions(SourceBuilder code) {
    Set<Declaration> defined = new HashSet<>();

    // Definitions may lazily declare new names; ensure we add them all
    List<Declaration> declarations =
        code.scope().keysOfType(Declaration.class).stream().sorted().collect(toList());
    while (!defined.containsAll(declarations)) {
      for (Declaration declaration : declarations) {
        if (defined.add(declaration)) {
          code.add(code.scope().get(declaration).definition);
        }
      }
      declarations = code.scope().keysOfType(Declaration.class).stream().sorted().collect(toList());
    }
  }
661054
public function getLocaleByCode($code)
    {
        $locales = $this->getLocales();
        if (array_key_exists($code, $locales)) {
            return $locales[$code];
        }
    }
1053634
public function arrayToClassElement($definition)
    {
        $class = new Classes();
        if (isset($definition['docblock'])) {
            $docblock = $this->arrayToDocblockElement($definition['docblock']);
            $class->setDocbloc($docblock);
        }
        if (isset($definition['namespace'])) {
            $class->setNamespace($definition['namespace']);
        }
        if (isset($definition['name'])) {
            $class->setName($definition['name']);
        }
        if (isset($definition['extends'])) {
           $class->setExtends($definition['extends']);
        }
        if (isset($definition['implements'])) {
            foreach ($definition['implements'] as $interface) {
                $class->addImplements($interface);
            }
        }
        if (isset($definition['uses'])) {
            foreach ($definition['uses'] as $alias => $use) {
                $alias = is_string($alias) ? $alias : null;
                $class->addUse($use, $alias);
            }
        }
        if (isset($definition['functions'])) {
            foreach ($definition['functions'] as $definition) {
                $function = $this->arrayToFunctionElement($definition);
                $class->addFunction($function);
            }
        }
        return $class;
    }
363430
public function scriptBlock($code, array $options = [])
    {
        $options = optionsParser($options, ['block' => true]);

        return parent::scriptBlock($code, $options->toArray());
    }
159048
public function addSideMenuItems($owner, $code, array $definitions)
    {
        foreach ($definitions as $sideCode => $definition) {
            $this->addSideMenuItem($owner, $code, $sideCode, (array) $definition);
        }
    }