1 | <?php |
||
38 | class DbMessageSource extends MessageSource |
||
39 | { |
||
40 | /** |
||
41 | * Prefix which would be used when generating cache key. |
||
42 | * @deprecated This constant has never been used and will be removed in 2.1.0. |
||
43 | */ |
||
44 | const CACHE_KEY_PREFIX = 'DbMessageSource'; |
||
45 | |||
46 | /** |
||
47 | * @var Connection|array|string the DB connection object or the application component ID of the DB connection. |
||
48 | * |
||
49 | * After the DbMessageSource object is created, if you want to change this property, you should only assign |
||
50 | * it with a DB connection object. |
||
51 | * |
||
52 | * Starting from version 2.0.2, this can also be a configuration array for creating the object. |
||
53 | */ |
||
54 | public $db = 'db'; |
||
55 | /** |
||
56 | * @var Cache|array|string the cache object or the application component ID of the cache object. |
||
57 | * The messages data will be cached using this cache object. |
||
58 | * Note, that to enable caching you have to set [[enableCaching]] to `true`, otherwise setting this property has no effect. |
||
59 | * |
||
60 | * After the DbMessageSource object is created, if you want to change this property, you should only assign |
||
61 | * it with a cache object. |
||
62 | * |
||
63 | * Starting from version 2.0.2, this can also be a configuration array for creating the object. |
||
64 | * @see cachingDuration |
||
65 | * @see enableCaching |
||
66 | */ |
||
67 | public $cache = 'cache'; |
||
68 | /** |
||
69 | * @var string the name of the source message table. |
||
70 | */ |
||
71 | public $sourceMessageTable = '{{%source_message}}'; |
||
72 | /** |
||
73 | * @var string the name of the translated message table. |
||
74 | */ |
||
75 | public $messageTable = '{{%message}}'; |
||
76 | /** |
||
77 | * @var integer the time in seconds that the messages can remain valid in cache. |
||
78 | * Use 0 to indicate that the cached data will never expire. |
||
79 | * @see enableCaching |
||
80 | */ |
||
81 | public $cachingDuration = 0; |
||
82 | /** |
||
83 | * @var boolean whether to enable caching translated messages |
||
84 | */ |
||
85 | public $enableCaching = false; |
||
86 | |||
87 | |||
88 | /** |
||
89 | * Initializes the DbMessageSource component. |
||
90 | * This method will initialize the [[db]] property to make sure it refers to a valid DB connection. |
||
91 | * Configured [[cache]] component would also be initialized. |
||
92 | * @throws InvalidConfigException if [[db]] is invalid or [[cache]] is invalid. |
||
93 | */ |
||
94 | 10 | public function init() |
|
102 | |||
103 | /** |
||
104 | * Loads the message translation for the specified language and category. |
||
105 | * If translation for specific locale code such as `en-US` isn't found it |
||
106 | * tries more generic `en`. |
||
107 | * |
||
108 | * @param string $category the message category |
||
109 | * @param string $language the target language |
||
110 | * @return array the loaded messages. The keys are original messages, and the values |
||
111 | * are translated messages. |
||
112 | */ |
||
113 | 6 | protected function loadMessages($category, $language) |
|
132 | |||
133 | /** |
||
134 | * Loads the messages from database. |
||
135 | * You may override this method to customize the message storage in the database. |
||
136 | * @param string $category the message category. |
||
137 | * @param string $language the target language. |
||
138 | * @return array the messages loaded from database. |
||
139 | */ |
||
140 | 6 | protected function loadMessagesFromDb($category, $language) |
|
163 | |||
164 | /** |
||
165 | * The method builds the [[Query]] object for the fallback language messages search. |
||
166 | * Normally is called from [[loadMessagesFromDb]]. |
||
167 | * |
||
168 | * @param string $category the message category |
||
169 | * @param string $language the originally requested language |
||
170 | * @param string $fallbackLanguage the target fallback language |
||
171 | * @return Query |
||
172 | * @see loadMessagesFromDb |
||
173 | * @since 2.0.7 |
||
174 | */ |
||
175 | 4 | protected function createFallbackQuery($category, $language, $fallbackLanguage) |
|
187 | } |
||
188 |