123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace yii\base;
- trait DynamicContentAwareTrait
- {
-
- private $_dynamicPlaceholders;
-
- abstract protected function getView();
-
- public function getDynamicPlaceholders()
- {
- return $this->_dynamicPlaceholders;
- }
-
- public function setDynamicPlaceholders($placeholders)
- {
- $this->_dynamicPlaceholders = $placeholders;
- }
-
- public function addDynamicPlaceholder($name, $statements)
- {
- $this->_dynamicPlaceholders[$name] = $statements;
- }
-
- protected function updateDynamicContent($content, $placeholders, $isRestoredFromCache = false)
- {
- if (empty($placeholders) || !is_array($placeholders)) {
- return $content;
- }
- if (count($this->getView()->getDynamicContents()) === 0) {
-
- foreach ($placeholders as $name => $statements) {
- $placeholders[$name] = $this->getView()->evaluateDynamicContent($statements);
- }
- $content = strtr($content, $placeholders);
- }
- if ($isRestoredFromCache) {
- $view = $this->getView();
- foreach ($placeholders as $name => $statements) {
- $view->addDynamicPlaceholder($name, $statements);
- }
- }
- return $content;
- }
- }
|