当前位置: 首页>>代码示例>>PHP>>正文


PHP Strings::length方法代码示例

本文整理汇总了PHP中Nette\Utils\Strings::length方法的典型用法代码示例。如果您正苦于以下问题:PHP Strings::length方法的具体用法?PHP Strings::length怎么用?PHP Strings::length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nette\Utils\Strings的用法示例。


在下文中一共展示了Strings::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: findFulltext

 /**
  * @param string $query
  * @return \Nette\Database\Table\Selection
  */
 public function findFulltext($query)
 {
     if (strpos($query, ' ') !== FALSE) {
         $query = explode(' ', $query);
     } else {
         $query = array($query);
     }
     $result = $this->table()->where('document_state', 'public');
     // maybe, there will be some tags in the query, let's see
     $tags = [];
     foreach ($query as $keyword) {
         if (strpos($keyword, '#') === 0 and Strings::length($keyword) > 2) {
             // yes, this is a tag
             $tags[] = str_replace('#', '', $keyword);
         } elseif (strpos($keyword, '#') === FALSE) {
             // this is definitely not a tag
             $result->where('title LIKE ? OR content LIKE ? OR :article_tag.tag.name LIKE ?', array("%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%"));
         }
     }
     // if there are any tags, add them to the search conditions
     if (count($tags) > 0) {
         $result->where(':article_tag.tag.name IN ?', $tags);
         $result->group("article.id")->having("COUNT(DISTINCT :article_tag.tag.name) = ?", count($tags));
     }
     return $result;
 }
开发者ID:aprila,项目名称:app-knowledge-base,代码行数:30,代码来源:ArticleRepository.php

示例2: setTaskName

 /**
  * Sets name of current task.
  *
  * @param string|null $taskName
  */
 public function setTaskName($taskName = NULL)
 {
     if ($taskName !== NULL && (!$taskName || !is_string($taskName) || Strings::length($taskName) <= 0)) {
         throw new InvalidTaskNameException('Given task name is not valid.');
     }
     $this->taskName = $taskName;
 }
开发者ID:duskohu,项目名称:Cronner,代码行数:12,代码来源:FileStorage.php

