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


PHP StringHelper::startsWith方法代码示例

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


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

示例1: getDiff

 /**
  * @inheritdoc
  */
 public function getDiff($file = null)
 {
     $previewFile = [];
     $ret = [];
     $appendFileDiff = function () use(&$previewFile, &$ret) {
         if (!empty($previewFile)) {
             $ret[] = new Diff($previewFile);
             $previewFile = [];
         }
     };
     $fullDiff = [];
     if (!is_null($file)) {
         $fullDiff = $this->repository->getDiff(Repository::DIFF_PATH, $file, $this->id);
     } else {
         $fullDiff = $this->repository->getDiff(Repository::DIFF_COMMIT, $this->id);
     }
     foreach ($fullDiff as $row) {
         if (StringHelper::startsWith($row, 'diff')) {
             // the new file diff, append to $ret
             $appendFileDiff();
         }
         $previewFile[] = $row;
     }
     // append last file diff to full array
     $appendFileDiff();
     return $ret;
 }
开发者ID:kalyabin,项目名称:yii2-git-view,代码行数:30,代码来源:Commit.php

示例2: actionIndex

 public function actionIndex()
 {
     $actions = [];
     $rc = new \ReflectionClass($this);
     $publicMethods = $rc->getMethods(\ReflectionMethod::IS_PUBLIC);
     $availableActions = [];
     foreach ($publicMethods as $publicMethod) {
         $methodName = $publicMethod->name;
         if ($methodName == 'actions') {
             continue;
         }
         if (StringHelper::startsWith($methodName, 'action')) {
             $availableActions[] = $methodName;
         }
     }
     if (count($this->actions()) > 0) {
         $availableActions = $availableActions + array_keys($this->actions());
     }
     $menus = [];
     foreach ($availableActions as $actionName) {
         $routeId = Inflector::camel2id(substr($actionName, strlen('action')));
         $menus[] = Html::a($actionName, [$routeId]);
     }
     echo implode('<br/>', $menus);
 }
开发者ID:cjq,项目名称:yii2-playground,代码行数:25,代码来源:SsdbController.php

示例3: env

 /**
  * Gets the value of an environment variable. Supports boolean, empty and null.
  *
  * @param  string $key
  * @param  mixed  $default
  * @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;
         case 'false':
         case '(false)':
             return false;
         case 'empty':
         case '(empty)':
             return '';
         case 'null':
         case '(null)':
             return;
     }
     if (strlen($value) > 1 && Str::startsWith($value, '"') && Str::endsWith($value, '"')) {
         return substr($value, 1, -1);
     }
     return $value;
 }
开发者ID:delagics,项目名称:yii2-app-another,代码行数:32,代码来源:helpers.php

示例4: up

 public function up()
 {
     $this->execute('ALTER TABLE galaxysss_1.gs_unions_office ADD category VARCHAR(100) NULL;');
     $path = Yii::getAlias('@app/app/assets/1.xml');
     $data = file_get_contents($path);
     $x = new \DOMDocument();
     $x->loadXML($data);
     $ret = [];
     /** @var \DOMElement $element */
     foreach ($x->documentElement->childNodes as $element) {
         if ($element instanceof \DOMElement) {
             $data = $element->getAttribute('data-jmapping');
             $pos = Str::pos('lat', $data);
             $pos1 = Str::pos('lng', $data);
             $lat = Str::sub($data, $pos + 5, $pos1 - $pos - 7);
             $pos = Str::pos('lng', $data);
             $pos1 = Str::pos('category', $data);
             $lng = Str::sub($data, $pos + 5, $pos1 - $pos - 8);
             $pos = Str::pos('category', $data);
             $category = Str::sub($data, $pos + 11);
             $category = Str::sub($category, 0, Str::length($category) - 2);
             $category = explode('|', $category);
             $list = $element->getElementsByTagName("p");
             if ($list->length == 1) {
                 /** @var \DOMElement $content */
                 $content = $list->item(0);
                 $content = $x->saveXML($content);
                 $content = Str::sub($content, 3);
                 $content = Str::sub($content, 0, Str::length($content) - 4);
                 $content = explode('<br/>', $content);
                 $ret2 = [];
                 foreach ($content as $item) {
                     if (StringHelper::startsWith($item, '<b>')) {
                         $item = Str::sub($item, 3);
                         $item = Str::sub($item, 0, Str::length($item) - 4);
                     }
                     $ret2[] = trim($item);
                 }
                 $name = $ret2[0];
                 array_shift($ret2);
                 if (StringHelper::startsWith($ret2[count($ret2) - 1], 'Открытие')) {
                     $ret2 = array_reverse($ret2);
                     array_shift($ret2);
                     $ret2 = array_reverse($ret2);
                 }
                 if (StringHelper::startsWith($ret2[count($ret2) - 1], '"ВкусВилл')) {
                     $ret2 = array_reverse($ret2);
                     array_shift($ret2);
                     $ret2 = array_reverse($ret2);
                 }
                 $address = $ret2[0];
                 array_shift($ret2);
                 $ret[] = [392, $address, $name, $lat, $lng, join('|', $category), Html::tag('p', join('<br/>', $ret2))];
             }
         }
     }
     $this->batchInsert('gs_unions_office', ['union_id', 'point_address', 'name', 'point_lat', 'point_lng', 'category', 'content'], $ret);
 }
