protected function getCleanStringValue($key) { $d = new Decorator(); $value = $this->get($key); $string = $d->stripIgnoredCharacters($value); if ($this->getStopwords()) { return $d->stripStopwords($string, $this->getStopwords()); } return $string; }
/** * Add a decorator to the element. * * @param Decorator|string $decorator Decorator object or name * @param mixed $_ Additional arguments are passed to the constructor * @return Element $this */ public function addDecorator($decorator) { // parent::addDecorator($decorator, ...$_); call_user_func_array([get_parent_class(), 'addDecorator'], func_get_args()); foreach ($this->getChildren() as $child) { if ($this->getOption('decorate') === false) { continue; } $decorator->apply($child, true); } return $this; }
/** * {@inheritdoc} * * @throws \InvalidArgumentException */ public function inject($originalValue) { if (!$this->supports($originalValue)) { throw new \InvalidArgumentException('You must provide a resource as the original value to use a ResourceDecorator'); } parent::inject($originalValue); }
/** * {@inheritdoc} * * @throws \InvalidArgumentException */ public function inject($originalValue) { if (!$this->supports($originalValue)) { throw new \InvalidArgumentException('You must provide an object as the original value to use an ObjectDecorator'); } return parent::inject($originalValue); }
public function operate() { parent::operate(); //调用装饰类的操作 $this->extraOperate(); //新增加的操作 }
function readAncodes($info) { $offset = $info['offset']; if (isset($this->cache[$offset])) { $this->hits++; return $this->cache[$offset]; } else { // in theory misses never occur $this->miss++; return parent::readAncodes($info); } }
public function render() { $stato = isset($this->model->result['stato']) ? $this->model->result['stato'] : null; $data_ora = isset($this->model->result['data_ora']) ? $this->model->result['data_ora'] : 'now'; $dec = new Decorator(); $updated = $dec->decorateDateTime($data_ora); if ($stato === true) { $classes = 'fa fa-fire status on'; $title = 'title-status-on'; } else { if ($stato === false) { $classes = 'fa fa-fire status off'; $title = 'title-status-off'; } else { $classes = 'fa fa-exclamation-circle status undefined'; $title = 'title-status-unknow'; } } $result = (object) ['result' => $stato, 'classes' => $classes, 'title' => $title, 'updated' => $updated]; return json_encode($result, JSON_NUMERIC_CHECK); }
public function Operation() { return '<B>' . parent::Operation() . '</B>'; }
public function operation() { return parent::operation() . ' - ' . $this->addedState; }
public function operation() { return parent::operation() . ' - ' . $this->addedBehavior(); }
public function Operation() { return '<a href="#">' . parent::Operation() . '</a>'; }
protected function getCleanStringValue($key) { $d = new Decorator(); $value = $this->get($key); return $d->onlyNumbers($value); }
/** * Выполняет загрузку модуля по его названию * * @param string $sModuleClass Класс модуля * @param bool $bInit Инициализировать модуль или нет * * @throws RuntimeException если класс $sModuleClass не существует * * @return Module */ public function LoadModule($sModuleClass, $bInit = false) { $tm1 = microtime(true); if (!class_exists($sModuleClass)) { throw new RuntimeException(sprintf('Class "%s" not found!', $sModuleClass)); } // * Создаем объект модуля $oModule = new $sModuleClass(); $oModuleDecorator = Decorator::Create($oModule); $this->aModules[$sModuleClass] = $oModuleDecorator; if ($bInit || $sModuleClass == 'ModuleCache') { $this->InitModule($oModuleDecorator); } $tm2 = microtime(true); $this->nTimeLoadModule += $tm2 - $tm1; return $oModuleDecorator; }
public function testDecorator() { $component = new ConcreteComponent(); $decorator = new Decorator($component); $decorator->operate(); }
public function render() { $dcr = new Decorator(); return json_encode(['temperature-value' => $dcr->decorateTemperature($this->model->temperatura), 'humidity-value' => $dcr->decorateUmidity($this->model->umidita), 'last-update' => $dcr->decorateDateTime($this->model->ultimo_aggiornamento)], JSON_FORCE_OBJECT | JSON_HEX_QUOT | JSON_HEX_TAG); }
/** * @see Base */ public function __construct($string, $options = array(), $messages = array()) { $this->string = $string; $this->tokens = $this->tokenize($string); parent::__construct($options, $messages); }
public function render() { $dec = new Decorator(); $updated = $dec->decorateDateTime('now'); return json_encode((object) ['points' => $this->model->getData(), 'updated' => $updated], JSON_NUMERIC_CHECK); }
function __construct($f) { parent::__construct($f); $this->getImageSize(); }
function __construct($file, array $styles = array("thumb" => "100x100")) { parent::__construct($file); $this->styles = preg_grep("/\\d+x\\d+/", $styles); }
function __construct($component) { parent::__construct($component); }
public function operation() { parent::operation(); $this->Addbehavior(); var_dump('具体装饰对象B的操作'); }
public function operation() { parent::operation(); $this->addedOperationB(); }
<?php /** * Copyright (c) 2014 Keith Casey * * This code is designed to accompany the lynda.com video course "Design Patterns in PHP" * by Keith Casey. If you've received this code without seeing the videos, go watch the * videos. It will make way more sense and be more useful in general. */ include_once 'decorator.php'; $object = new Decorator(); $object->sentence = "This is a sample sentence that we're going to manipulate in the Decorator."; // This should output: this is a sample sentence that we're going to manipulate in the decorator. echo $object->lower(); // This should output: THIS IS A SAMPLE SENTENCE THAT WE'RE GOING TO MANIPULATE IN THE DECORATOR. echo $object->uppercase();
/** * Write all messages from stack. */ public function writeAll() { while ($message = array_shift($this->stack)) { parent::writeln($message[0], $message[1]); } }
public function testSpecialPlaceholder() { $context = new Context('name', 'id'); $decorator = new Decorator(); $decorator->context($context); }
public function Operation() { return 'B :' . parent::Operation(); }
public function Operation() { return '<strong>' . parent::Operation() . '</strong>'; }
/** * @param RenderInterface $wrapable * @param $width * @param $color */ public function __construct($wrapable, $width, $color) { parent::__construct($wrapable); $this->width = $width; $this->color = $color; }
/** * Render the row * * @param array $columnWidths Width of all columns * @param \Zend\Text\Table\Decorator $decorator Decorator for the row borders * @param integer $padding Padding for the columns * @throws \Zend\Text\Table\Exception\OverflowException When there are too many columns * @return string */ public function render(array $columnWidths, Decorator $decorator, $padding = 0) { // Prepare an array to store all column widths $this->_columnWidths = array(); // If there is no single column, create a column which spans over the // entire row if (count($this->_columns) === 0) { $this->appendColumn(new Column(null, null, count($columnWidths))); } // First we have to render all columns, to get the maximum height $renderedColumns = array(); $maxHeight = 0; $colNum = 0; foreach ($this->_columns as $column) { // Get the colspan of the column $colSpan = $column->getColSpan(); // Verify if there are enough column widths defined if ($colNum + $colSpan > count($columnWidths)) { throw new Exception\OverflowException('Too many columns'); } // Calculate the column width $columnWidth = $colSpan - 1 + array_sum(array_slice($columnWidths, $colNum, $colSpan)); // Render the column and split it's lines into an array $result = explode("\n", $column->render($columnWidth, $padding)); // Store the width of the rendered column $this->_columnWidths[] = $columnWidth; // Store the rendered column and calculate the new max height $renderedColumns[] = $result; $maxHeight = max($maxHeight, count($result)); // Set up the internal column number $colNum += $colSpan; } // If the row doesnt contain enough columns to fill the entire row, fill // it with an empty column if ($colNum < count($columnWidths)) { $remainingWidth = count($columnWidths) - $colNum - 1 + array_sum(array_slice($columnWidths, $colNum)); $renderedColumns[] = array(str_repeat(' ', $remainingWidth)); $this->_columnWidths[] = $remainingWidth; } // Add each single column line to the result $result = ''; for ($line = 0; $line < $maxHeight; $line++) { $result .= $decorator->getVertical(); foreach ($renderedColumns as $renderedColumn) { if (isset($renderedColumn[$line]) === true) { $result .= $renderedColumn[$line]; } else { $result .= str_repeat(' ', strlen($renderedColumn[0])); } $result .= $decorator->getVertical(); } $result .= "\n"; } return $result; }
public function render() { $dcr = new Decorator(); return json_encode((object) ['dettaglio' => $this->model->dettaglio, 'temp_antigelo' => $this->model->antigelo, 'temperature' => $this->model->temperature, 'temp_riferimento' => $this->encodeHtml($this->model), 'temp_rif_att' => $dcr->decorateTemperature($this->model->rif_temp_attuale)]); }