本文整理汇总了PHP中Nette\String类的典型用法代码示例。如果您正苦于以下问题:PHP String类的具体用法?PHP String怎么用?PHP String使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了String类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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");
}
示例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", ' '));
}
示例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;
}
示例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;
}
示例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());
}
}
}
示例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();
}
示例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;
}
示例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);
}
示例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}}";
}
);
}
示例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;
}
示例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;
}
示例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);
}
);
}
示例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 ms</th><th>SQL Statement</th><th>Params</th><th>Rows</th></tr>' . $s . '
</table>
</div>';
}
示例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);
}
示例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;
}