开发者ID:Makeyko,项目名称:galaxysss,代码行数:58,代码来源:m150701_072142_office.php

示例5: __get

 public function __get($name)
 {
     if (\yii\helpers\StringHelper::startsWith($name, 'id')) {
         $id = (int) substr($name, 2);
         if (is_null($this->id)) {
             return null;
         }
         return \yii\helpers\ArrayHelper($this->id, $id, null);
     }
 }
开发者ID:Makeyko,项目名称:galaxysss,代码行数:10,代码来源:Investigator.php

示例6: actionIndex

 /**
  * @hass-todo
  */
 public function actionIndex()
 {
     $namespaces = \HassClassLoader::getHassCoreFile();
     $result = [];
     foreach ($namespaces as $namespace => $dir) {
         $controllerDir = $dir . DIRECTORY_SEPARATOR . "controllers";
         if (!is_dir($controllerDir)) {
             continue;
         }
         $files = FileHelper::findFiles($controllerDir);
         $moduleId = trim(substr($namespace, strrpos(rtrim($namespace, "\\"), "\\")), "\\");
         $result[$moduleId]["module"] = $moduleId;
         $result[$moduleId]["permissions"] = [];
         foreach ($files as $file) {
             $childDir = rtrim(pathinfo(substr($file, strpos($file, "controllers") + 12), PATHINFO_DIRNAME), ".");
             if ($childDir) {
                 $class = $namespace . "controllers\\" . str_replace("/", "\\", $childDir) . "\\" . rtrim(basename($file), ".php");
             } else {
                 $class = $namespace . "controllers\\" . rtrim(basename($file), ".php");
             }
             $controllerId = Inflector::camel2id(str_replace("Controller", "", pathinfo($file, PATHINFO_FILENAME)));
             $reflect = new \ReflectionClass($class);
             $methods = $reflect->getMethods(\ReflectionMethod::IS_PUBLIC);
             /** @var \ReflectionMethod $method */
             foreach ($methods as $method) {
                 if (!StringHelper::startsWith($method->name, "action")) {
                     continue;
                 }
                 if ($method->name == "actions") {
                     $object = \Yii::createObject(["class" => $class], [$controllerId, $moduleId]);
                     $actions = $method->invoke($object);
                     foreach ($actions as $actionId => $config) {
                         $route = $moduleId . "/" . $controllerId . "/" . $actionId;
                         if ($childDir) {
                             $route = $moduleId . "/" . $childDir . "/" . $controllerId . "/" . $actionId;
                         }
                         $result[$moduleId]["permissions"][$route] = ["type" => Item::TYPE_PERMISSION, "description" => $controllerId . "-" . Inflector::camel2words($actionId)];
                     }
                     continue;
                 }
                 $actionId = Inflector::camel2id(substr($method->name, 6));
                 $route = $moduleId . "/" . $controllerId . "/" . $actionId;
                 if ($childDir) {
                     $route = $moduleId . "/" . $childDir . "/" . $controllerId . "/" . $actionId;
                 }
                 $result[$moduleId]["permissions"][$route] = ["type" => Item::TYPE_PERMISSION, "description" => $controllerId . "-" . Inflector::camel2words(substr($method->name, 6))];
             }
         }
     }
     $result["super"] = ['module' => 'SUPER_PERMISSION', 'permissions' => array(\hass\rbac\Module::SUPER_PERMISSION => array('type' => Item::TYPE_PERMISSION, 'description' => 'SUPER_PERMISSION'))];
     $result = "<?php \n return " . var_export($result, true) . ";";
     file_put_contents(dirname(__DIR__) . "/permissions.php", $result);
     return $this->render("index");
 }