示例3: validateLength

 /**
  * Length validator: is control's value length in range?
  *
  * @param  TextBase
  * @param  array  min and max length pair
  *
  * @return bool
  */
 public static function validateLength(TextBase $control, $range)
 {
     if (!is_array($range)) {
         $range = array($range, $range);
     }
     return Validators::isInRange(Strings::length($control->getValue()), $range);
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:15,代码来源:TextBase.php

示例4: createGrid

 protected function createGrid()
 {
     $grid = $this->createPreparedGrid();
     $grid->setModel($this->getModel());
     $grid->addColumnNumber('id', 'ID')->setSortable()->setFilterNumber();
     $grid->addColumnText('username', 'Přihlašovací jméno')->setSortable()->setDefaultSort('asc')->setFilterText();
     $grid->addColumnText('name', 'Jméno')->setSortable()->setFilterText();
     $grid->addColumnText('surname', 'Příjmení')->setSortable()->setFilterText();
     $grid->addColumnText('email', 'Email')->setCustomRender(function ($row) {
         if (Strings::length($row->email) <= 0) {
             return '';
         }
         return Html::el('a')->setText($row->email)->href('mailto:' . $row->email);
     })->setSortable()->setFilterText()->setColumn('user.email');
     $section = $grid->addColumnText('section', 'Sekce');
     $this->helpers->setupAsMultirecord($section, function ($row) {
         $selection = $this->sectionFacade->all();
         $this->userFilter->filterId($selection, $row->id, ':user_has_section');
         $selection->select("section.id,section.name");
         return $selection->fetchPairs('id', 'name');
     });
     $role = $grid->addColumnText('role', 'Role');
     $this->helpers->setupAsMultirecord($role, function ($row) {
         $selection = $this->roleFacade->all();
         $this->userFilter->filterId($selection, $row->id, ':user_has_role');
         $selection->select("role.code,role.name");
         return $selection->fetchPairs('code', 'name');
     });
     $this->helpers->addEditAction($grid);
     $this->helpers->addDeleteEvent($grid, $this->deleteRow, function ($row) {
         return $row->surname . ' ' . $row->name;
     });
     return $grid;
 }
开发者ID:kysela-petr,项目名称:generator-kysela,代码行数:34,代码来源:UserGrid.php

示例5: sanitize

 /**
  * Filter: removes unnecessary whitespace and shortens value to control's max length.
  *
  * @return string
  */
 public function sanitize($value)
 {
     if ($this->control->maxlength && Nette\Utils\Strings::length($value) > $this->control->maxlength) {
         $value = Nette\Utils\Strings::substring($value, 0, $this->control->maxlength);
     }
     return Nette\Utils\Strings::trim(strtr($value, "\r\n", '  '));
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:12,代码来源:TextInput.php

示例6: maybeReplacePlaceholderWithPrefix

 private function maybeReplacePlaceholderWithPrefix($key)
 {
     if (Strings::startsWith($key, self::PREFIX_PLACEHOLDER)) {
         return $this->dbPrefix . Strings::substring($key, Strings::length(self::PREFIX_PLACEHOLDER));
     }
     return $key;
 }
开发者ID:wp-cpm,项目名称:versionpress,代码行数:7,代码来源:UserMetaStorage.php

示例7: prepareTemplate

 protected function prepareTemplate($id)
 {
     $this->template->id = $id;
     $this->template->current = $this->action;
     if (Strings::length($id)) {
         $this->template->roleName = $this->getRoleName($id);
     }
 }
开发者ID:kysela-petr,项目名称:generator-kysela,代码行数:8,代码来源:RolePresenter.php

示例8: getTable

 /**
  * Model\Entity\SomeEntity -> some_entity
  * @param string $entityClass
  * @return string
  */
 public function getTable($entityClass)
 {
     if (Strings::endsWith($entityClass, 'y')) {
         return $this->camelToUnderdash(Strings::substring($this->trimNamespace($entityClass), 0, Strings::length($entityClass))) . 'ies';
     } else {
         return $this->camelToUnderdash($this->trimNamespace($entityClass)) . 's';
     }
 }
开发者ID:kizi,项目名称:easyminer-easyminercenter,代码行数:13,代码来源:StandardMapper.php

示例9: createTemplate

 /**
  * @return Template
  */
 public function createTemplate(UI\Control $control = NULL)
 {
     $latte = $this->latteFactory->create();
     $template = new Template($latte);
     $presenter = $control ? $control->getPresenter(FALSE) : NULL;
     if ($control instanceof UI\Presenter) {
         $latte->setLoader(new Loader($control));
     }
     if ($latte->onCompile instanceof \Traversable) {
         $latte->onCompile = iterator_to_array($latte->onCompile);
     }
     array_unshift($latte->onCompile, function ($latte) use($control, $template) {
         $latte->getParser()->shortNoEscape = TRUE;
         $latte->getCompiler()->addMacro('cache', new Nette\Bridges\CacheLatte\CacheMacro($latte->getCompiler()));
         UIMacros::install($latte->getCompiler());
         if (class_exists('Nette\\Bridges\\FormsLatte\\FormMacros')) {
             Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler());
         }
         if ($control) {
             $control->templatePrepareFilters($template);
         }
     });
     $latte->addFilter('url', 'rawurlencode');
     // back compatiblity
     foreach (array('normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse') as $name) {
         $latte->addFilter($name, 'Nette\\Utils\\Strings::' . $name);
     }
     $latte->addFilter('null', function () {
     });
     $latte->addFilter('length', function ($var) {
         return is_string($var) ? Nette\Utils\Strings::length($var) : count($var);
     });
     $latte->addFilter('modifyDate', function ($time, $delta, $unit = NULL) {
         return $time == NULL ? NULL : Nette\Utils\DateTime::from($time)->modify($delta . $unit);
         // intentionally ==
     });
     if (!array_key_exists('translate', $latte->getFilters())) {
         $latte->addFilter('translate', function () {
             throw new Nette\InvalidStateException('Translator has not been set. Set translator using $template->setTranslator().');
         });
     }
     // default parameters
     $template->control = $template->_control = $control;
     $template->presenter = $template->_presenter = $presenter;
     $template->user = $this->user;
     $template->netteHttpResponse = $this->httpResponse;
     $template->netteCacheStorage = $this->cacheStorage;
     $template->baseUri = $template->baseUrl = $this->httpRequest ? rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/') : NULL;
     $template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl);
     $template->flashes = array();
     if ($presenter instanceof UI\Presenter && $presenter->hasFlashSession()) {
         $id = $control->getParameterId('flash');
         $template->flashes = (array) $presenter->getFlashSession()->{$id};
     }
     return $template;
 }
