1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?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;
- }
- }
|