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

PHP Nette\String类代码示例

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

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



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

示例1: getPresenterClass

 public function getPresenterClass(&$name)
 {
     if (isset($this->cache[$name])) {
         list($className, $name) = $this->cache[$name];
         return $className;
     }
     if (!is_string($name) || !String::match($name, "#^[a-zA-Z-ÿ][a-zA-Z0-9-ÿ:]*\$#")) {
         throw new InvalidPresenterException("Presenter name must be alphanumeric string, '{$name}' is invalid.");
     }
     $classNameBase = str_replace(':', 'Module\\', $name) . 'Presenter';
     $classNames = array_map(function ($namespace) use($classNameBase) {
         return ($namespace ? $namespace . "\\" : "") . $classNameBase;
     }, $this->namespaces);
     foreach ($classNames as $className) {
         if (!class_exists($className)) {
             continue;
         }
         $reflection = new ClassReflection($className);
         if (!$reflection->implementsInterface('Nette\\Application\\IPresenter')) {
             throw new InvalidPresenterException("Cannot load presenter '{$name}', class '{$className}' is not Nette\\Application\\IPresenter implementor.");
         }
         if ($reflection->isAbstract()) {
             throw new InvalidPresenterException("Cannot load presenter '{$name}', class '{$className}' is abstract.");
         }
         return $className;
     }
     throw new InvalidPresenterException("Cannot load presenter {$name}, class " . implode(" nor ", $classNames) . " does not exist");
 }
开发者ID:janmarek,项目名称:Neuron,代码行数:28,代码来源:PresenterLoader.php


示例2: sanitize

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


示例3: __invoke

 /**
  * Invoke filter
  * @param string code
  * @param WebLoader loader
  * @param string file
  * @return string
  */
 public function __invoke($code, WebLoader $loader, $file)
 {
     if (String::endsWith($file, ".less")) {
         return $this->getLessC()->parse($code);
     }
     return $code;
 }
开发者ID:janmarek,项目名称:Neuron,代码行数:14,代码来源:LessFilter.php


示例4: checkMaxLength

 /**
  * Filter: shortens value to control's max length.
  * @return string
  */
 public function checkMaxLength($value)
 {
     if ($this->control->maxlength && Nette\String::length($value) > $this->control->maxlength) {
         $value = iconv_substr($value, 0, $this->control->maxlength, 'UTF-8');
     }
     return $value;
 }
开发者ID:nella,项目名称:ActiveMapper,代码行数:11,代码来源:TextInput.php


示例5: attached

 /**
  * This method will be called when the component (or component's parent)
  * becomes attached to a monitored object. Do not call this method yourself.
  * @param  IComponent
  * @return void
  */
 protected function attached($dataGrid)
 {
     if ($dataGrid instanceof DataGrid) {
         $this->setParent($dataGrid->getComponent('columns', TRUE));
         if ($this->caption === NULL) {
             $this->caption = \Nette\String::capitalize($this->getName());
         }
     }
 }
开发者ID:jurasm2,项目名称:datagrid,代码行数:15,代码来源:DataGridColumn.php


示例6: processRequest

	/**
	 * Processes given request.
	 *
	 * @author   Jan Tvrdík
	 * @param    PresenterRequest
	 * @return   void
	 * @throws   Nette\Applicationy\AbortException|BadRequestException
	 */
	public function processRequest(PresenterRequest $request)
	{
		$params = $request->getParams();
		if (!isset($params['page'])) {
			throw new BadRequestException('Invalid request. Parameter \'page\' is required.');
		}
		$this->page = $params['page'];
		if (!Nette\String::match($this->page, self::PAGE_REGEXP)) {
			throw new BadRequestException('Parameter \'page\' contains illegal characters.');
		}
		$this->sendTemplate();
	}
开发者ID:JanTvrdik,项目名称:NetteExtrasWeb,代码行数:20,代码来源:StaticPagePresenter.php


