@@ -80,33 +80,33 @@ |
||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | - * Method combines both [[setHasCache()]] and [[getHasCache()]] methods to retrieve value identified by a $key, |
|
| 84 | - * or to store the result of $closure execution if there is no cache available for the $key. |
|
| 85 | - * |
|
| 86 | - * Usage example: |
|
| 87 | - * |
|
| 88 | - * ```php |
|
| 89 | - * use CacheableTrait; |
|
| 90 | - * |
|
| 91 | - * public function getTopProducts($count = 10) |
|
| 92 | - * { |
|
| 93 | - * return $this->getOrSetHasCache(['top-n-products', 'n' => $count], function ($cache) use ($count) { |
|
| 94 | - * return Products::find()->mostPopular()->limit(10)->all(); |
|
| 95 | - * }, 1000); |
|
| 96 | - * } |
|
| 97 | - * ``` |
|
| 98 | - * |
|
| 99 | - * @param mixed $key a key identifying the value to be cached. This can be a simple string or |
|
| 100 | - * a complex data structure consisting of factors representing the key. |
|
| 101 | - * @param \Closure $closure the closure that will be used to generate a value to be cached. |
|
| 102 | - * In case $closure returns `false`, the value will not be cached. |
|
| 103 | - * @param int $duration default duration in seconds before the cache will expire. If not set, |
|
| 104 | - * [[defaultDuration]] value will be used. |
|
| 105 | - * @param Dependency $dependency dependency of the cached item. If the dependency changes, |
|
| 106 | - * the corresponding value in the cache will be invalidated when it is fetched via [[get()]]. |
|
| 107 | - * This parameter is ignored if [[serializer]] is `false`. |
|
| 108 | - * @return mixed result of $closure execution |
|
| 109 | - */ |
|
| 83 | + * Method combines both [[setHasCache()]] and [[getHasCache()]] methods to retrieve value identified by a $key, |
|
| 84 | + * or to store the result of $closure execution if there is no cache available for the $key. |
|
| 85 | + * |
|
| 86 | + * Usage example: |
|
| 87 | + * |
|
| 88 | + * ```php |
|
| 89 | + * use CacheableTrait; |
|
| 90 | + * |
|
| 91 | + * public function getTopProducts($count = 10) |
|
| 92 | + * { |
|
| 93 | + * return $this->getOrSetHasCache(['top-n-products', 'n' => $count], function ($cache) use ($count) { |
|
| 94 | + * return Products::find()->mostPopular()->limit(10)->all(); |
|
| 95 | + * }, 1000); |
|
| 96 | + * } |
|
| 97 | + * ``` |
|
| 98 | + * |
|
| 99 | + * @param mixed $key a key identifying the value to be cached. This can be a simple string or |
|
| 100 | + * a complex data structure consisting of factors representing the key. |
|
| 101 | + * @param \Closure $closure the closure that will be used to generate a value to be cached. |
|
| 102 | + * In case $closure returns `false`, the value will not be cached. |
|
| 103 | + * @param int $duration default duration in seconds before the cache will expire. If not set, |
|
| 104 | + * [[defaultDuration]] value will be used. |
|
| 105 | + * @param Dependency $dependency dependency of the cached item. If the dependency changes, |
|
| 106 | + * the corresponding value in the cache will be invalidated when it is fetched via [[get()]]. |
|
| 107 | + * This parameter is ignored if [[serializer]] is `false`. |
|
| 108 | + * @return mixed result of $closure execution |
|
| 109 | + */ |
|
| 110 | 110 | public function getOrSetHasCache($key, \Closure $closure, $duration = null, $dependency = null) |
| 111 | 111 | { |
| 112 | 112 | if (($value = $this->getHasCache($key)) !== false) { |
@@ -74,7 +74,7 @@ |
||
| 74 | 74 | if (is_file($file)) { |
| 75 | 75 | $phpCode = file_get_contents($file); |
| 76 | 76 | } else { |
| 77 | - $phpCode = $file; |
|
| 77 | + $phpCode = $file; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | $namespace = false; |
@@ -29,38 +29,38 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class Encode extends Behavior |
| 31 | 31 | { |
| 32 | - public $attributes = []; |
|
| 32 | + public $attributes = []; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @inheritdoc |
|
| 36 | - */ |
|
| 37 | - public function events() |
|
| 38 | - { |
|
| 39 | - return [ |
|
| 40 | - ActiveRecord::EVENT_AFTER_FIND => 'afterFind', |
|
| 41 | - ]; |
|
| 42 | - } |
|
| 34 | + /** |
|
| 35 | + * @inheritdoc |
|
| 36 | + */ |
|
| 37 | + public function events() |
|
| 38 | + { |
|
| 39 | + return [ |
|
| 40 | + ActiveRecord::EVENT_AFTER_FIND => 'afterFind', |
|
| 41 | + ]; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Event will be triggered after find. |
|
| 46 | - * |
|
| 47 | - * @param \yii\base\Event $event The after find event. |
|
| 48 | - */ |
|
| 49 | - public function afterFind($event) |
|
| 50 | - { |
|
| 51 | - foreach ($this->attributes as $attribute) { |
|
| 52 | - $this->owner->{$attribute} = $this->encodeValue($this->owner->{$attribute}); |
|
| 53 | - } |
|
| 54 | - } |
|
| 44 | + /** |
|
| 45 | + * Event will be triggered after find. |
|
| 46 | + * |
|
| 47 | + * @param \yii\base\Event $event The after find event. |
|
| 48 | + */ |
|
| 49 | + public function afterFind($event) |
|
| 50 | + { |
|
| 51 | + foreach ($this->attributes as $attribute) { |
|
| 52 | + $this->owner->{$attribute} = $this->encodeValue($this->owner->{$attribute}); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Encodes the given value based on {{luya\helpers\Html::encode()}}. |
|
| 58 | - * |
|
| 59 | - * @param string $value The value which should be encoded. |
|
| 60 | - * @return string Returns the encoded value. |
|
| 61 | - */ |
|
| 62 | - public function encodeValue($value) |
|
| 63 | - { |
|
| 64 | - return Html::encode($value); |
|
| 65 | - } |
|
| 56 | + /** |
|
| 57 | + * Encodes the given value based on {{luya\helpers\Html::encode()}}. |
|
| 58 | + * |
|
| 59 | + * @param string $value The value which should be encoded. |
|
| 60 | + * @return string Returns the encoded value. |
|
| 61 | + */ |
|
| 62 | + public function encodeValue($value) |
|
| 63 | + { |
|
| 64 | + return Html::encode($value); |
|
| 65 | + } |
|
| 66 | 66 | } |
| 67 | 67 | \ No newline at end of file |