本文整理汇总了PHP中Nette\Utils\Strings::substring方法的典型用法代码示例。如果您正苦于以下问题:PHP Strings::substring方法的具体用法?PHP Strings::substring怎么用?PHP Strings::substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\Strings
的用法示例。
在下文中一共展示了Strings::substring方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: __invoke
/**
* @param \Nette\Application\Application $application
* @param \Nette\Application\Request $request
*/
public function __invoke(Application $application, Request $request)
{
if (PHP_SAPI === 'cli') {
newrelic_background_job(TRUE);
}
$params = $request->getParameters();
$action = $request->getPresenterName();
if (isset($params[$this->actionKey])) {
$action = sprintf('%s:%s', $action, $params[$this->actionKey]);
}
if (!empty($this->map)) {
foreach ($this->map as $pattern => $appName) {
if ($pattern === '*') {
continue;
}
if (Strings::endsWith($pattern, '*')) {
$pattern = Strings::substring($pattern, 0, -1);
}
if (Strings::startsWith($pattern, ':')) {
$pattern = Strings::substring($pattern, 1);
}
if (Strings::startsWith($action, $pattern)) {
\VrtakCZ\NewRelic\Tracy\Bootstrap::setup($appName, $this->license);
break;
}
}
}
newrelic_name_transaction($action);
newrelic_disable_autorum();
}
示例3: 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", ' '));
}
示例4: computeHash
/**
* @param string|array $file
* @param int $time
* @param bool $debugMode
*
* @return string
*/
public static function computeHash($file, $time, $debugMode)
{
$debug = $debugMode ? 1 : 0;
$file = is_array($file) ? implode(',', $file) : $file;
$md5Raw = md5("{$debug};{$file};{$time}", TRUE);
$base64 = Strings::replace(base64_encode($md5Raw), '~\\W~');
return Strings::substring(Strings::webalize($base64), 0, 8);
}
示例5: 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';
}
}
示例6: toCamelCase
/**
* Converts the given string to "camelCase".
* @param string $string
* @return string
*/
public static function toCamelCase($string)
{
static $canUse = null;
if (is_null($canUse)) {
$canUse = method_exists(Strings::class, 'firstLower');
// Nette/Utils >= 2.3 only
}
$pascal = self::toPascalCase($string);
return $canUse ? Strings::firstLower($pascal) : Strings::lower(Strings::substring($pascal, 0, 1)) . Strings::substring($pascal, 1);
}
示例7: normalizeGithubRepositoryUrl
/**
* @param string
* @return string
*/
public static function normalizeGithubRepositoryUrl($url)
{
self::assertGithubRepositoryUrl($url);
$url = str_replace('github.com:', 'github.com/', $url);
if (Strings::endsWith($url, '.git')) {
$url = Strings::substring($url, 0, -4);
}
$match = Strings::match($url, '~' . self::GITHUB_REGEXP . '~');
return 'https://' . Strings::lower($match[0]);
}
示例8: createRoute
public function createRoute($title, $contentId, $sectionId)
{
$route = array();
$route['contentId'] = $contentId;
$webalize = \Nette\Utils\Strings::webalize($title);
$webalize = \Nette\Utils\Strings::substring($webalize, 0, 50);
$route['url'] = "program/" . $sectionId . "/" . $webalize;
$route['creationTime'] = date("Y-m-d G:i:s");
return $route;
}
示例9: sanitizeFileName
/**
* @param FileUpload $fileUpload
* @return string
*/
public static function sanitizeFileName(FileUpload $fileUpload)
{
$filename = $fileUpload->getSanitizedName();
$filename = Strings::lower($filename);
$fileInfo = new \SplFileInfo($filename);
$suffix = $fileInfo->getExtension();
$basename = $fileInfo->getBasename(".{$suffix}");
$hash = md5($fileUpload->getContents());
$hash = Strings::substring($hash, 0, 9);
return Strings::substring($basename, 0, 50) . "_{$hash}.{$suffix}";
}
示例10: getNormalizedRouterName
/**
* @return string|NULL
*/
private function getNormalizedRouterName()
{
$config = $this->getConfig($this->defaults);
if (empty($config['router'])) {
return NULL;
}
if (Strings::startsWith($config['router'], '@')) {
return Strings::substring($config['router'], 1);
}
return $config['router'];
}
示例11: getValue
/**
* Returns control's value.
* @return string
*/
public function getValue()
{
$value = $this->value;
if (!empty($this->control->maxlength)) {
$value = Strings::substring($value, 0, $this->control->maxlength);
}
foreach ($this->filters as $filter) {
$value = (string) call_user_func($filter, $value);
}
return $value === Strings::trim($this->translate($this->emptyValue)) ? '' : $value;
}
示例12: zipDirToFile
/**
* @param string $source
* @param string $zipFile
*/
public function zipDirToFile($source, $zipFile)
{
$archive = new ZipArchive();
$archive->open($zipFile, ZipArchive::CREATE);
$directory = basename($zipFile, '.zip');
/** @var SplFileInfo $file */
foreach (Finder::findFiles('*')->from($source) as $file) {
$relativePath = Strings::substring($file->getRealPath(), strlen($source) + 1);
$archive->addFile($file, $directory . '/' . $relativePath);
}
$archive->close();
}
示例13: match
/**
* Match request
* @param IRequest $request
* @return Request
*/
public function match(Http\IRequest $request)
{
$path = $request->url->getPathInfo();
if (!Strings::contains($path, $this->prefix)) {
return NULL;
}
$path = Strings::substring($path, strlen($this->prefix) + 1);
$pathParts = explode('/', $path);
$pathArguments = array_slice($pathParts, 1);
$action = $this->getActionName($request->getMethod(), $pathArguments);
$params = $this->getPathParameters($pathArguments);
$params[Route::MODULE_KEY] = $this->module;
$params[Route::PRESENTER_KEY] = $pathParts[0];
$params['action'] = $action;
$presenter = ($this->module ? $this->module . ':' : '') . $params[Route::PRESENTER_KEY];
$appRequest = new Application\Request($presenter, $request->getMethod(), $params, $request->getPost(), $request->getFiles());
return $appRequest;
}
示例14: renderSitemap
/**
* @param string
*/
public function renderSitemap($type = 'html')
{
$this->template->addons = $this->addons->findAll();
$this->template->vendors = $this->addons->findVendors();
$this->template->categories = $this->tags->findMainTags();
$pages = array();
foreach (Finder::findFiles('*.texy')->from($this->pagesDataPath) as $file) {
/** @var \SplFileInfo $file */
$slug = Strings::substring($file->getRealPath(), Strings::length($this->pagesDataPath) + 1, -5);
$data = $this->pageProcessor->process(file_get_contents($file->getRealPath()));
$createdAt = new \DateTime();
$createdAt->setTimestamp($file->getMTime());
$pages[] = (object) array('slug' => $slug, 'name' => $data['title'], 'createdAt' => $createdAt);
}
$this->template->pages = $pages;
if ($type == 'xml') {
$this->setView('sitemap.xml');
}
}
示例15: translate
public function translate($message, $count = NULL, $parameters = array(), $domain = NULL, $locale = NULL)
{
$translationString = $message instanceof Phrase ? $message->message : $message;
$prefix = $this->prefix . '.';
if (Strings::startsWith($message, '//')) {
$prefix = NULL;
$translationString = Strings::substring($translationString, 2);
}
if ($message instanceof Phrase) {
return $this->translator->translate(new Phrase($prefix . $translationString, $message->count, $message->parameters, $message->domain, $message->locale));
}
if (is_array($count)) {
$locale = $domain ?: NULL;
$domain = $parameters ?: NULL;
$parameters = $count ?: array();
$count = NULL;
}
return $this->translator->translate($prefix . $translationString, $count, (array) $parameters, $domain, $locale);
}