• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Utils\Strings类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: preUpload

 /**
  * @ORM\PreFlush()
  */
 public function preUpload()
 {
     if ($this->file) {
         if ($this->file instanceof FileUpload) {
             $basename = $this->file->getSanitizedName();
             $basename = $this->suggestName($this->getFilePath(), $basename);
             $this->setName($basename);
         } else {
             $basename = trim(Strings::webalize($this->file->getBasename(), '.', FALSE), '.-');
             $basename = $this->suggestName(dirname($this->file->getPathname()), $basename);
             $this->setName($basename);
         }
         if ($this->_oldPath && $this->_oldPath !== $this->path) {
             @unlink($this->getFilePathBy($this->_oldProtected, $this->_oldPath));
         }
         if ($this->file instanceof FileUpload) {
             $this->file->move($this->getFilePath());
         } else {
             copy($this->file->getPathname(), $this->getFilePath());
         }
         return $this->file = NULL;
     }
     if (($this->_oldPath || $this->_oldProtected !== NULL) && ($this->_oldPath != $this->path || $this->_oldProtected != $this->protected)) {
         $oldFilePath = $this->getFilePathBy($this->_oldProtected !== NULL ? $this->_oldProtected : $this->protected, $this->_oldPath ?: $this->path);
         if (file_exists($oldFilePath)) {
             rename($oldFilePath, $this->getFilePath());
         }
     }
 }
开发者ID:svobodni,项目名称:web,代码行数:32,代码来源:FileEntity.php


示例2: setValue

 /**
  * Sets selected items (by keys).
  * @param  array
  * @return self
  */
 public function setValue($values)
 {
     if (is_scalar($values) || $values === NULL) {
         $values = (array) $values;
     } elseif (!is_array($values)) {
         throw new Nette\InvalidArgumentException(sprintf("Value must be array or NULL, %s given in field '%s'.", gettype($values), $this->name));
     }
     $flip = [];
     foreach ($values as $value) {
         if (!is_scalar($value) && !method_exists($value, '__toString')) {
             throw new Nette\InvalidArgumentException(sprintf("Values must be scalar, %s given in field '%s'.", gettype($value), $this->name));
         }
         $flip[(string) $value] = TRUE;
     }
     $values = array_keys($flip);
     if ($this->checkAllowedValues && ($diff = array_diff($values, array_keys($this->items)))) {
         $set = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) {
             return var_export($s, TRUE);
         }, array_keys($this->items))), 70, '...');
         $vals = (count($diff) > 1 ? 's' : '') . " '" . implode("', '", $diff) . "'";
         throw new Nette\InvalidArgumentException("Value{$vals} are out of allowed set [{$set}] in field '{$this->name}'.");
     }
     $this->value = $values;
     return $this;
 }
开发者ID:jjanekk,项目名称:forms,代码行数:30,代码来源:MultiChoiceControl.php


示例3: constructUrl

 public function constructUrl(Request $appRequest, Url $refUrl)
 {
     // Module prefix not match.
     if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) {
         return null;
     }
     $params = $appRequest->getParameters();
     $urlStack = [];
     // Module prefix
     $moduleFrags = explode(":", Strings::lower($appRequest->getPresenterName()));
     $resourceName = array_pop($moduleFrags);
     $urlStack += $moduleFrags;
     // Resource
     $urlStack[] = Strings::lower($resourceName);
     // Id
     if (isset($params['id']) && is_scalar($params['id'])) {
         $urlStack[] = $params['id'];
         unset($params['id']);
     }
     // Set custom action
     if (isset($params['action']) && $this->_isApiAction($params['action'])) {
         unset($params['action']);
     }
     $url = $refUrl->getBaseUrl() . implode('/', $urlStack);
     // Add query parameters
     if (!empty($params)) {
         $url .= "?" . http_build_query($params);
     }
     return $url;
 }
开发者ID:bauer01,项目名称:unimapper-nette,代码行数:30,代码来源:Route.php