示例7: getPresenterClass

	/**
	 * @param  string  presenter name
	 * @return string  class name
	 * @throws InvalidPresenterException
	 */
	public function getPresenterClass(& $name)
	{
		if (isset($this->cache[$name])) {
			list($class, $name) = $this->cache[$name];
			return $class;
		}

		if (!is_string($name) || !Nette\String::match($name, "#^[a-zA-Z\x7f-\xff][a-zA-Z0-9\x7f-\xff:]*$#")) {
			throw new InvalidPresenterException("Presenter name must be alphanumeric string, '$name' is invalid.");
		}

		$class = $this->formatPresenterClass($name);

		if (!class_exists($class)) {
			// internal autoloading
			$file = $this->formatPresenterFile($name);
			if (is_file($file) && is_readable($file)) {
				Nette\Loaders\LimitedScope::load($file);
			}

			if (!class_exists($class)) {
				throw new InvalidPresenterException("Cannot load presenter '$name', class '$class' was not found in '$file'.");
			}
		}

		$reflection = new Nette\Reflection\ClassReflection($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.");
		}

		if ($reflection->isAbstract()) {
			throw new InvalidPresenterException("Cannot load presenter '$name', class '$class' is abstract.");
		}

		// canonicalize presenter name
		$realName = $this->unformatPresenterClass($class);
		if ($name !== $realName) {
			if ($this->caseSensitive) {
				throw new InvalidPresenterException("Cannot load presenter '$name', case mismatch. Real name is '$realName'.");
			} else {
				$this->cache[$name] = array($class, $realName);
				$name = $realName;
			}
		} else {
			$this->cache[$name] = array($class, $realName);
		}

		return $class;
	}
开发者ID:norbe,项目名称:AutoUse,代码行数:56,代码来源:PresenterLoader.php


示例8: processArguments

 public function processArguments($args, IContext $context)
 {
     return array_map(function ($arg) use($context) {
         if (!is_string($arg)) {
             return $arg;
         } elseif (String::startsWith($arg, "%")) {
             return $context->getService(substr($arg, 1));
         } elseif (String::startsWith($arg, "\$\$")) {
             return Environment::getConfig(substr($arg, 2));
         } elseif (String::startsWith($arg, "\$")) {
             return Environment::getVariable(substr($arg, 1));
         } else {
             return $arg;
         }
     }, $args);
 }
开发者ID:janmarek,项目名称:Neuron,代码行数:16,代码来源:ServiceLoader.php


示例9: texyElements

	/**
	 * Processes <texy>...</texy> elements.
	 *
	 * @author   David Grudl, Jan Tvrdík
	 * @param    string
	 * @return   string
	 */
	public static function texyElements($s)
	{
		$texy = self::$texy;
		if ($texy === NULL) throw new \InvalidStateException(get_class($this) . '::$texy must be set.');

		return Nette\String::replace($s, '#<texy>(.*?)</texy>#s', function ($m) use ($texy) {
				$s = $m[1];
				$singleLine = (strpos($s, "\n") === FALSE);
				$s = trim($s, "\n");
				$tabs = strspn($s, "\t");
				if ($tabs) $s = Nette\String::replace($s, "#^\t{1,$tabs}#m", '');
				$s = $texy->process($s, $singleLine);
				return "{syntax double}$s{{/syntax}}";
			}
		);
	}
开发者ID:JanTvrdik,项目名称:NetteExtrasWeb,代码行数:23,代码来源:TemplateFilters.php


示例10: canonicalizeDestination

 private function canonicalizeDestination($destination)
 {
     // searching for any string that wikipedia knows
     $c = curl_init();
     curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($c, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
     curl_setopt($c, CURLOPT_USERAGENT, 'Travelbot 1.0 beta');
     curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE);
     curl_setopt($c, CURLOPT_MAXREDIRS, 100);
     $uri = new Uri('http://en.wikipedia.org/w/api.php');
     $uri->setQuery(array('format' => 'json', 'action' => 'opensearch', 'search' => $destination, 'limit' => 5));
     curl_setopt($c, CURLOPT_URL, (string) $uri);
     $result = curl_exec($c);
     curl_close($c);
     $json = json_decode($result);
     if ($json === FALSE) {
         throw new InvalidStateException('Malformed JSON response.');
     }
     if (!isset($json[1][0])) {
         throw new ArticleException('Article not found.');
     }
     $destination = $json[1][0];
     // canonization (redirection to the final article)
     $c = curl_init();
     curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($c, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
     curl_setopt($c, CURLOPT_USERAGENT, 'Travelbot 1.0 beta');
     curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE);
     curl_setopt($c, CURLOPT_MAXREDIRS, 100);
     $uri = new Uri('http://en.wikipedia.org/w/api.php');
     $uri->setQuery(array('format' => 'json', 'action' => 'query', 'titles' => $destination, 'redirects' => TRUE));
     curl_setopt($c, CURLOPT_URL, (string) $uri);
     $result = curl_exec($c);
     curl_close($c);
     $json = json_decode($result);
     if ($json === FALSE) {
         return $destination;
     }
     if (isset($json->query->redirects[0])) {
         return $json->query->redirects[0]->to;
     } else {
         if (isset($json->query->normalized[0])) {
             return String::capitalize($json->query->normalized[0]->to);
         }
     }
     return $destination;
 }
开发者ID:jff15,项目名称:travelbot,代码行数:47,代码来源:ArticleWikipediaMapper.php


示例11: el

 /**
  * Static factory.
  * @param  string element name (or NULL)
  * @param  array|string element's attributes (or textual content)
  * @return Html
  */
 public static function el($name = NULL, $attrs = NULL)
 {
     $el = new static();
     $parts = explode(' ', $name, 2);
     $el->setName($parts[0]);
     if (is_array($attrs)) {
         $el->attrs = $attrs;
     } elseif ($attrs !== NULL) {
         $el->setText($attrs);
     }
     if (isset($parts[1])) {
         foreach (Nette\String::matchAll($parts[1] . ' ', '#([a-z0-9:-]+)(?:=(["\'])?(.*?)(?(2)\\2|\\s))?#i') as $m) {
             $el->attrs[$m[1]] = isset($m[3]) ? $m[3] : TRUE;
         }
     }
     return $el;
 }
开发者ID:JanTvrdik,项目名称:nette,代码行数:23,代码来源:Html.php


示例12: __invoke

	/**
	 * Processes <texy>...</texy> elements.
	 *
	 * @author   David Grudl, Jan Tvrdík
	 * @param    string
	 * @return   string
	 */
	public function __invoke($s)
	{
		$texy = $this->texy;
		$autoChangeSyntax = $this->autoChangeSyntax;
		if ($texy === NULL) throw new \InvalidStateException(get_class($this) . '::$texy must be set.');

		return Nette\String::replace($s, '#<texy>(.*?)</texy>#s', function ($m) use ($texy, $autoChangeSyntax) {
				$s = $m[1];
				$singleLine = (strpos($s, "\n") === FALSE);
				$s = trim($s, "\r\n");
				$tabs = strspn($s, "\t");
				if ($tabs) $s = Nette\String::replace($s, "#^\t{1,$tabs}#m", '');
				$s = $texy->process($s, $singleLine);
				return ($autoChangeSyntax ? "{syntax double}$s{{/syntax}}" : $s);
			}
		);
	}
开发者ID:JanTvrdik,项目名称:StaticWeb,代码行数:24,代码来源:TexyElementsFilter.php


示例13: getPanel

	public function getPanel()
	{
		$s = '';
		foreach ($this->queries as $query) {
			list($sql, $params, $time, $rows) = $query;
			$s .= '<tr><td>' . sprintf('%0.3f', $time * 1000) . '</td><td class="database-sql">' . Connection::highlightSql(Nette\String::truncate($sql, self::$maxLength))
				. '</td><td>' . htmlSpecialChars(implode(', ', $params)) . '</td><td>' . $rows . '</td></tr>';
		}

		return empty($this->queries) ? '' :
			'<style> #nette-debug-database td.database-sql { background: white !important } </style>
			<h1>Queries: ' . count($this->queries) . ($this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '') . '</h1>
			<div class="nette-inner">
			<table>
				<tr><th>Time&nbsp;ms</th><th>SQL Statement</th><th>Params</th><th>Rows</th></tr>' . $s . '
			</table>
			</div>';
	}
开发者ID:newPOPE,项目名称:screencast,代码行数:18,代码来源:DatabasePanel.php


示例14: process

 /**
  * @param  string
  * @param  array
  * @return array of [sql, params]
  */
 public function process($sql, $params)
 {
     $this->params = $params;
     $this->counter = 0;
     $this->remaining = array();
     $cmd = strtoupper(substr(ltrim($sql), 0, 6));
     // detect array mode
     $this->arrayMode = $cmd === 'INSERT' || $cmd === 'REPLAC' ? 'values' : 'assoc';
     /*~
     			\'.*?\'|".*?"|   ## string
     			:[a-zA-Z0-9_]+:| ## :substitution:
     			\?               ## placeholder
     		~xs*/
     $sql = Nette\String::replace($sql, '~\'.*?\'|".*?"|:[a-zA-Z0-9_]+:|\\?~s', array($this, 'callback'));
     while ($this->counter < count($params)) {
         $sql .= ' ' . $this->formatValue($params[$this->counter++]);
     }
     return array($sql, $this->remaining);
 }
开发者ID:JanTvrdik,项目名称:nette,代码行数:24,代码来源:SqlPreprocessor.php


示例15: absolutizeUrl

 /**
  * Make relative url absolute
  * @param string image url
  * @param string single or double quote
  * @param string absolute css file path
  * @param string source path
  * @return string
  */
 public static function absolutizeUrl($url, $quote, $cssFile, $sourcePath)
 {
     // is already absolute
     if (preg_match("/^([a-z]+:\\/)?\\//", $url)) {
         return $url;
     }
     $docroot = realpath(WWW_DIR);
     $basePath = rtrim(Environment::getVariable("baseUri"), '/');
     // inside document root
     if (String::startsWith($cssFile, $docroot)) {
         $path = $basePath . substr(dirname($cssFile), strlen($docroot)) . DIRECTORY_SEPARATOR . $url;
         // outside document root
     } else {
         $path = $basePath . substr($sourcePath, strlen($docroot)) . DIRECTORY_SEPARATOR . $url;
     }
     //$path = self::cannonicalizePath($path);
     $path = strtr($path, "\\", "/");
     return $quote === '"' ? addslashes($path) : $path;
 }
开发者ID:janmarek,项目名称:Neuron,代码行数:27,代码来源:CssUrlsFilter.php


示例16: createComponentAddTagForm

 protected function createComponentAddTagForm()
 {
     $form = new AppForm();
     $form->addText("name", "Name", 40, 50);
     $form->addSubmit("s", "Add");
     $presenter = $this;
     $form->onSubmit[] = function ($form) use($presenter) {
         $name = $form->values["name"];
         $tag = new Tag();
         $tag->name = $name;
         $tag->url = String::webalize($name);
         try {
             $tag->save();
             $presenter->flashMessage("Tag was added!");
             $presenter->redirect("default");
         } catch (\ModelException $e) {
             $tag->addErrorsToForm($form);
         }
     };
     return $form;
 }
开发者ID:janmarek,项目名称:Ormion,代码行数:21,代码来源:TagPresenter.php


示例17: setUrl

 public function setUrl($url)
 {
     $uriScript = new UriScript($url);
     $uriScript->setScriptPath(Environment::getHttpRequest()->getUri()->getScriptPath());
     $httpRequest = new HttpRequest($uriScript);
     $presenterRequest = Environment::getApplication()->getRouter()->match($httpRequest);
     if ($presenterRequest === null || !String::startsWith($url, Environment::getVariable("baseUri"))) {
         $this->url = $url ?: null;
         $this->destination = null;
         $this->params = array();
     } else {
         $presenter = $presenterRequest->getPresenterName();
         $params = $presenterRequest->getParams();
         $action = isset($params["action"]) ? $params["action"] : "default";
         $module = isset($params["module"]) ? $params["module"] . ":" : "";
         unset($params["action"]);
         $this->destination = "{$module}{$presenter}:{$action}";
         $this->params = $params;
         $this->url = null;
     }
 }
开发者ID:janmarek,项目名称:Neuron,代码行数:21,代码来源:MenuItem.php


示例18: texyElements

 /**
  * Process <texy>...</texy> elements.
  * @param  string
  * @return string
  */
 public static function texyElements($s)
 {
     return String::replace($s, '#<texy([^>]*)>(.*?)</texy>#s', function ($m) {
         list(, $mAttrs, $mContent) = $m;
         // parse attributes
         $attrs = array();
         if ($mAttrs) {
             foreach (String::matchAll($mAttrs, '#([a-z0-9:-]+)\\s*(?:=\\s*(\'[^\']*\'|"[^"]*"|[^\'"\\s]+))?()#isu') as $m) {
                 $key = strtolower($m[1]);
                 $val = $m[2];
                 if ($val == NULL) {
                     $attrs[$key] = TRUE;
                 } elseif ($val[0] === '\'' || $val[0] === '"') {
                     $attrs[$key] = html_entity_decode(substr($val, 1, -1), ENT_QUOTES, 'UTF-8');
                 } else {
                     $attrs[$key] = html_entity_decode($val, ENT_QUOTES, 'UTF-8');
                 }
             }
         }
         return TemplateFilters::$texy->process($m[2]);
     });
 }
开发者ID:JanTvrdik,项目名称:nette,代码行数:27,代码来源:TemplateFilters.php


示例19: setHeader

 /**
  * Sets a header.
  * @param  string
  * @param  string|array  value or pair email => name
  * @param  bool
  * @return MailMimePart  provides a fluent interface
  */
 public function setHeader($name, $value, $append = FALSE)
 {
     if (!$name || preg_match('#[^a-z0-9-]#i', $name)) {
         throw new \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 = array();
         }
         foreach ($value as $email => $name) {
             if ($name !== NULL && !Nette\String::checkEncoding($name)) {
                 throw new \InvalidArgumentException("Name is not valid UTF-8 string.");
             }
             if (!preg_match('#^[^@",\\s]+@[^@",\\s]+\\.[a-z]{2,10}$#i', $email)) {
                 throw new \InvalidArgumentException("Email address '{$email}' is not valid.");
             }
             if (preg_match('#[\\r\\n]#', $name)) {
                 throw new \InvalidArgumentException("Name cannot contain the line separator.");
             }
             $tmp[$email] = $name;
         }
     } else {
         $value = (string) $value;
         if (!Nette\String::checkEncoding($value)) {
             throw new \InvalidArgumentException("Header is not valid UTF-8 string.");
         }
         $this->headers[$name] = preg_replace('#[\\r\\n]+#', ' ', $value);
     }
     return $this;
 }
开发者ID:nella,项目名称:ActiveMapper,代码行数:44,代码来源:MailMimePart.php


示例20: scanScript

 /**
  * Analyse PHP file.
  * @param  string
  * @return void
  */
 private function scanScript($file)
 {
     $T_NAMESPACE = PHP_VERSION_ID < 50300 ? -1 : T_NAMESPACE;
     $T_NS_SEPARATOR = PHP_VERSION_ID < 50300 ? -1 : T_NS_SEPARATOR;
     $expected = FALSE;
     $namespace = '';
     $level = 0;
     $time = filemtime($file);
     $s = file_get_contents($file);
     if ($matches = String::match($s, '#//nette' . 'loader=(\\S*)#')) {
         foreach (explode(',', $matches[1]) as $name) {
             $this->addClass($name, $file, $time);
         }
         return;
     }
     foreach (token_get_all($s) as $token) {
         if (is_array($token)) {
             switch ($token[0]) {
                 case T_COMMENT:
                 case T_DOC_COMMENT:
                 case T_WHITESPACE:
                     continue 2;
                 case $T_NS_SEPARATOR:
                 case T_STRING:
                     if ($expected) {
                         $name .= $token[1];
                     }
                     continue 2;
                 case $T_NAMESPACE:
                 case T_CLASS:
                 case T_INTERFACE:
                     $expected = $token[0];
                     $name = '';
                     continue 2;
                 case T_CURLY_OPEN:
                 case T_DOLLAR_OPEN_CURLY_BRACES:
                     $level++;
             }
         }
         if ($expected) {
             switch ($expected) {
                 case T_CLASS:
                 case T_INTERFACE:
                     if ($level === 0) {
                         $this->addClass($namespace . $name, $file, $time);
                     }
                     break;
                 case $T_NAMESPACE:
                     $namespace = $name . '\\';
             }
             $expected = NULL;
         }
         if ($token === '{') {
             $level++;
         } elseif ($token === '}') {
             $level--;
         }
     }
 }
开发者ID:nella,项目名称:ActiveMapper,代码行数:64,代码来源:RobotLoader.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP Application\Request类代码示例发布时间:2022-05-23
下一篇:
PHP Nette\ObjectMixin类代码示例发布时间: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