CommerceGuys\Addressing\Formatter\DefaultFormatter::setOption PHP Method

setOption() public method

public setOption ( $key, $value )
    public function setOption($key, $value)
    {
        if (!array_key_exists($key, $this->getDefaultOptions())) {
            throw new \InvalidArgumentException(sprintf('Invalid option "%s".', $key));
        }
        $this->options[$key] = $value;
        return $this;
    }

Usage Example

Example #1
0
 /**
  * Format an address
  *
  * @param AddressInterface $address
  * @param null $locale
  * @param bool $html
  * @param string $htmlTag
  * @param array $htmlAttributes
  * @return string
  */
 public function format(AddressInterface $address, $locale = null, $html = true, $htmlTag = "p", $htmlAttributes = [])
 {
     $locale = $this->normalizeLocale($locale);
     $addressFormatRepository = new AddressFormatRepository();
     $countryRepository = new CountryRepository();
     $subdivisionRepository = new SubdivisionRepository();
     $formatter = new DefaultFormatter($addressFormatRepository, $countryRepository, $subdivisionRepository, $locale);
     $formatter->setOption('html', $html);
     $formatter->setOption('html_tag', $htmlTag);
     $formatter->setOption('html_attributes', $htmlAttributes);
     $addressFormatted = $formatter->format($address);
     return $addressFormatted;
 }
All Usage Examples Of CommerceGuys\Addressing\Formatter\DefaultFormatter::setOption