示例4: getPresenterClass

 /**
  * Generates and checks presenter class name.
  * @param  string  presenter name
  * @return string  class name
  * @throws InvalidPresenterException
  */
 public function getPresenterClass(&$name)
 {
     if (isset($this->cache[$name])) {
         return $this->cache[$name];
     }
     if (!is_string($name) || !Nette\Utils\Strings::match($name, '#^[a-zA-Z\\x7f-\\xff][a-zA-Z0-9\\x7f-\\xff:]*\\z#')) {
         throw new InvalidPresenterException("Presenter name must be alphanumeric string, '{$name}' is invalid.");
     }
     $class = $this->formatPresenterClass($name);
     if (!class_exists($class)) {
         throw new InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' was not found.");
     }
     $reflection = new \ReflectionClass($class);
     $class = $reflection->getName();
     if (!$reflection->implementsInterface('Nette\\Application\\IPresenter')) {
         throw new InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' is not Nette\\Application\\IPresenter implementor.");
     } elseif ($reflection->isAbstract()) {
         throw new InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' is abstract.");
     }
     $this->cache[$name] = $class;
     if ($name !== ($realName = $this->unformatPresenterClass($class))) {
         trigger_error("Case mismatch on presenter name '{$name}', correct name is '{$realName}'.", E_USER_WARNING);
         $name = $realName;
     }
     return $class;
 }
开发者ID:jave007,项目名称:test,代码行数:32,代码来源:PresenterFactory.php


示例5: __construct

 /**
  * @param Task $task
  * @param \SimpleXMLElement|null $pmml
  * @param DatabaseFactory $databaseFactory
  * @param PreprocessingFactory $preprocessingFactory
  * @param string $appVersion =''
  */
 public function __construct(Task $task, \SimpleXMLElement $pmml = null, DatabaseFactory $databaseFactory, PreprocessingFactory $preprocessingFactory, $appVersion = '')
 {
     if ($task instanceof Task) {
         $this->task = $task;
         $this->miner = $task->miner;
     }
     $this->appVersion = $appVersion;
     if (!empty($pmml)) {
         if ($pmml instanceof \SimpleXMLElement) {
             $this->pmml = $pmml;
         } elseif (is_string($pmml)) {
             $this->pmml = simplexml_load_string($pmml);
         }
     }
     if (!$pmml instanceof \SimpleXMLElement) {
         $this->prepareBlankPmml();
     }
     $this->appendTaskInfo();
     $this->databaseFactory = $databaseFactory;
     $this->preprocessingFactory = $preprocessingFactory;
     $connectivesArr = Cedent::getConnectives();
     foreach ($connectivesArr as $connective) {
         $this->connectivesArr[$connective] = Strings::firstUpper($connective);
     }
 }
开发者ID:kizi,项目名称:easyminer-easyminercenter,代码行数:32,代码来源:GuhaPmmlSerializer.php


示例6: setValue

 public function setValue($values)
 {
     if (is_scalar($values) || $values === NULL) {
         $values = (array) $values;
     } elseif (!is_array($values)) {
         throw new Nette\InvalidArgumentException(sprintf("Value must be array or NULL, %s given in field '%s'.", gettype($values), $this->name));
     }
     $flip = array();
     foreach ($values as $value) {
         if (!is_scalar($value) && !method_exists($value, '__toString')) {
             throw new Nette\InvalidArgumentException(sprintf("Values must be scalar, %s given in field '%s'.", gettype($value), $this->name));
         }
         $flip[(string) $value] = TRUE;
     }
     $values = array_keys($flip);
     $items = $this->items;
     $nestedKeys = array();
     array_walk_recursive($items, function ($value, $key) use(&$nestedKeys) {
         $nestedKeys[] = $key;
     });
     if ($diff = array_diff($values, $nestedKeys)) {
         $range = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) {
             return var_export($s, TRUE);
         }, $nestedKeys)), 70, '...');
         $vals = (count($diff) > 1 ? 's' : '') . " '" . implode("', '", $diff) . "'";
         throw new Nette\InvalidArgumentException("Value{$vals} are out of allowed range [{$range}] in field '{$this->name}'.");
     }
     $this->value = $values;
     return $this;
 }
