当前位置: 首页>>代码示例>>PHP>>正文


PHP Str::startsWith方法代码示例

本文整理汇总了PHP中Str::startsWith方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::startsWith方法的具体用法?PHP Str::startsWith怎么用?PHP Str::startsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Str的用法示例。


在下文中一共展示了Str::startsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: env

 /**
  * Gets the value of an environment variable. Supports boolean, empty and null.
  *
  * @param $key     string
  * @param $default mixed
  * @return mixed
  */
 function env($key, $default = null)
 {
     $value = getenv($key);
     if ($value === false) {
         return value($default);
     }
     switch (strtolower($value)) {
         case 'true':
         case '(true)':
             return true;
             break;
         case 'false':
         case '(false)':
             return false;
             break;
         case 'empty':
         case '(empty)':
             return '';
             break;
         case 'null':
         case '(null)':
             return;
             break;
         default:
             break;
     }
     if (strlen($value) > 1 && Str::startsWith($value, '"') && Str::endsWith($value, '"')) {
         return substr($value, 1, -1);
     }
     return $value;
 }
开发者ID:drmyersii,项目名称:drm2.co,代码行数:38,代码来源:helpers.php

示例2: putUpdate

 public function putUpdate()
 {
     // Handle the rest of the settings
     $fields = Input::all();
     foreach ($fields as $key => $value) {
         // Check if it's a private key
         if (\Str::startsWith($key, '_')) {
             continue;
         }
         // Void unchanged/unset values.
         if ($value == '') {
             continue;
         }
         // Handle salt
         if ($key == 'salt') {
             exit('this isn\'t ready');
             $auth = Config::get('salt.credentials');
             foreach ($value as $k => $v) {
                 if ($k == 'auth_username') {
                     $auth['username'] = $v;
                 }
                 if ($k == 'auth_password' && $v != '') {
                     $auth['password'] = $v;
                 }
                 Config::set($k, $v);
             }
         }
         $key = str_replace('_', '.', $key);
         Setting::set($key, $value);
     }
     return Redirect::action('Admin\\SettingController@getIndex');
 }
开发者ID:abhijo89,项目名称:VMPanel,代码行数:32,代码来源:SettingController.php

示例3: formAfterDelete

 public function formAfterDelete($model)
 {
     $fields = json_decode($model->fields);
     foreach ($fields as $value) {
         if (\Str::startsWith($value, 'attachment::')) {
             $id = explode('::', $value)[1];
             $file = \System\Models\File::find($id);
             if ($file) {
                 $file->delete();
             }
         }
     }
 }
开发者ID:tysonrude,项目名称:bloom7,代码行数:13,代码来源:UserForms.php

示例4: parameters

 /**
  * Extract all of the parameters from the tokens.
  *
  * @param array $tokens
  *
  * @return array
  */
 protected static function parameters(array $tokens)
 {
     $arguments = [];
     $options = [];
     foreach ($tokens as $token) {
         if (!Str::startsWith($token, '--')) {
             $arguments[] = static::parseArgument($token);
         } else {
             $options[] = static::parseOption(ltrim($token, '-'));
         }
     }
     return [$arguments, $options];
 }
开发者ID:axyr,项目名称:silverstripe-console,代码行数:20,代码来源:Parser.php

示例5: extract_doc_annotations

function extract_doc_annotations($comment, $annotation)
{
    $values = [];
    foreach (explode("\n", $comment) as $line) {
        if (!Str::startsWith(trim($line), '* ' . $annotation)) {
            continue;
        }
        $value = Str::substringAfter($line, $annotation);
        if ($value !== '') {
            $values[] = trim($value);
        }
    }
    return $values;
}
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:14,代码来源:doc-loader.php

示例6: displayBuildMessage

 protected function displayBuildMessage($buildMessage)
 {
     $message = trim($buildMessage);
     $change = BuildCommand::CHANGE;
     $delete = BuildCommand::DELETE;
     $notice = BuildCommand::NOTICE;
     $error = BuildCommand::ERROR;
     if (Str::startsWith($message, $change)) {
         $this->info($this->parseMessage($message, $change));
     } elseif (Str::startsWith($message, $delete)) {
         $this->warn($this->parseMessage($message, $delete));
     } elseif (Str::startsWith($message, $notice)) {
         $this->comment($this->parseMessage($message, $notice));
     } elseif (Str::startsWith($message, $error)) {
         $this->error($this->parseMessage($message, $error));
     } elseif ($message) {
         $this->line($this->parseMessage($message));
     }
 }