开发者ID:knedle,项目名称:twitter-nette-skeleton,代码行数:59,代码来源:TemplateFactory.php

示例10: __invoke

 /**
  * Invoke filter
  *
  * @param string code
  * @param WebLoader loader
  * @param string file
  * @return string
  */
 public function __invoke($code, \Lohini\WebLoader\WebLoader $loader, $file = NULL)
 {
     $regexp = '/@charset ["\']utf\\-8["\'];(\\n)?/i';
     $removed = Strings::replace($code, $regexp);
     // At least one charset was in the code
     if (Strings::length($removed) < Strings::length($code)) {
         $code = self::CHARSET . "\n" . $removed;
     }
     return $code;
 }
开发者ID:lohini,项目名称:webloader,代码行数:18,代码来源:CssCharsetFilter.php

示例11: prepareFulltext

 /**
  * @param $queryString
  */
 public function prepareFulltext($queryString)
 {
     if (!$this->queryPrepared) {
         if (Strings::length($queryString) > 2) {
             $this->template->searchResults = $this->articleManager->findFulltext($queryString);
         } elseif (Strings::length($queryString) > 0) {
             $this->template->searchStatus = 'too-short';
         }
         $this->queryPrepared = TRUE;
     }
 }
开发者ID:JanTvrdik,项目名称:planette,代码行数:14,代码来源:SearchControl.php

示例12: encodePassword

 /**
  * Funkce pro symetrické zakódování hesla
  * @param string $password
  * @return string
  */
 public static function encodePassword($password)
 {
     $saltLength = Strings::length(self::PASSWORDS_SALT) - 1;
     $passwordsSalt = self::PASSWORDS_SALT . self::PASSWORDS_SALT . self::PASSWORDS_SALT;
     $randNumber = rand(1, $saltLength);
     $char = Strings::substring($passwordsSalt, $randNumber, 1);
     //získán náhodný znak ze soli
     $length = 12;
     $key = Strings::substring($passwordsSalt, $randNumber, $length);
     $encodedPassword = $char . $length . self::encrypt($password, $key);
     return $encodedPassword;
 }
开发者ID:kizi,项目名称:easyminer-easyminercenter,代码行数:17,代码来源:StringsHelper.php

示例13: renderDefault

 public function renderDefault($page = 1)
 {
     $empty = FALSE;
     $this->page = $page;
     $paginator = new Paginator();
     $paginator->setItemsPerPage(10);
     $paginator->setPage($this->page);
     if (!$this->user->isAllowed('Article', 'editAll')) {
         $count = $this->articleManager->getCount($this->user->id);
     } else {
         $count = $this->articleManager->getCount();
     }
     $paginator->setItemCount($count);
     if (Strings::length($this->q) >= 3) {
         $this->fulltextQuery = $this->q;
     }
     if ($this->fulltextQuery) {
         if (!$this->user->isAllowed('Article', 'editAll')) {
             $fulltextArticles = $this->articleManager->findFulltext($this->fulltextQuery)->fetchAll();
         } else {
             $fulltextArticles = $this->articleManager->findFulltext($this->fulltextQuery)->where('article.user_id', $this->user->id)->fetchAll();
         }
         if (!empty($fulltextArticles)) {
             $paginator->setItemCount(count($fulltextArticles));
             $fulltextPages = array_chunk($fulltextArticles, $paginator->itemsPerPage, true);
             $this->template->listOfArticles = $fulltextPages[$paginator->page - 1];
         } else {
             $paginator->setItemCount(0);
             $this->template->listOfArticles = array();
         }
     } else {
         if (!$this->user->isAllowed('Article', 'editAll')) {
             $this->template->listOfArticles = $this->articleManager->findAll()->where('article.user_id', $this->user->id)->limit($paginator->getLength(), $paginator->getOffset())->fetchAll();
         } else {
             $this->template->listOfArticles = $this->articleManager->findAll()->limit($paginator->getLength(), $paginator->getOffset())->fetchAll();
         }
         if (empty($this->template->listOfArticles)) {
             $empty = TRUE;
         }
     }
     $this->template->fulltextQuery = $this->q;
     $this->template->page = $this->page;
     $this->template->empty = $empty;
     if ($count > $paginator->itemsPerPage && !$paginator->last) {
         $this->template->showMoreButton = TRUE;
     }
     if ($this->ajax) {
         $this->redrawControl('datalistResult');
     }
 }