开发者ID:krejcon3,项目名称:checkboxtree,代码行数:30,代码来源:CheckBoxTree.php


示例7: 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


示例8: from

 /**
  * @return self
  */
 public static function from(\ReflectionParameter $from)
 {
     $param = new static();
     $param->name = $from->getName();
     $param->reference = $from->isPassedByReference();
     if ($from->isArray()) {
         $param->typeHint = 'array';
     } elseif (PHP_VERSION_ID >= 50400 && $from->isCallable()) {
         $param->typeHint = 'callable';
     } else {
         try {
             $param->typeHint = $from->getClass() ? '\\' . $from->getClass()->getName() : NULL;
         } catch (\ReflectionException $e) {
             if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
                 $param->typeHint = '\\' . $m[1];
             } else {
                 throw $e;
             }
         }
     }
     $param->optional = PHP_VERSION_ID < 50407 ? $from->isOptional() || $param->typeHint && $from->allowsNull() : $from->isDefaultValueAvailable();
     $param->defaultValue = PHP_VERSION_ID === 50316 ? $from->isOptional() : $from->isDefaultValueAvailable() ? $from->getDefaultValue() : NULL;
     $namespace = $from->getDeclaringClass() ? $from->getDeclaringClass()->getNamespaceName() : NULL;
     $namespace = $namespace ? "\\{$namespace}\\" : '\\';
     if (Nette\Utils\Strings::startsWith($param->typeHint, $namespace)) {
         $param->typeHint = substr($param->typeHint, strlen($namespace));
     }
     return $param;
 }
开发者ID:NetteCamp,项目名称:2015-nextras-orm-twitter,代码行数:32,代码来源:Parameter.php


示例9: startup

 public function startup()
 {
     parent::startup();
     $this->dir = new DirEntity();
     $this->dir->setInvisible(TRUE);
     $this->dir->setName(Strings::webalize(get_class($this)) . Strings::random());
 }
开发者ID:svobodni,项目名称:web,代码行数:7,代码来源:AbstractImageEntity.php


示例10: getGitInfo

 /**
  * Returns Git info
  *
  * @return array
  */
 public static function getGitInfo()
 {
     $gitBinary = VP_GIT_BINARY;
     $info = [];
     $process = new Process(ProcessUtils::escapeshellarg($gitBinary) . " --version");
     $process->run();
     $info['git-binary-as-configured'] = $gitBinary;
     $info['git-available'] = $process->getErrorOutput() === null || !strlen($process->getErrorOutput());
     if ($info['git-available'] === false) {
         $info['output'] = ['stdout' => trim($process->getOutput()), 'stderr' => trim($process->getErrorOutput())];
         $info['env-path'] = getenv('PATH');
         return $info;
     }
     $output = trim($process->getOutput());
     $match = Strings::match($output, "~git version (\\d[\\d\\.]+\\d).*~");
     $version = $match[1];
     $gitPath = "unknown";
     if ($gitBinary == "git") {
         $osSpecificWhereCommand = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? "where" : "which";
         $process = new Process("{$osSpecificWhereCommand} git");
         $process->run();
         if ($process->isSuccessful()) {
             $gitPath = $process->getOutput();
         }
     } else {
         $gitPath = $gitBinary;
     }
     $info['git-version'] = $version;
     $info['git-binary-as-called-by-vp'] = $gitBinary;
     $info['git-full-path'] = $gitPath;
     $info['versionpress-min-required-version'] = RequirementsChecker::GIT_MINIMUM_REQUIRED_VERSION;
     $info['matches-min-required-version'] = RequirementsChecker::gitMatchesMinimumRequiredVersion($version);
     return $info;
 }
开发者ID:versionpress,项目名称:versionpress,代码行数:39,代码来源:SystemInfo.php