开发者ID:axyr,项目名称:silverstripe-console,代码行数:19,代码来源:BuildCommand.php

示例7: getRequestTarget

 /**
  * {@inheritdoc}
  */
 public final function getRequestTarget()
 {
     if (null !== $this->requestTarget) {
         return $this->requestTarget;
     }
     $uri = $this->getUri();
     if (null === $uri) {
         return '/';
     }
     $path = $uri->getPath();
     if (is_callable([$uri, 'getBasePath']) and !Str::startsWith($path, '/') and '' !== ($basePath = $uri->getBasePath())) {
         $path = $basePath . ('/' === $basePath ? '' : '/') . $path;
     }
     $requestTarget = $path;
     $query = $uri->getQuery();
     if ('' !== $query) {
         $requestTarget .= '?' . $query;
     }
     $this->setRequestTarget($requestTarget);
     return $requestTarget;
 }
开发者ID:elegantweb,项目名称:framework,代码行数:24,代码来源:Request.php

示例8: starts_with

 /**
  * Determine if a given string starts with a given substring.
  *
  * @param  string  $haystack
  * @param  string|array  $needles
  * @return bool
  */
 function starts_with($haystack, $needles)
 {
     return Str::startsWith($haystack, $needles);
 }
开发者ID:runningjack,项目名称:busticketAPI1,代码行数:11,代码来源:helpers.php

示例9: isBooleanField

 public function isBooleanField($field)
 {
     return Str::startsWith($field, 'ind_');
 }
开发者ID:richarrieta,项目名称:miequipo,代码行数:4,代码来源:BaseModel.php

示例10: registerProfilerToOutput

 /**
  * Register an after filter to automatically display the profiler.
  *
  * @return void
  */
 public function registerProfilerToOutput()
 {
     $app = $this->app;
     $sessionHash = static::SESSION_HASH;
     $app['router']->after(function ($request, $response) use($app, $sessionHash) {
         $profiler = $app['profiler'];
         $session = $app['session'];
         if ($session->has($sessionHash)) {
             $profiler->enable($session->get($sessionHash));
         }
         // Do not display profiler on ajax requests or non-HTML responses.
         $isHTML = \Str::startsWith($response->headers->get('Content-Type'), 'text/html');
         if (!$profiler->isEnabled() or $request->ajax() or !$isHTML) {
             return;
         }
         $responseContent = $response->getContent();
         // Don't do anything if the response content is not a string.
         if (is_string($responseContent)) {
             $profiler = $profiler->render();
             // If we can find a closing HTML tag in the response, let's add the
             // profiler content inside it.
             if (($pos = strrpos($responseContent, '</html>')) !== false) {
                 $responseContent = substr($responseContent, 0, $pos) . $profiler . substr($responseContent, $pos);
             } else {
                 $responseContent .= $profiler;
             }
             $response->setContent($responseContent);
         }
     });
 }
开发者ID:loic-sharma,项目名称:profiler,代码行数:35,代码来源:ProfilerServiceProvider.php

示例11: testStartsWithIsFalse

 public function testStartsWithIsFalse()
 {
     $this->assertFalse(Str::startsWith('abcdefghij', 'ahh'));
 }
开发者ID:starweb,项目名称:starlit-utils,代码行数:4,代码来源:StrTest.php

