/** * Generate the Link Tag. * * @param string $value The Brackets value `[]`. * @param string $sub The optional Parentheses value `()` * @see \luya\tag\TagInterface::parse() * @return string The parser tag. */ public function parse($value, $sub) { if (substr($value, 0, 2) == '//') { $value = StringHelper::replaceFirst('//', Url::base(true) . '/', $value); $external = false; } else { $external = true; } $value = Url::ensureHttp($value); $label = empty($sub) ? $value : $sub; return Html::a($label, $value, ['class' => $external ? 'link-external' : 'link-internal', 'target' => $external ? '_blank' : null]); }
public function actionClasses() { if (Config::has('rc1_block_classes_renameing')) { return $this->outputError("You already have run the classes updater, so your system should be up-to-date already."); } foreach (Block::find()->all() as $block) { $ns = $block->class; foreach ($this->_classMapping as $old => $new) { if (StringHelper::startsWith($ns, $old)) { $this->outputError('old: ' . $ns); $newNs = StringHelper::replaceFirst($old, $new, $ns); $block->updateAttributes(['class' => $newNs]); $this->outputSuccess('new: ' . $newNs); } } } Config::set('rc1_block_classes_renameing', true); return $this->outputSuccess('OK. You can now run the import command.'); }
public function testReplaceFirst() { $this->assertSame('abc 123 123', StringHelper::replaceFirst('123', 'abc', '123 123 123')); $this->assertSame('abc 123 ABC', StringHelper::replaceFirst('ABC', '123', 'abc ABC ABC')); }