示例11: __construct

 public function __construct(Nette\Loaders\RobotLoader $robotLoader)
 {
     $classes = $robotLoader->getIndexedClasses();
     foreach ($classes as $class => $file) {
         if (class_exists($class)) {
             $reflection = new \Nette\Reflection\ClassType($class);
             if ($reflection->implementsInterface('Tatami\\Modules\\IModule')) {
                 if (!($reflection->isAbstract() or $reflection->isInterface())) {
                     $this->modules[] = $this->parseModuleName($reflection->getShortName());
                 }
             }
             if ($reflection->isSubclassOf('Tatami\\Presenters\\BackendPresenter')) {
                 $moduleName = $this->parseModuleName($reflection->getNamespaceName());
                 $presenterName = $this->parsePresenterName($reflection->getShortName());
                 $this->presenters[$moduleName][] = $presenterName;
                 $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
                 foreach ($methods as $method) {
                     if (Strings::match($method->name, '/action/') or Strings::match($method->name, '/render/')) {
                         $this->actions[$presenterName][] = $this->parseActionName($method->name);
                     }
                 }
             }
             unset($reflection);
         }
     }
 }
开发者ID:bazo,项目名称:Tatami,代码行数:26,代码来源:ShortcutsManager.php


示例12: __construct

 /**
  * @param string $name
  * @param Language $language
  */
 public function __construct($name, Language $language)
 {
     $this->name = $name;
     $this->language = $language;
     $this->slug = Strings::webalize($name);
     $this->scenarios = new ArrayCollection();
 }
开发者ID:stekycz,项目名称:dwarf-search,代码行数:11,代码来源:Character.php


示例13: getChangeDescription

 public function getChangeDescription()
 {
     if ($this->count === 1) {
         return $this->changeInfos[0]->getChangeDescription();
     }
     return sprintf("%s %d %s", Strings::capitalize(StringUtils::verbToPastTense($this->getAction())), $this->count, StringUtils::pluralize($this->getEntityName()));
 }
开发者ID:wp-cpm,项目名称:versionpress,代码行数:7,代码来源:BulkChangeInfo.php


示例14: getChangeDescription

 public function getChangeDescription()
 {
     if ($this->action === 'activate') {
         return "Site language switched to '{$this->languageName}'";
     }
     return Strings::capitalize(StringUtils::verbToPastTense($this->action)) . " translation '{$this->languageName}'";
 }
开发者ID:wp-cpm,项目名称:versionpress,代码行数:7,代码来源:TranslationChangeInfo.php


示例15: formatRecordString

 public static function formatRecordString($record, $formatString)
 {
     return Strings::replace($formatString, '#%[^%]*%#u', function ($m) use($record) {
         $m = Strings::trim($m[0], '%');
         return $m != '' ? $record[$m] : "%";
     });
 }
开发者ID:hleumas,项目名称:gridito,代码行数:7,代码来源:Grid.php


示例16: compare

 /**
  * @param string $actual
  * @param string $condition
  * @param mixed $expected
  * @throws Exception
  * @return bool
  */
 public function compare($actual, $condition, $expected)
 {
     $expected = (array) $expected;
     $expected = current($expected);
     $cond = str_replace(' ?', '', $condition);
     if ($cond === 'LIKE') {
         $actual = Strings::toAscii($actual);
         $expected = Strings::toAscii($expected);
         $pattern = str_replace('%', '(.|\\s)*', preg_quote($expected, '/'));
         return (bool) preg_match("/^{$pattern}\$/i", $actual);
     } elseif ($cond === '=') {
         return $actual == $expected;
     } elseif ($cond === '<>') {
         return $actual != $expected;
     } elseif ($cond === 'IS NULL') {
         return $actual === NULL;
     } elseif ($cond === 'IS NOT NULL') {
         return $actual !== NULL;
     } elseif ($cond === '<') {
         return (int) $actual < $expected;
     } elseif ($cond === '<=') {
         return (int) $actual <= $expected;
     } elseif ($cond === '>') {
         return (int) $actual > $expected;
     } elseif ($cond === '>=') {
         return (int) $actual >= $expected;
     } else {
         throw new Exception("Condition '{$condition}' not implemented yet.");
     }
 }
开发者ID:DaveLister007,项目名称:grido,代码行数:37,代码来源:ArraySource.php


