/** * 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); }
/** * 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); }
/** * 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; } } } }); }
/** * 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); }
* @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); }); }
/** * 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.'); } }
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); }
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); }