示例12: getPropertiesFromMethods

 /**
  * @param \Illuminate\Database\Eloquent\Model $model
  */
 protected function getPropertiesFromMethods($model)
 {
     $methods = get_class_methods($model);
     if ($methods) {
         foreach ($methods as $method) {
             if (\Str::startsWith($method, 'get') && \Str::endsWith($method, 'Attribute') && $method !== 'setAttribute') {
                 //Magic get<name>Attribute
                 $name = \Str::snake(substr($method, 3, -9));
                 if (!empty($name)) {
                     $this->setProperty($name, null, true, null);
                 }
             } elseif (\Str::startsWith($method, 'set') && \Str::endsWith($method, 'Attribute') && $method !== 'setAttribute') {
                 //Magic set<name>Attribute
                 $name = \Str::snake(substr($method, 3, -9));
                 if (!empty($name)) {
                     $this->setProperty($name, null, null, true);
                 }
             } elseif (\Str::startsWith($method, 'scope') && $method !== 'scopeQuery') {
                 //Magic set<name>Attribute
                 $name = \Str::camel(substr($method, 5));
                 if (!empty($name)) {
                     $reflection = new \ReflectionMethod($model, $method);
                     $args = $this->getParameters($reflection);
                     //Remove the first ($query) argument
                     array_shift($args);
                     $this->setMethod($name, $reflection->class, $args);
                 }
             } elseif (!method_exists('Eloquent', $method) && !\Str::startsWith($method, 'get')) {
                 //Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
                 $reflection = new \ReflectionMethod($model, $method);
                 $file = new \SplFileObject($reflection->getFileName());
                 $file->seek($reflection->getStartLine() - 1);
                 $code = '';
                 while ($file->key() < $reflection->getEndLine()) {
                     $code .= $file->current();
                     $file->next();
                 }
                 $begin = strpos($code, 'function(');
                 $code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
                 $begin = stripos($code, 'return $this->');
                 $parts = explode("'", substr($code, $begin + 14), 3);
                 //"return $this->" is 14 chars
                 if (isset($parts[2])) {
                     list($relation, $returnModel, $rest) = $parts;
                     $returnModel = "\\" . ltrim($returnModel, "\\");
                     $relation = trim($relation, ' (');
                     if ($relation === "belongsTo" or $relation === 'hasOne') {
                         //Single model is returned
                         $this->setProperty($method, $returnModel, true, null);
                     } elseif ($relation === "belongsToMany" or $relation === 'hasMany') {
                         //Collection or array of models (because Collection is Arrayable)
                         $this->setProperty($method, '\\Illuminate\\Database\\Eloquent\\Collection|' . $returnModel . '[]', true, null);
                     }
                 } else {
                     //Not a relation
                 }
             }
         }
     }
 }
开发者ID:ngogiangthanh,项目名称:code-nien-luan-ktpm-k36,代码行数:63,代码来源:ModelsCommand.php

示例13: afterListener

 /**
  * Output data on route after
  *
  * @return void
  */
 protected function afterListener()
 {
     $this->app['router']->after(function ($request, $response) {
         // Do not display profiler on non-HTML responses.
         if (\Str::startsWith($response->headers->get('Content-Type'), 'text/html')) {
             $content = $response->getContent();
             $output = Profiler::outputData();
             $body_position = strripos($content, '</body>');
             if ($body_position !== FALSE) {
                 $content = substr($content, 0, $body_position) . $output . substr($content, $body_position);
             } else {
                 $content .= $output;
             }
             $response->setContent($content);
         }
     });
 }
开发者ID:seantrane,项目名称:profiler,代码行数:22,代码来源:ProfilerServiceProvider.php

示例14: isPhar

 public static function isPhar($path = null)
 {
     $path = $path === null ? __FILE__ : $path;
     return Str::startsWith($path, 'phar://');
 }
开发者ID:laradic,项目名称:support,代码行数:5,代码来源:Path.php

示例15: isFillable

 public function isFillable($key)
 {
     if (static::$unguarded) {
         return true;
     }
     // If the key is in the "fillable" array, we can of course assume that it's
     // a fillable attribute. Otherwise, we will check the guarded array when
     // we need to determine if the attribute is black-listed on the model.
     if (in_array($key, $this->fillable)) {
         return true;
     }
     //This is the only one line that has been changed from original method.
     if ($this->isTranslatableFillable($key)) {
         return true;
     }
     if ($this->isGuarded($key)) {
         return false;
     }
     return empty($this->fillable) && !Str::startsWith($key, '_');
 }
开发者ID:aewebsolutions,项目名称:laravel-translator,代码行数:20,代码来源:Model.php


注:本文中的Str::startsWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。