开发者ID:rocketyang,项目名称:hasscms-app,代码行数:57,代码来源:ToolController.php

示例7: __construct

 /**
  * Constructor
  *
  * @param string $pathName
  * @param BaseRepository $repository
  * @param string|null $status file status in revision
  *
  * @throws CommonException
  */
 public function __construct($pathName, BaseRepository $repository, $status = null)
 {
     $this->name = basename($pathName);
     $this->path = FileHelper::normalizePath($pathName);
     // first character for status
     $this->status = !is_null($status) ? substr($status, 0, 1) : $status;
     $this->repository = $repository;
     if (!StringHelper::startsWith($this->path, $repository->getProjectPath())) {
         throw new CommonException("Path {$this->path} outband of repository");
     }
     $this->relativePath = substr($this->path, strlen($repository->getProjectPath()));
     parent::__construct([]);
 }
开发者ID:kalyabin,项目名称:yii2-vcs-common,代码行数:22,代码来源:File.php

示例8: actionIndex

 public function actionIndex()
 {
     if (count(Yii::$app->request->post()) > 0) {
         $formValues = Yii::$app->request->post((new Investigator())->formName());
         $add = [];
         $skip = [];
         foreach ($formValues as $name => $value) {
             if (StringHelper::startsWith($name, 'id')) {
                 $id = substr($name, 2);
                 foreach (Yii::$app->session->get('items') as $sessionItem) {
                     if ($sessionItem['id'] == $id) {
                         switch ($value) {
                             // пропустить
                             case 1:
                                 $skip[] = $sessionItem['id'];
                                 break;
                                 // добавить
                             // добавить
                             case 2:
                                 $add[] = $sessionItem['id'];
                                 break;
                         }
                     }
                 }
             }
         }
         if (count($skip) > 0) {
             (new Query())->createCommand()->update(Inv::TABLE, ['status' => Inv::STATUS_SKIP], ['in', 'id', $skip])->execute();
         }
         foreach ($add as $item) {
             $i = Inv::find($item);
             $class = $i->getField('class_name');
             // послание
             /** @var \app\services\investigator\InvestigatorInterface $class */
             $class = new $class();
             $extractor = $class->getItem($i->getField('url'));
             // добавляю
             Chenneling::insertExtractorInterface($extractor);
         }
         if (count($add) > 0) {
             (new Query())->createCommand()->update(Inv::TABLE, ['status' => Inv::STATUS_ADD], ['in', 'id', $add])->execute();
         }
         Yii::$app->session->remove('items');
         Yii::$app->session->setFlash('contactFlash');
         return $this->render([]);
     } else {
         $items = \app\models\Investigator::query(['status' => \app\models\Investigator::STATUS_NEW])->select(['class_name as class', 'id', 'url', 'date_insert', 'status', 'name'])->all();
         Yii::$app->session->set('items', $items);
         return $this->render(['items' => $items]);
     }
 }
开发者ID:Makeyko,项目名称:galaxysss,代码行数:51,代码来源:Admin_investigatorController.php

示例9: initialize

 /**
  * @inheritdoc
  */
 protected function initialize($rows)
 {
     $diffId = null;
     $this->previousFilePath = self::NULL_PATH;
     $this->newFilePath = self::NULL_PATH;
     foreach ($rows as $n => $row) {
         if ($n >= 0 && $n <= 2) {
             // first 3 lines are description
             if (trim($this->description)) {
                 $this->description .= PHP_EOL . $row;
             } else {
                 $this->description = $row;
             }
             if (StringHelper::startsWith($row, 'Binary files')) {
                 // stop parsing if diff is binary
                 $this->isBinary = true;
                 break;
             }
             // old or new file path
             $matches = [];
             if (preg_match('#^\\-\\-\\-[\\s]a(.*)$#i', $row, $matches)) {
                 $this->previousFilePath = $matches[1];
             } else {
                 if (preg_match('#^\\+\\+\\+[\\s]b(.*)$#i', $row, $matches)) {
                     $this->newFilePath = $matches[1];
                 }
             }
         } else {
             if ($n == 3 && StringHelper::startsWith($row, 'GIT binary patch')) {
                 // stop parsing if diff is binary
                 $this->isBinary = true;
                 break;
             } else {
                 if (StringHelper::startsWith($row, '@@')) {
                     // new diff line
                     $diffId = $row;
                     $matches = [];
                     $pattern = '#^@@[\\s]\\-([\\d]+),?([\\d]+)?[\\s]\\+([\\d]+),?([\\d]+)?[\\s]@@#i';
                     preg_match($pattern, $row, $matches);
                     $this->lines[$diffId] = ['beginA' => isset($matches[1]) ? (int) $matches[1] : 1, 'beginB' => isset($matches[3]) ? (int) $matches[3] : 1, 'cntA' => isset($matches[2]) ? (int) $matches[2] : 0, 'cntB' => isset($matches[4]) ? (int) $matches[4] : 0, 'lines' => []];
                 } else {
                     if ($diffId && isset($this->lines[$diffId])) {
                         // changed row
                         $this->lines[$diffId]['lines'][] = $row;
                     }
                 }
             }
         }
     }
 }
开发者ID:kalyabin,项目名称:yii2-hg-view,代码行数:53,代码来源:Diff.php

示例10: getContentAsArray

 /**
  * Возвращает массив чистых строк без тегов
  *
  * @return array
  */
 public function getContentAsArray()
 {
     $html = $this->getObjArticle();
     $ret = [];
     foreach ($html->find('div.td-post-text-content/p') as $p) {
         if ($p instanceof \simple_html_dom_node) {
             if ($p->children[0]->tag != 'noindex') {
                 $string = trim($p->plaintext);
                 if (StringHelper::startsWith($string, '&nbsp;')) {
                     $string = Str::sub($string, 6);
                 }
                 $ret[] = $string;
             }
         }
     }
     return $ret;
 }
开发者ID:Makeyko,项目名称:galaxysss,代码行数:22,代码来源:Verhosvet.php

示例11: beforeAction

 public function beforeAction($action)
 {
     if (!parent::beforeAction($action)) {
         return false;
     }
     $get = Yii::$app->request->get();
     $filterParams = array_filter($get, function ($val, $key) {
         return StringHelper::startsWith($key, self::FILTER_GET_TAG);
     }, ARRAY_FILTER_USE_BOTH);
     //        $filterNames = array_map(function($val){
     //            return substr($val, strlen(self::FILTER_GET_TAG));
     //        }, $filterParams);
     foreach ($filterParams as $key => $value) {
         $this->addFilter($key, $value);
     }
     return true;
 }
开发者ID:Polymedia,项目名称:BI-Platform-v3,代码行数:17,代码来源:BaseDashboardController.php

示例12: update2

 public function update2($id)
 {
     $item = parent::update();
     $item['id'] = $id;
     $class = new \app\models\SubscribeHistory($item);
     $content = $class->getField('content');
     require_once Yii::getAlias('@csRoot/services/simplehtmldom_1_5/simple_html_dom.php');
     $content = str_get_html($content);
     foreach ($content->find('img') as $element) {
         $src = $element->attr['src'];
         if (StringHelper::startsWith($src, 'http') == false) {
             $element->attr['src'] = Url::to($src, true);
         }
     }
     $content = $content->root->outertext();
     $class->setContent($content);
     return $item;
 }
开发者ID:Makeyko,项目名称:galaxysss,代码行数:18,代码来源:SubscribeHistory.php

示例13: actionRaw

 /**
  * View project path tree or raw project file
  *
  * @param string|null $path Relative project path (null if root)
  */
 public function actionRaw($path = null)
 {
     $absolutePath = FileHelper::normalizePath($this->repository->getProjectPath() . DIRECTORY_SEPARATOR . $path);
     if (!StringHelper::startsWith($absolutePath, $this->repository->getProjectPath()) || !file_exists($absolutePath)) {
         throw new NotFoundHttpException();
     }
     $breadcrumbs = $this->generateBreadcrumbs($path);
     if (is_dir($absolutePath)) {
         // render path tree
         $filesList = $this->repository->getFilesList($path);
         return $this->render('tree', ['project' => $this->project, 'repository' => $this->repository, 'filesList' => $filesList, 'breadcrumbs' => $breadcrumbs]);
     } else {
         if (is_file($absolutePath)) {
             // render raw file
             $fileContents = file_get_contents($absolutePath);
             return $this->render('raw', ['repository' => $this->repository, 'project' => $this->project, 'breadcrumbs' => $breadcrumbs, 'fileContents' => $fileContents]);
         }
     }
     // if else - 404
     throw new NotFoundHttpException();
 }
