Commit 7d1e0122 authored by jaredsmith's avatar jaredsmith

Add objects for Country and Locale per reqest in d.o issue 2571387

parent 1218a249
<?php
/**
* @file
* Contains \Drupal\commerce\Country
*/
namespace Drupal\commerce;
/**
* Represents a country.
*/
final class Country {
/**
* Two-letter country code.
*
* @var string
*/
protected $countryCode;
/**
* Constructs a new Country object.
*
* @param string $countryCode
* The country code.
*/
public function __construct($countryCode) {
$this->countryCode = strtoupper($countryCode);
}
/**
* Gets the country code.
*
* @return string
*/
public function getCountryCode() {
return $this->countryCode;
}
/**
* Gets the string representation of the country.
*
* @return string
*/
public function __toString() {
return $this->countryCode;
}
}
......@@ -17,7 +17,7 @@ interface CountryContextInterface {
/**
* Gets the country for the current request.
*
* @return \Drupal\commerce\CountryInterface
* @return \Drupal\commerce\Country
*/
public function getCountry();
......
<?php
/**
* @file
* Contains \Drupal\commerce\Locale
*/
namespace Drupal\commerce;
/**
* Represents a locale.
*/
final class Locale {
/**
* The locale
*
* @var string
*/
protected $localeCode;
/**
* Constructs a new Locale object.
*
* @param string $localeCode
* The locale code.
*/
public function __construct($localeCode) {
$this->localeCode = strtoupper($localeCode);
}
/**
* Gets the locale code.
*
* @return string
*/
public function getLocaleCode() {
return $this->localeCode;
}
/**
* Gets the string representation of the locale.
*
* @return string
*/
public function __toString() {
return $this->localeCode;
}
}
......@@ -17,7 +17,7 @@ interface LocaleContextInterface {
/**
* Gets the locale for the current request.
*
* @return \Drupal\commerce\LocaleInterface
* @return \Drupal\commerce\Locale
*/
public function getLocale();
......
......@@ -15,8 +15,8 @@ interface CountryResolverInterface {
/**
* Resolves the country.
*
* @return string|null
* The country, if resolved. Otherwise NULL, indicating that the next
* @return \Drupal\commerce\Country|null
* The country object, if resolved. Otherwise NULL, indicating that the next
* resolver in the chain should be called.
*/
public function resolve();
......
......@@ -8,6 +8,7 @@
namespace Drupal\commerce\Resolver;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\commerce\Country;
/**
* Returns the site's default country.
......@@ -35,7 +36,8 @@ class DefaultCountryResolver implements CountryResolverInterface {
* {@inheritdoc}
*/
public function resolve() {
return $this->configFactory->get('system.date')->get('country.default');
$countryCode = $this->configFactory->get('system.date')->get('country.default');
return new Country($countryCode);
}
}
......@@ -8,6 +8,7 @@
namespace Drupal\commerce\Resolver;
use Drupal\commerce\CountryContextInterface;
use Drupal\commerce\Locale;
use Drupal\Core\Language\LanguageManagerInterface;
/**
......@@ -64,7 +65,7 @@ class DefaultLocaleResolver implements LocaleResolverInterface {
$locale = $language;
}
return $locale;
return new Locale($locale);
}
}
......@@ -15,8 +15,8 @@ interface LocaleResolverInterface {
/**
* Resolves the locale.
*
* @return string|null
* The locale, if resolved. Otherwise NULL, indicating that the next
* @return \Drupal\commerce\Locale|null
* The locale object, if resolved. Otherwise NULL, indicating that the next
* resolver in the chain should be called.
*/
public function resolve();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment