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