1 <?php
2
3 /* --------------------------------------------------------------
4 LanguageCode.php 2015-12-15
5 Gambio GmbH
6 http://www.gambio.de
7 Copyright (c) 2015 Gambio GmbH
8 Released under the GNU General Public License (Version 2)
9 [http://www.gnu.org/licenses/gpl-2.0.html]
10 --------------------------------------------------------------
11 */
12
13 /**
14 * LanguageCode
15 *
16 * @category System
17 * @package Shared
18 */
19 class LanguageCode
20 {
21 /**
22 * Language code.
23 * @var string
24 */
25 protected $languageCode = '';
26
27
28 /**
29 * Class Constructor
30 *
31 * Validates the parameter and saves it to the property in uppercase format.
32 *
33 * @param StringType $code
34 *
35 * @throws InvalidArgumentException
36 */
37 public function __construct(StringType $code)
38 {
39 if(strlen($code->asString()) !== 2) // Argument must have 2 letters.
40 {
41 throw new InvalidArgumentException('$code must have exactly 2 letters');
42 }
43
44 $this->languageCode = strtoupper($code->asString());
45 }
46
47
48 /**
49 * Returns the language code.
50 * @return string
51 */
52 public function __toString()
53 {
54 return $this->languageCode;
55 }
56
57
58 /**
59 * As String
60 *
61 * Returns the language code as a string.
62 *
63 * @return string
64 */
65 public function asString()
66 {
67 return $this->languageCode;
68 }
69 }