| 1 | <?php |
||
| 19 | trait TranslatedTrait |
||
| 20 | { |
||
| 21 | 4 | public function transactions() |
|
| 22 | { |
||
| 23 | return [ |
||
| 24 | 4 | ActiveRecord::SCENARIO_DEFAULT => ActiveRecord::OP_ALL, |
|
| 25 | 4 | ]; |
|
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param string $language |
||
| 30 | * @return bool |
||
| 31 | */ |
||
| 32 | 2 | public function hasTranslate($language) |
|
| 36 | |||
| 37 | /** |
||
| 38 | * Returns a value indicating whether the named attribute has been changed |
||
| 39 | * or attribute has been changed in translation relation model. |
||
| 40 | * @param string $name the name of the attribute. |
||
| 41 | * @param boolean $identical whether the comparison of new and old value is made for |
||
| 42 | * identical values using `===`, defaults to `true`. Otherwise `==` is used for comparison. |
||
| 43 | * @return boolean whether the attribute has been changed |
||
| 44 | */ |
||
| 45 | 1 | public function isAttributeChanged($name, $identical = true) |
|
| 53 | } |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.