Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21namespace Wikimedia\Bcp47Code;
22
23/**
24 * This interface defines an opaque object representing a language.
25 * The language can return a standardized IETF BCP 47 language tag
26 * representing itself.
27 *
28 * It is recommended that the internal language class in your code
29 * implement the Bcp47Code interface, and that you provide a mechanism
30 * that will accept a Bcp47Code and return an appropriate instance of
31 * your internal language code.
32 *
33 * For example:
34 * <pre>
35 * use Wikimedia\Bcp47Code\Bcp47Code;
36 *
37 * class MyLanguage implements Bcp47Code {
38 *    public function toBcp47Code(): string {
39 *      return $this->code;
40 *    }
41 *    public static function fromBcp47(Bcp47Code $code): MyLanguage {
42 *      if ($code instanceof MyLanguage) {
43 *         return $code;
44 *      }
45 *      return new MyLanguage($code->toBcp47Code());
46 *    }
47 *    public function isSameCodeAs( Bcp47Code $other ): bool {
48 *      if ( $other instanceof MyLanguage ) {
49 *         // implement optimized MyLanguage-specific comparison
50 *      }
51 *      return strcasecmp( $this->toBcp47Code(), $other->toBcp47Code() ) === 0;
52 *    }
53 * }
54 * </pre>
55 */
56interface Bcp47Code {
57
58    /**
59     * @return string a standardized IETF BCP 47 language tag
60     */
61    public function toBcp47Code(): string;
62
63    /**
64     * Compare two Bcp47Code objects.  Note that BCP 47 codes are case
65     * insensitive, so if this comparison is going to use ::toBcp47Code()
66     * ensure the comparison is case insensitive.
67     *
68     * @param Bcp47Code $other The language tag to compare to
69     * @return bool true if this language tag is the same as the given one
70     */
71    public function isSameCodeAs( Bcp47Code $other ): bool;
72}