private function ensureNumber($number) { if (!StringHelper::startsWith($number, '+')) { $number = '+' . $number; } return str_replace(" ", "", $number); }
/** * Setter method for $blockName, ensure the correct block name. * * @param string $name The name of the block. */ public function setBlockName($name) { if (!StringHelper::endsWith($name, 'Block')) { $name .= 'Block'; } $this->_blockName = Inflector::camelize($name); }
public function onAfterListFind($event) { $value = StringHelper::typeCast($event->sender->getAttribute($this->name)); foreach ($this->data as $item) { if ($item['value'] === $value) { $event->sender->setAttribute($this->name, $item['label']); } } }
public function testArrayStrictContains() { $this->assertTrue(StringHelper::contains(['foo', 'bar'], 'hello foo bar', true)); // enabled $strict mode $this->assertFalse(StringHelper::contains(['notexistings', 'bar'], 'hello bar foo', true)); // enabled $strict mode $this->assertFalse(StringHelper::contains(['bar', 'notexistings'], 'hello bar foo', true)); // enabled $strict mode $this->assertFalse(StringHelper::contains(['notexistings'], 'hello bar foo', true)); // enabled strict mode $this->assertTrue(StringHelper::contains(['a', 'b', 'c'], 'thesmallabc', true)); }
/** * 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 static function addToIndex($url, $title = null, $urlFoundOnPage = null) { $model = self::findOne(['url' => $url]); if ($model) { return false; } $model = new self(); $model->url = $url; $model->title = StringHelper::truncate($title, 197); $model->url_found_on_page = $urlFoundOnPage; $model->crawled = 0; return $model->save(false); }
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 getLinks() { try { $crawler = $this->getCrawler(); if (!$crawler) { return []; } $links = $crawler->filterXPath('//a')->each(function ($node, $i) { return $node->extract(array('_text', 'href'))[0]; }); foreach ($links as $key => $item) { if (StringHelper::contains(['@'], $item[1])) { unset($links[$key]); continue; } $url = parse_url($item[1]); if (!isset($url['host']) || !isset($url['scheme'])) { $base = $this->baseHost; } else { $base = $url['scheme'] . '://' . $url['host']; } $path = null; if (isset($url['path'])) { $path = $url['path']; } $url = rtrim($base, "/") . "/" . ltrim($path, "/"); $links[$key][0] = self::cleanupString($links[$key][0]); $links[$key][1] = http_build_url($url, ['query' => isset($host['query']) ? $host['query'] : []], HTTP_URL_JOIN_QUERY | HTTP_URL_STRIP_FRAGMENT); } return $links; } catch (\Exception $e) { return []; } }
public function onAfterListFind($event) { $value = $event->sender->getAttribute($this->name); if (!$this->i18n) { $value = $this->jsonDecode($value); } $value = StringHelper::typeCast($value); if (!empty($value)) { $results = []; foreach ($this->getItems()['items'] as $item) { foreach ($value as $k => $v) { if (isset($v['value']) && $item['value'] === $v['value']) { $results[] = $item['label']; } } } $event->sender->setAttribute($this->name, implode(", ", $results)); } }