示例17: setHeader

 /**
  * Sets a header.
  * @param  string
  * @param  string|array  value or pair email => name
  * @param  bool
  * @return self
  */
 public function setHeader($name, $value, $append = FALSE)
 {
     if (!$name || preg_match('#[^a-z0-9-]#i', $name)) {
         throw new Nette\InvalidArgumentException("Header name must be non-empty alphanumeric string, '{$name}' given.");
     }
     if ($value == NULL) {
         // intentionally ==
         if (!$append) {
             unset($this->headers[$name]);
         }
     } elseif (is_array($value)) {
         // email
         $tmp =& $this->headers[$name];
         if (!$append || !is_array($tmp)) {
             $tmp = [];
         }
         foreach ($value as $email => $recipient) {
             if ($recipient !== NULL && !Strings::checkEncoding($recipient)) {
                 Nette\Utils\Validators::assert($recipient, 'unicode', "header '{$name}'");
             }
             if (preg_match('#[\\r\\n]#', $recipient)) {
                 throw new Nette\InvalidArgumentException('Name must not contain line separator.');
             }
             Nette\Utils\Validators::assert($email, 'email', "header '{$name}'");
             $tmp[$email] = $recipient;
         }
     } else {
         $value = (string) $value;
         if (!Strings::checkEncoding($value)) {
             throw new Nette\InvalidArgumentException('Header is not valid UTF-8 string.');
         }
         $this->headers[$name] = preg_replace('#[\\r\\n]+#', ' ', $value);
     }
     return $this;
 }
开发者ID:jakubboucek,项目名称:mail,代码行数:42,代码来源:MimePart.php


示例18: getAssets

 /**
  * @param array $resources
  * @param bool $minify
  * @param string $baseDir
  * @throws AssetsException
  * @return array
  */
 public function getAssets(array $resources, $minify, $baseDir)
 {
     $config = [];
     $return = [];
     foreach ($resources as $resource) {
         $contents = file_get_contents($resource);
         $decompiled = Strings::endsWith($resource, '.json') ? json_decode($contents, TRUE) : Neon::decode($contents);
         $config = \Nette\DI\Config\Helpers::merge($config, $decompiled);
     }
     foreach ($config as $moduleArray) {
         foreach ($moduleArray as $type => $typeArray) {
             if (!isset(self::$supportTypes[$type])) {
                 throw new AssetsException("Found section '{$type}', but expected one of " . implode(', ', array_keys(self::$supportTypes)));
             }
             foreach ($typeArray as $minified => $assets) {
                 if ($minify) {
                     $return[$type][$minified] = TRUE;
                     continue;
                 }
                 foreach ((array) $assets as $row) {
                     if (strpos($row, '*') !== FALSE) {
                         /** @var \SplFileInfo $file */
                         foreach (Finder::findFiles(basename($row))->in($baseDir . '/' . dirname($row)) as $file) {
                             $return[$type][$minified][] = dirname($row) . '/' . $file->getBasename();
                         }
                     } else {
                         $return[$type][$minified][] = $row;
                     }
                 }
             }
         }
     }
     return $return;
 }
开发者ID:webchemistry,项目名称:assets,代码行数:41,代码来源:AssetsExtension.php


示例19: drawGroups

 protected function drawGroups(OutputInterface $output, Group $group)
 {
     $output->writeln(Nette\Utils\Strings::padLeft('', $group->getDepth(), ' ') . '\\_ ' . $group->getName() . ":" . $group->getType());
     foreach ($group->getChild() as $v) {
         $this->drawGroups($output, $v);
     }
 }
开发者ID:trejjam,项目名称:emailing,代码行数:7,代码来源:CliGroups.php


示例20: getChangeDescription

 public function getChangeDescription()
 {
     if ($this->action === 'switch') {
         return "Theme switched to '{$this->themeName}'";
     }
     return Strings::capitalize(StringUtils::verbToPastTense($this->action)) . " theme '{$this->themeName}'";
 }
开发者ID:wp-cpm,项目名称:versionpress,代码行数:7,代码来源:ThemeChangeInfo.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Utils\Validators类代码示例发布时间:2022-05-23
下一篇:
PHP Utils\Random类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap