本文整理匯總了PHP中Illuminate\Support\Str::replaceFirst方法的典型用法代碼示例。如果您正苦於以下問題:PHP Str::replaceFirst方法的具體用法?PHP Str::replaceFirst怎麽用?PHP Str::replaceFirst使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Support\Str
的用法示例。
在下文中一共展示了Str::replaceFirst方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: auth
/**
* Authenticate the incoming request for a given channel.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function auth($request)
{
if (Str::startsWith($request->channel_name, ['private-', 'presence-']) && !$request->user()) {
throw new HttpException(403);
}
$channelName = Str::startsWith($request->channel_name, 'private-') ? Str::replaceFirst('private-', '', $request->channel_name) : Str::replaceFirst('presence-', '', $request->channel_name);
return parent::verifyUserCanAccessChannel($request, $channelName);
}
示例2: to
/**
* Generate an absolute URL to the given path.
*
* @param string $path
* @param mixed $extra
* @param bool|null $secure
* @return string
*/
public function to($path, $extra = [], $secure = null)
{
// First we will check if the URL is already a valid URL. If it is we will not
// try to generate a new one but will simply return the URL as is, which is
// convenient since developers do not always have to check if it's valid.
if ($this->isValidUrl($path)) {
return $path;
}
$subfolder = site()->subfolder;
$path = $subfolder ? $subfolder . '/' . Str::replaceFirst('/' . $subfolder . '/', '', $path) : $path;
return parent::to($path, $extra, $secure);
}
示例3: registerClassAutoloader
/**
* Register class autoloader for plugins.
*
* @return void
*/
protected function registerClassAutoloader($paths)
{
spl_autoload_register(function ($class) use($paths) {
// traverse in registered plugin paths
foreach ((array) array_keys($paths) as $namespace) {
if ($namespace != '' && mb_strpos($class, $namespace) === 0) {
// parse real file path
$path = $paths[$namespace] . Str::replaceFirst($namespace, '', $class) . ".php";
$path = str_replace('\\', '/', $path);
if (file_exists($path)) {
// include class file if it exists
include $path;
}
}
}
});
}
示例4:
/**
* Replace the first occurrence of a given value in the string.
*
* @param string $search
* @param string $replace
* @param string $subject
* @return string
*/
function str_replace_first($search, $replace, $subject)
{
return Str::replaceFirst($search, $replace, $subject);
}
示例5: function
* @param string $string
* @param string $delimiter
* @param int $nth
* @return string
*/
Str::macro('segment', function ($string, $delimiter, $nth) {
$segments = explode($delimiter, $string);
if ($nth < 0) {
$segments = array_reverse($segments);
$nth = abs($nth) - 1;
} elseif ($nth == 0) {
$nth++;
} else {
$nth--;
}
return isset($segments[$nth]) ? $segments[$nth] : '';
});
}
if (!Str::hasMacro('shift')) {
/**
* Shift off the first segment of a string based on a delimiter.
* Returns the remaining string.
*
* @param string $string
* @param string $delimiter
* @return string
*/
Str::macro('shift', function ($string, $delimiter) {
return Str::replaceFirst(Str::firstSegment($string, $delimiter) . $delimiter, '', $string);
});
}
示例6: url
/**
* Get the URL for the file at the given path.
*
* @param string $path
* @return string
*/
public function url($path)
{
$adapter = $this->driver->getAdapter();
if ($adapter instanceof AwsS3Adapter) {
$path = $adapter->getPathPrefix() . $path;
return $adapter->getClient()->getObjectUrl($adapter->getBucket(), $path);
} elseif ($adapter instanceof LocalAdapter) {
$path = '/storage/' . $path;
return Str::contains($path, '/storage/public') ? Str::replaceFirst('/public', '', $path) : $path;
} elseif (method_exists($adapter, 'getUrl')) {
return $adapter->getUrl($path);
} else {
throw new RuntimeException('This driver does not support retrieving URLs.');
}
}
示例7: view
protected function view($view, $data = [], $mergeData = [])
{
if (!Str::contains($view, '{account}')) {
return view($view, $data, $mergeData);
}
$viewPath = Str::replaceFirst("{account}", $this->shop() ? '__shop' : '__account', $view);
return view($viewPath, $data, $mergeData);
}
示例8: booleanType
public function booleanType($model, $field)
{
$fieldInput = '<label>' . Form::checkbox($field, '1', $model->{$field}) . ' ' . trans('livecms::' . $this->groupName . '.formclicktomakeas', ['field' => Str::title(Str::replaceFirst('is_', '', $field))]) . ' </label>';
return $this->fieldWrapper($field, $fieldInput);
}