/
TranslateStrategyInterface.php
118 lines (108 loc) · 4.3 KB
/
TranslateStrategyInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
declare(strict_types=1);
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 4.0.0
* @license https://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\ORM\Behavior\Translate;
use ArrayObject;
use Cake\Collection\CollectionInterface;
use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\ORM\PropertyMarshalInterface;
use Cake\ORM\Query;
use Cake\ORM\Table;
/**
* This interface describes the methods for translate behavior strategies.
*/
interface TranslateStrategyInterface extends PropertyMarshalInterface
{
/**
* Return translation table instance.
*
* @return \Cake\ORM\Table
*/
public function getTranslationTable(): Table;
/**
* Sets the locale to be used.
*
* When fetching records, the content for the locale set via this method,
* and likewise when saving data, it will save the data in that locale.
*
* Note that in case an entity has a `_locale` property set, that locale
* will win over the locale set via this method (and over the globally
* configured one for that matter)!
*
* @param string|null $locale The locale to use for fetching and saving
* records. Pass `null` in order to unset the current locale, and to make
* the behavior fall back to using the globally configured locale.
* @return $this
*/
public function setLocale(?string $locale);
/**
* Returns the current locale.
*
* If no locale has been explicitly set via `setLocale()`, this method will
* return the currently configured global locale.
*
* @return string
*/
public function getLocale(): string;
/**
* Returns a fully aliased field name for translated fields.
*
* If the requested field is configured as a translation field, field with
* an alias of a corresponding association is returned. Table-aliased
* field name is returned for all other fields.
*
* @param string $field Field name to be aliased.
* @return string
*/
public function translationField(string $field): string;
/**
* Modifies the results from a table find in order to merge full translation records
* into each entity under the `_translations` key
*
* @param \Cake\Datasource\ResultSetInterface $results Results to modify.
* @return \Cake\Collection\CollectionInterface
*/
public function groupTranslations($results): CollectionInterface;
/**
* Callback method that listens to the `beforeFind` event in the bound
* table. It modifies the passed query by eager loading the translated fields
* and adding a formatter to copy the values into the main table records.
*
* @param \Cake\Event\EventInterface $event The beforeFind event that was fired.
* @param \Cake\ORM\Query $query Query
* @param \ArrayObject $options The options for the query
* @return void
*/
public function beforeFind(EventInterface $event, Query $query, ArrayObject $options);
/**
* Modifies the entity before it is saved so that translated fields are persisted
* in the database too.
*
* @param \Cake\Event\EventInterface $event The beforeSave event that was fired
* @param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved
* @param \ArrayObject $options the options passed to the save method
* @return void
*/
public function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options);
/**
* Unsets the temporary `_i18n` property after the entity has been saved
*
* @param \Cake\Event\EventInterface $event The beforeSave event that was fired
* @param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved
* @return void
*/
public function afterSave(EventInterface $event, EntityInterface $entity);
}