开发者ID:kalyabin,项目名称:comitka,代码行数:26,代码来源:TreeController.php

示例14: run

 /**
  * Render file view.
  * If has CommonException - it's may by only not found commit, or not found file in project path.
  *
  * @return array
  * @throws NotFoundHttpException
  */
 public function run()
 {
     /* @var $commit BaseCommit */
     $commit = null;
     /* @var $fileDiff BaseDiff[] */
     $fileDiff = [];
     /* @var $fileContents string */
     $fileContents = '';
     $isBinary = false;
     try {
         // get commit model by commit identifier
         $commit = $this->repository->getCommit($this->commitId);
         $fileDiff = $commit->getDiff($this->filePath);
         $isBinary = isset($fileDiff[0]) && $fileDiff[0]->getIsBinary();
         if ($this->mode === self::MODE_RAW_BINARY && $isBinary) {
             // returns raw binary file
             $images = ['png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif'];
             $pathinfo = pathinfo($this->filePath);
             $mimeType = isset($images[strtolower($pathinfo['extension'])]) ? $images[strtolower($pathinfo['extension'])] : 'application/octet-stream';
             if (!StringHelper::startsWith($mimeType, 'image/')) {
                 header('Content-Description: File Transfer');
                 header('Content-Disposition: attachment; filename=' . basename($this->filePath));
             }
             header('Content-Type: ' . $mimeType);
             header('Content-Transfer-Encoding: binary');
             header('Expires: 0');
             header('Cache-Control: must-revalidate');
             header('Pragma: public');
             $commit->getRawBinaryFile($this->filePath, function ($data) {
                 print $data;
                 flush();
             });
             exit;
         } elseif ($this->mode === self::MODE_RAW && $commit->getFileStatus($this->filePath) != File::STATUS_DELETION) {
             // modified file
             $fileContents = $isBinary ? '' : $commit->getRawFile($this->filePath);
         } elseif ($this->mode === self::MODE_RAW) {
             // moved file
             $fileContents = $isBinary ? '' : $commit->getPreviousRawFile($this->filePath);
         }
     } catch (CommonException $ex) {
         throw new ServerErrorHttpException(Yii::t('app', 'System error: {message}', ['message' => $ex->getMessage()]), $ex->getCode(), $ex);
     }
     $viewFile = null;
     switch ($this->mode) {
         case self::MODE_DIFF:
             $viewFile = $isBinary ? 'file_raw' : 'file_diff';
             break;
         case self::MODE_COMPARE:
             $viewFile = $isBinary ? 'file_raw' : 'file_compare';
             break;
         case self::MODE_RAW:
             $viewFile = 'file_raw';
             break;
         default:
             throw new NotFoundHttpException();
     }
     return ['diff' => Yii::t('project', 'Revision') . ': ' . $commit->getId(), 'html' => $this->controller->renderAjax('commit/' . $viewFile, ['project' => $this->project, 'commit' => $commit, 'diffs' => $fileDiff, 'fileContents' => $fileContents, 'path' => $this->filePath, 'isBinary' => $isBinary])];
 }
开发者ID:kalyabin,项目名称:comitka,代码行数:66,代码来源:FileViewAction.php

示例15: formatAmount

 /**
  * Format the given amount into a displayable currency.
  *
  * @param int $amount
  *
  * @return string
  */
 public static function formatAmount($amount)
 {
     if (static::$formatCurrencyUsing) {
         return call_user_func(static::$formatCurrencyUsing, $amount);
     }
     $amount = number_format($amount / 100, 2);
     if (StringHelper::startsWith($amount, '-')) {
         return '-' . static::usesCurrencySymbol() . ltrim($amount, '-');
     }
     return static::usesCurrencySymbol() . $amount;
 }
开发者ID:yii2mod,项目名称:yii2-cashier,代码行数:18,代码来源:Cashier.php


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