本文整理汇总了PHP中Illuminate\Support\Str::substr方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::substr方法的具体用法?PHP Str::substr怎么用?PHP Str::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Str
的用法示例。
在下文中一共展示了Str::substr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTokenFromHeaders
/**
* Get the authorization bearer token from the headers, useful when AUTHing a user hitting the API that
* has already logged in.
*/
public function getTokenFromHeaders()
{
$bearer = Request::header('authorization');
if (Str::startsWith($bearer, 'Bearer ')) {
$this->token = Str::substr($bearer, 7);
}
}
示例2: getTestPath
public function getTestPath($name)
{
$name = $this->getClassNamespace($name);
$name = Str::substr($name, strlen($this->getRootNamespace()) + 1);
$switchToDirectorySlashes = Utils::switchToDirectorySlashes($name);
return 'tests' . DIRECTORY_SEPARATOR . str_replace(DIRECTORY_SEPARATOR, "", $switchToDirectorySlashes) . 'Test.php';
}
示例3: setData
public function setData($data)
{
$fullClassName = $this->composer->getClassNamespace($data['name']);
$testName = str_replace("\\", "", Str::substr($fullClassName, strlen($this->composer->getRootNamespace()) + 1)) . 'Test';
$data = array_merge(['namespace' => Utils::getJustNamespace($fullClassName), 'className' => Utils::getJustClassName($fullClassName), 'testName' => $testName], $data);
$this->data = $data;
return $this;
}
示例4: handle
public function handle(Request $request, Closure $next)
{
$default = $request->session()->get('locale', 'en');
$locale = $request->input('locale', $default);
$locale = Str::substr($locale, 0, 2);
$request->session()->put('locale', $locale);
$this->app->setLocale($locale);
return $next($request);
}
示例5: put
/**
* Put a request handler
*
* @param string $message
* @param callable $callback
* @return $this
*/
public function put($message, callable $callback)
{
list($method, $path) = explode(' ', $message);
if (Str::startsWith($path, '/')) {
$path = Str::substr($path, 1);
}
$method = Str::upper($method);
$this->handlers[$method][$path] = $callback;
return $this;
}
示例6: __callStatic
public static function __callStatic($name, $attributes)
{
if (Str::startsWith('get', $name)) {
$method = Str::camel($name);
if (method_exists(new static(), $method)) {
$class = static::class;
if (Arr::exists($attributes, 0)) {
return $class::$method($attributes[0]);
}
return $class::$method();
}
}
return env(Str::upper(Str::snake(Str::substr($name, 3))));
}
示例7: boot
/**
* @return void
*/
public function boot()
{
$this->getRouter()->get('/', function () {
$home = $this->getSetting()->get('site.home', 'default');
$page_id = 0;
if ($home != 'default' && Str::contains($home, 'page_')) {
$page_id = Str::substr($home, 5);
}
if ($page_id && Page::whereEnabled(true)->whereId($page_id)->count()) {
return $this->app->call('Notadd\\Page\\Controllers\\PageController@show', ['id' => $page_id]);
}
$this->app->make('view')->share('logo', file_get_contents(realpath($this->app->frameworkPath() . '/views/install') . DIRECTORY_SEPARATOR . 'logo.svg'));
return $this->app->make('view')->make('default::index');
});
}
示例8: handle
public function handle()
{
if (($table = $this->option('table')) === null) {
$tables = $this->DBHelper->listTables();
$table = $this->choice('Choose table:', $tables, null);
}
$columns = collect($this->DBHelper->listColumns($table));
$this->transformer->setColumns($columns);
$namespace = config('thunderclap.namespace');
$moduleName = str_replace('_', '', title_case($table));
$containerPath = config('thunderclap.target_dir', base_path('modules'));
$modulePath = $containerPath . DIRECTORY_SEPARATOR . $moduleName;
// 1. check existing module
if (is_dir($modulePath)) {
$overwrite = $this->confirm("Folder {$modulePath} already exist, do you want to overwrite it?");
if ($overwrite) {
File::deleteDirectory($modulePath);
} else {
return false;
}
}
// 2. create modules directory
$this->info('Creating modules directory...');
$this->packerHelper->makeDir($containerPath);
$this->packerHelper->makeDir($modulePath);
// 3. copy module skeleton
$stubs = __DIR__ . '/../../stubs';
$this->info('Copying module skeleton into ' . $modulePath);
File::copyDirectory($stubs, $modulePath);
$templates = ['module-name' => str_replace('_', '-', $table), 'route-prefix' => config('thunderclap.routes.prefix')];
// 4. rename file and replace common string
$search = [':Namespace:', ':module_name:', ':module-name:', ':module name:', ':Module Name:', ':moduleName:', ':ModuleName:', ':FILLABLE:', ':TRANSFORMER_FIELDS:', ':VALIDATION_RULES:', ':LANG_FIELDS:', ':TABLE_HEADERS:', ':TABLE_FIELDS:', ':DETAIL_FIELDS:', ':FORM_CREATE_FIELDS:', ':FORM_EDIT_FIELDS:', ':VIEW_EXTENDS:', ':route-prefix:', ':route-middleware:', ':route-url-prefix:'];
$replace = [$namespace, snake_case($table), $templates['module-name'], str_replace('_', ' ', strtolower($table)), ucwords(str_replace('_', ' ', $table)), str_replace('_', '', camel_case($table)), str_replace('_', '', title_case($table)), $this->transformer->toFillableFields(), $this->transformer->toTransformerFields(), $this->transformer->toValidationRules(), $this->transformer->toLangFields(), $this->transformer->toTableHeaders(), $this->transformer->toTableFields(), $this->transformer->toDetailFields(), $this->transformer->toFormCreateFields(), $this->transformer->toFormUpdateFields(), config('thunderclap.view.extends'), $templates['route-prefix'], $this->toArrayElement(config('thunderclap.routes.middleware')), $this->getRouteUrlPrefix($templates['route-prefix'], $templates['module-name'])];
foreach (File::allFiles($modulePath) as $file) {
if (is_file($file)) {
$newFile = $deleteOriginal = false;
if (Str::endsWith($file, '.stub')) {
$newFile = Str::substr($file, 0, -5);
$deleteOriginal = true;
}
$this->packerHelper->replaceAndSave($file, $search, $replace, $newFile, $deleteOriginal);
}
}
$this->warn('Add following service provider to config/app.php ====> ' . $namespace . '\\' . ucwords(str_replace('_', ' ', $table)) . '\\ServiceProvider::class,');
}
示例9: handle
/**
* Handle the event.
*
* @param \App\Events\WechatUserSubscribed $event
* @return \App\Models\Message
*/
public function handle(WechatUserSubscribed $event)
{
$m = $event->message;
/**
* openId is always unique to our official account, so if user subscribes
* again, we just need to toggle un-subscribed flag.
*/
if ($subscriber = Subscriber::where('openId', $m->fromUserName)->where('unsubscribed', true)->first()) {
$subscriber->unsubscribed = false;
} else {
$subscriber = new Subscriber();
$subscriber->openId = $m->fromUserName;
}
$subscriber->save();
// Link profile with subscriber if subscribe comes from profile page.
if ($key = $m->messageable->eventKey) {
Profile::find(Str::substr($key, Str::length('qrscene_')))->update(['weixin' => $m->fromUserName]);
event(new ChangeSubscriberGroup($subscriber));
}
return $this->greetMessage($m->fromUserName, !is_null($key));
}
示例10: substr
/**
* Substr
*
* @param string $origin origin text
* @param int $len cut length
* @return string
*/
protected function substr($origin, $len)
{
$text = Str::substr($origin, 0, $len);
return $origin == $text ? $text : $text . '...';
}
示例11: callCustomDirective
/**
* Call the given directive with the given value.
*
* @param string $name
* @param string|null $value
* @return string
*/
protected function callCustomDirective($name, $value)
{
if (Str::startsWith($value, '(') && Str::endsWith($value, ')')) {
$value = Str::substr($value, 1, -1);
}
return call_user_func($this->customDirectives[$name], trim($value));
}
示例12: savePhotos
/**
* Save photos uploaded with the form into
* the Photo model.
*
* @param object $request
* @param object $work
*
* @return void
*/
public function savePhotos($request, $work)
{
// Bail early if we don't have any files
if (!$request->hasFile('photos')) {
return;
}
$files = $request->file('photos');
// Loop through all files and create new entries
foreach ($files as $key => $file) {
$photoTitle = Str::substr($work->title, 0, 10);
// Create new photo
$photo = Photo::create(['title' => $photoTitle]);
// Set image name as slugify title in lowercase
$imageName = $photo->id . '.' . Str::slug($photoTitle) . '.' . $file->getClientOriginalExtension();
$imageName = Str::lower($imageName);
// Move file to storage location
$imagePath = storage_path() . '/uploads/img/';
$file->move($imagePath, $imageName);
// Add image filename to model
$photo->update(['filename' => $imageName, 'work_id' => $work->id]);
}
}
示例13: prepareRequest
protected function prepareRequest($request, array &$options)
{
$method = $request->getMethod();
$uri = $request->getUri();
$basePath = $options['base_uri']->getPath();
$path = Str::substr($uri->getPath(), Str::length($basePath));
if ($method === 'GET') {
parse_str($uri->getQuery(), $options['query']);
} else {
$body = (string) $request->getBody();
$options['json'] = json_decode($body, true);
}
return [$method, $path];
}
示例14: bearerToken
/**
* Get the bearer token from the request headers.
*
* @return string|null
*/
public function bearerToken()
{
$header = $this->header('Authorization', '');
if (Str::startsWith($header, 'Bearer ')) {
return Str::substr($header, 7);
}
}
示例15: registerCss
/**
* @param string $path
* @return mixed|void
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function registerCss($path)
{
if ($this->finder->exits($path)) {
switch (str_replace(Str::substr($path, strpos($path, '.')), '', Str::substr($path, strpos($path, '::') + 2))) {
case 'css':
$this->material->registerCssMaterial($path);
break;
case 'less':
$this->material->registerLessMaterial($path);
break;
case 'sass':
$this->material->registerSassMaterial($path);
break;
}
} else {
throw new FileNotFoundException('Css file [' . $path . '] does not exits!');
}
}