Language.php 1.91 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php

/**
 * @file
 * Definition of Drupal\Core\Language\Language.
 */

namespace Drupal\Core\Language;

/**
 * An object containing the information for an interface language.
 *
 * @todo To keep backwards compatibility with stdClass, we currently use
 * public scopes for the Language class's variables. We will change these to
 * full get/set functions in a follow-up issue: http://drupal.org/node/1512424
 *
 * @see language_default()
 */
class Language {
  // Properties within the Language are set up as the default language.
21
22
23
  public $name = '';
  public $langcode = '';
  public $direction = LANGUAGE_LTR;
24
25
26
  public $weight = 0;
  public $default = FALSE;
  public $method_id = NULL;
27
  public $locked = FALSE;
28
29
30
31
32
33
34
35

  /**
   * Language constructor builds the default language object.
   *
   * @param array $options
   *   The properties used to construct the language.
   */
  public function __construct(array $options = array()) {
36
    // Set all the provided properties for the language.
37
38
39
    foreach ($options as $name => $value) {
      $this->$name = $value;
    }
40
41
42
43
44
45
46
47
48
49
50
51
52
    // If some options were not set, set sane defaults of a predefined language.
    if (!isset($options['name']) || !isset($options['direction'])) {
      include_once DRUPAL_ROOT . '/core/includes/standard.inc';
      $predefined = standard_language_list();
      if (isset($predefined[$this->langcode])) {
        if (!isset($options['name'])) {
          $this->name = $predefined[$this->langcode][0];
        }
        if (!isset($options['direction']) && isset($predefined[$this->langcode][2])) {
          $this->direction = $predefined[$this->langcode][2];
        }
      }
    }
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  }

  /**
   * Extend $this with properties from the given object.
   *
   * @todo Remove this function once $GLOBALS['language'] is gone.
   */
  public function extend($obj) {
    $vars = get_object_vars($obj);
    foreach ($vars as $var => $value) {
      $this->$var = $value;
    }
  }
}