开发者ID:aprila,项目名称:app-knowledge-base,代码行数:50,代码来源:ArticlesPresenter.php

示例14: fetchThumbnail

 /**
  * Returns instance of ImageInfo about fetched thumbnail
  *
  * @param string $name
  * @return \Imager\ImageInfo
  */
 public function fetchThumbnail($name)
 {
     if (!isset($name) || Strings::length($name) === 0) {
         throw new InvalidArgumentException('Name of fetched file cannot be empty.');
     }
     $thumbnail = $this->getThumbnailPath($name);
     if (!file_exists($thumbnail)) {
         $msg = sprintf('Thumbnail image "%s" not exists.', $thumbnail);
         throw new NotExistsException($msg);
     }
     $parts = Helpers::parseName($name);
     if (isset($parts['id'])) {
         $source = $this->fetch($parts['id']);
     }
     return new ImageInfo($thumbnail, $source);
 }
开发者ID:lawondyss,项目名称:imager,代码行数:22,代码来源:Repository.php

示例15: createTemplate

 /**
  * @param \Nette\Application\UI\Control $control
  * @return \Nette\Bridges\ApplicationLatte\Template
  */
 public function createTemplate(\Nette\Application\UI\Control $control)
 {
     $latte = $this->latteFactory->create();
     $template = new Template($latte);
     $presenter = $control->getPresenter(false);
     if ($control instanceof \Nette\Application\UI\Presenter) {
         $latte->setLoader(new Loader($control));
     }
     if ($latte->onCompile instanceof \Traversable) {
         $latte->onCompile = iterator_to_array($latte->onCompile);
     }
     array_unshift($latte->onCompile, function ($latte) use($control, $template) {
         $latte->getParser()->shortNoEscape = true;
         $latte->getCompiler()->addMacro('cache', new CacheMacro($latte->getCompiler()));
         UIMacros::install($latte->getCompiler());
         FormMacros::install($latte->getCompiler());
         $control->templatePrepareFilters($template);
     });
     $latte->addFilter('url', 'rawurlencode');
     // back compatiblity
     foreach (array('normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse') as $name) {
         $latte->addFilter($name, 'Nette\\Utils\\Strings::' . $name);
     }
     $latte->addFilter('null', function () {
     });
     $latte->addFilter('length', function ($var) {
         return is_string($var) ? \Nette\Utils\Strings::length($var) : count($var);
     });
     $latte->addFilter('modifyDate', function ($time, $delta, $unit = null) {
         return $time == null ? null : \Nette\Utils\DateTime::from($time)->modify($delta . $unit);
         // intentionally ==
     });
     // default parameters
     $template->control = $template->_control = $control;
     $template->presenter = $template->_presenter = $presenter;
     $template->netteHttpResponse = $this->httpResponse;
     $template->netteCacheStorage = $this->cacheStorage;
     $template->pathResolver = $this->pathResolver;
     $template->netteUser = $this->user;
     $template->basePath = preg_replace('#https?://[^/]+#A', '', $this->httpRequest ? rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/') : null);
     $template->flashes = array();
     if ($presenter instanceof \Nette\Application\UI\Presenter && $presenter->hasFlashSession()) {
         $id = $control->getParameterId('flash');
         $template->flashes = (array) $presenter->getFlashSession()->{$id};
     }
     return $template;
 }
开发者ID:venne,项目名称:venne,代码行数:51,代码来源:TemplateFactory.php


注:本文中的Nette\Utils\Strings::length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。