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


PHP helpers\StringHelper类代码示例

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


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

示例1: bOrderAttr

 public static function bOrderAttr()
 {
     if (is_null(static::$b_order_attr)) {
         static::$b_order_attr = Inflector::camel2id(StringHelper::basename(static::bClass()), '_') . '_ord';
     }
     return static::$b_order_attr;
 }
开发者ID:omidonix,项目名称:yii2-sortable-behavior,代码行数:7,代码来源:PivotRecord.php

示例2: upload

 public function upload($attribute)
 {
     $class = \yii\helpers\StringHelper::basename(get_class($this->owner)) . 'Cutter';
     if ($uploadImage = UploadedFile::getInstance($this->owner, $attribute)) {
         if (!$this->owner->isNewRecord) {
             $this->delete($attribute);
         }
         $cropping = $_POST[$class][$attribute . '-cropping'];
         $croppingFileName = md5($uploadImage->name . $this->quality . Json::encode($cropping));
         $croppingFileExt = strrchr($uploadImage->name, '.');
         $croppingFileDir = substr($croppingFileName, 0, 2);
         $croppingFileBasePath = Yii::getAlias($this->basePath) . $this->baseDir;
         if (!is_dir($croppingFileBasePath)) {
             mkdir($croppingFileBasePath, 0755, true);
         }
         $croppingFilePath = Yii::getAlias($this->basePath) . $this->baseDir . DIRECTORY_SEPARATOR . $croppingFileDir;
         if (!is_dir($croppingFilePath)) {
             mkdir($croppingFilePath, 0755, true);
         }
         $fileSavePath = $croppingFilePath . DIRECTORY_SEPARATOR . $croppingFileName . $croppingFileExt;
         $point = new Point($cropping['dataX'], $cropping['dataY']);
         $box = new Box($cropping['dataWidth'], $cropping['dataHeight']);
         $palette = new \Imagine\Image\Palette\RGB();
         $color = $palette->color('fff', 0);
         Image::frame($uploadImage->tempName, 0, 'fff', 0)->rotate($cropping['dataRotate'], $color)->crop($point, $box)->save($fileSavePath, ['quality' => $this->quality]);
         $this->owner->{$attribute} = $this->baseDir . DIRECTORY_SEPARATOR . $croppingFileDir . DIRECTORY_SEPARATOR . $croppingFileName . $croppingFileExt;
     } elseif (isset($_POST[$class][$attribute . '-remove']) && $_POST[$class][$attribute . '-remove']) {
         $this->delete($attribute);
     } elseif (!empty($_POST[$class][$attribute])) {
         $this->owner->{$attribute} = $_POST[$class][$attribute];
     } elseif (isset($this->owner->oldAttributes[$attribute])) {
         $this->owner->{$attribute} = $this->owner->oldAttributes[$attribute];
     }
 }
开发者ID:sadovojav,项目名称:yii2-image-cutter,代码行数:34,代码来源:CutterBehavior.php

示例3: actionConvert

 /**
  * Convert display date for saving to model
  *
  * @return string JSON encoded HTML output
  */
 public function actionConvert()
 {
     $output = '';
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $post = Yii::$app->request->post();
     if (isset($post['displayDate'])) {
         $saveFormat = ArrayHelper::getValue($post, 'saveFormat');
         $dispFormat = ArrayHelper::getValue($post, 'dispFormat');
         $dispTimezone = ArrayHelper::getValue($post, 'dispTimezone');
         $saveTimezone = ArrayHelper::getValue($post, 'saveTimezone');
         $settings = ArrayHelper::getValue($post, 'settings', []);
         // Russian dates ends with \r. - i dont know why
         if (StringHelper::endsWith($dispFormat, '.')) {
             $dispFormat = substr($dispFormat, 0, strlen($dispFormat) - 4);
             $post['displayDate'] = substr($post['displayDate'], 0, strlen($post['displayDate']) - 4);
         }
         if (ArrayHelper::getValue($post, 'type') != DateControl::FORMAT_DATETIME) {
             $dispTimezone = null;
             $saveTimezone = null;
         }
         $date = DateControl::getTimestamp($post['displayDate'], $dispFormat, $dispTimezone, $settings);
         if (empty($date) || !$date) {
             $value = '';
         } elseif ($saveTimezone != null) {
             $value = $date->setTimezone(new DateTimeZone($saveTimezone))->format($saveFormat);
         } else {
             $value = $date->format($saveFormat);
         }
         return ['status' => 'success', 'output' => $value];
     } else {
         return ['status' => 'error', 'output' => 'No display date found'];
     }
 }
开发者ID:alexsuter,项目名称:yii2-datecontrol,代码行数:38,代码来源:ParseController.php

示例4: tableName

 /**
  * @inheritdoc
  */
 public static function tableName()
 {
     $name = Inflector::camel2id(StringHelper::basename(get_called_class()), '_');
     $length = mb_strlen($name, \Yii::$app->charset) - 7;
     // - mb_strlen('_record', Yii::$app->charset);
     return '{{%' . trim(mb_substr($name, 0, $length, \Yii::$app->charset)) . '}}';
 }
开发者ID:just-leo,项目名称:cardgame-serial,代码行数:10,代码来源:ActiveRecord.php

示例5: buildXml

 /**
  * @param DOMElement $element
  * @param mixed $data
  */
 protected function buildXml($element, $data)
 {
     if (is_object($data)) {
         $child = new DOMElement(StringHelper::basename(get_class($data)));
         $element->appendChild($child);
         if ($data instanceof Arrayable) {
             $this->buildXml($child, $data->toArray());
         } else {
             $array = [];
             foreach ($data as $name => $value) {
                 $array[$name] = $value;
             }
             $this->buildXml($child, $array);
         }
     } elseif (is_array($data)) {
         foreach ($data as $name => $value) {
             if (is_int($name) && is_object($value)) {
                 $this->buildXml($element, $value);
             } elseif (is_array($value) || is_object($value)) {
                 $child = new DOMElement(is_int($name) ? $this->itemTag : $name);
                 $element->appendChild($child);
                 $this->buildXml($child, $value);
             } else {
                 $child = new DOMElement(is_int($name) ? $this->itemTag : $name);
                 $element->appendChild($child);
                 $child->appendChild(new DOMText((string) $value));
             }
         }
     } else {
         $element->appendChild(new DOMText((string) $data));
     }
 }
开发者ID:Jaaviieer,项目名称:PrograWeb,代码行数:36,代码来源:XmlResponseFormatter.php

示例6: checkForNews

 private function checkForNews()
 {
     try {
         $response = (new Client())->createRequest()->setUrl($this->getCurrentFeed()->url)->send();
         if (!$response->isOk) {
             throw new \Exception();
         }
         $rss = simplexml_load_string($response->getContent());
         $newItemsCount = 0;
         foreach ($rss->channel->item as $item) {
             if (!NewModel::findOne(['feed' => $this->getCurrentFeed()->id, 'url' => (string) $item->link])) {
                 $new = new NewModel();
                 $new->feed = $this->getCurrentFeed()->id;
                 $new->published_at = date_create_from_format(\DateTime::RSS, (string) $item->pubDate)->format('Y-m-d H:i:s');
                 $new->title = (string) $item->title;
                 if (isset($item->description)) {
                     $new->short_text = StringHelper::truncate(strip_tags((string) $item->description), 250);
                 }
                 $new->url = (string) $item->link;
                 if ($new->save()) {
                     $newItemsCount++;
                 }
             }
         }
         if ($newItemsCount > 0) {
             \Yii::$app->session->addFlash('info', \Yii::t('user', 'Get news: ') . $newItemsCount);
             $this->clearOldNewsIfNeed();
             \Yii::$app->cache->delete($this->getNewsCacheKey());
             \Yii::$app->cache->delete($this->getFeedsCacheKey());
         }
     } catch (Exception $e) {
         \Yii::$app->session->addFlash('danger', \Yii::t('user', 'Get news error'));
     }
 }
开发者ID:atoumus,项目名称:yii2-rss-reader-example,代码行数:34,代码来源:ListAction.php

示例7: makeRestoreCommand

 /**
  * @param $path
  * @param array $dbInfo
  * @param array $restoreOptions
  * @return string
  */
 public function makeRestoreCommand($path, array $dbInfo, array $restoreOptions)
 {
     $arguments = [];
     if (StringHelper::endsWith($path, '.gz', false)) {
         $arguments[] = 'gunzip -c';
         $arguments[] = $path;
         $arguments[] = '|';
     }
     if ($this->isWindows()) {
         $arguments[] = 'set PGPASSWORD=' . $dbInfo['password'];
         $arguments[] = '&';
     } else {
         $arguments[] = 'PGPASSWORD=' . $dbInfo['password'];
     }
     // default port
     if (empty($dbInfo['port'])) {
         $dbInfo['port'] = '5432';
     }
     $arguments = array_merge($arguments, ['psql', '--host=' . $dbInfo['host'], '--port=' . $dbInfo['port'], '--username=' . $dbInfo['username'], '--no-password']);
     if ($restoreOptions['preset']) {
         $arguments[] = trim($restoreOptions['presetData']);
     }
     $arguments[] = $dbInfo['dbName'];
     if (!StringHelper::endsWith($path, '.gz', false)) {
         $arguments[] = '<';
         $arguments[] = $path;
     }
     return implode(' ', $arguments);
 }
开发者ID:beaten-sect0r,项目名称:yii2-db-manager,代码行数:35,代码来源:PostgresDumpManager.php

示例8: __construct

 /**
  * @param \phpDocumentor\Reflection\BaseReflector $reflector
  * @param Context $context
  * @param array $config
  */
 public function __construct($reflector = null, $context = null, $config = [])
 {
     parent::__construct($config);
     if ($reflector === null) {
         return;
     }
     // base properties
     $this->name = ltrim($reflector->getName(), '\\');
     $this->startLine = $reflector->getNode()->getAttribute('startLine');
     $this->endLine = $reflector->getNode()->getAttribute('endLine');
     $docblock = $reflector->getDocBlock();
     if ($docblock !== null) {
         $this->shortDescription = ucfirst($docblock->getShortDescription());
         if (empty($this->shortDescription) && !$this instanceof PropertyDoc && $context !== null && $docblock->getTagsByName('inheritdoc') === null) {
             $context->errors[] = ['line' => $this->startLine, 'file' => $this->sourceFile, 'message' => "No short description for " . substr(StringHelper::basename(get_class($this)), 0, -3) . " '{$this->name}'"];
         }
         $this->description = $docblock->getLongDescription()->getContents();
         $this->phpDocContext = $docblock->getContext();
         $this->tags = $docblock->getTags();
         foreach ($this->tags as $i => $tag) {
             if ($tag instanceof SinceTag) {
                 $this->since = $tag->getVersion();
                 unset($this->tags[$i]);
             } elseif ($tag instanceof DeprecatedTag) {
                 $this->deprecatedSince = $tag->getVersion();
                 $this->deprecatedReason = $tag->getDescription();
                 unset($this->tags[$i]);
             }
         }
     } elseif ($context !== null) {
         $context->errors[] = ['line' => $this->startLine, 'file' => $this->sourceFile, 'message' => "No docblock for element '{$this->name}'"];
     }
 }
开发者ID:136216444,项目名称:yii2-apidoc,代码行数:38,代码来源:BaseDoc.php

示例9: testTruncateWords

 public function testTruncateWords()
 {
     $this->assertEquals('это тестовая multibyte строка', StringHelper::truncateWords('это тестовая multibyte строка', 5));
     $this->assertEquals('это тестовая multibyte...', StringHelper::truncateWords('это тестовая multibyte строка', 3));
     $this->assertEquals('это тестовая multibyte!!!', StringHelper::truncateWords('это тестовая multibyte строка', 3, '!!!'));
     $this->assertEquals('это строка с          неожиданными...', StringHelper::truncateWords('это строка с          неожиданными пробелами', 4));
 }
开发者ID:sciurodont,项目名称:yii2,代码行数:7,代码来源:StringHelperTest.php

示例10: rules

 public function rules()
 {
     return [[['type_in', 'hdomain_id_in'], 'filter', 'filter' => function ($value) {
         $res = StringHelper::explode($value, ',', true, true);
         return $res;
     }, 'skipOnArray' => true, 'on' => ['export-hosts']], [['type_in'], 'default', 'value' => ['a', 'aaaa'], 'on' => ['export-hosts']], [['type_in'], 'each', 'rule' => ['in', 'range' => array_keys($this->getTypes())], 'on' => ['export-hosts']], [['hdomain_id_in'], 'required', 'on' => ['export-hosts']]];
 }
开发者ID:hiqdev,项目名称:hipanel-module-dns,代码行数:7,代码来源:RecordSearch.php

示例11: init

 public function init()
 {
     if (!$this->modelName) {
         $this->modelName = StringHelper::basename(get_class($this), 'Controller');
     }
     if (!$this->modelClass) {
         $modelClass = 'app\\models\\' . $this->modelName;
         if (class_exists($modelClass)) {
             $this->modelClass = $modelClass;
         } else {
             $modelClass = 'app\\models\\readonly\\' . $this->modelName;
             if (class_exists($modelClass)) {
                 $this->modelClass = $modelClass;
             }
         }
     }
     if (!$this->filterModelClass) {
         $filterModelClass = 'app\\models\\search\\' . $this->modelName . 'Search';
         if (class_exists($filterModelClass)) {
             $this->filterModelClass = $filterModelClass;
         } else {
             $filterModelClass = 'app\\models\\readonly\\search\\' . $this->modelName . 'Search';
             if (class_exists($filterModelClass)) {
                 $this->filterModelClass = $filterModelClass;
             }
         }
     }
     parent::init();
 }
开发者ID:ivan-chkv,项目名称:yii2-mozayka,代码行数:29,代码来源:ActiveController.php

示例12: 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

示例13: Preview

 public static function Preview($models)
 {
     foreach ($models as $key => $model) {
         $models[$key]['text'] = StringHelper::truncate(strip_tags($model['text']), 400);
     }
     return $models;
 }
开发者ID:developer-av,项目名称:yii2-blog,代码行数:7,代码来源:Posts.php

示例14: testBasename

 public function testBasename()
 {
     $this->assertEquals('', StringHelper::basename(''));
     $this->assertEquals('file', StringHelper::basename('file'));
     $this->assertEquals('file.test', StringHelper::basename('file.test', '.test2'));
     $this->assertEquals('file', StringHelper::basename('file.test', '.test'));
     $this->assertEquals('file', StringHelper::basename('/file'));
     $this->assertEquals('file.test', StringHelper::basename('/file.test', '.test2'));
     $this->assertEquals('file', StringHelper::basename('/file.test', '.test'));
     $this->assertEquals('file', StringHelper::basename('/path/to/file'));
     $this->assertEquals('file.test', StringHelper::basename('/path/to/file.test', '.test2'));
     $this->assertEquals('file', StringHelper::basename('/path/to/file.test', '.test'));
     $this->assertEquals('file', StringHelper::basename('\\file'));
     $this->assertEquals('file.test', StringHelper::basename('\\file.test', '.test2'));
     $this->assertEquals('file', StringHelper::basename('\\file.test', '.test'));
     $this->assertEquals('file', StringHelper::basename('C:\\file'));
     $this->assertEquals('file.test', StringHelper::basename('C:\\file.test', '.test2'));
     $this->assertEquals('file', StringHelper::basename('C:\\file.test', '.test'));
     $this->assertEquals('file', StringHelper::basename('C:\\path\\to\\file'));
     $this->assertEquals('file.test', StringHelper::basename('C:\\path\\to\\file.test', '.test2'));
     $this->assertEquals('file', StringHelper::basename('C:\\path\\to\\file.test', '.test'));
     // mixed paths
     $this->assertEquals('file.test', StringHelper::basename('/path\\to/file.test'));
     $this->assertEquals('file.test', StringHelper::basename('/path/to\\file.test'));
     $this->assertEquals('file.test', StringHelper::basename('\\path/to\\file.test'));
     // \ and / in suffix
     $this->assertEquals('file', StringHelper::basename('/path/to/filete/st', 'te/st'));
     $this->assertEquals('st', StringHelper::basename('/path/to/filete/st', 'te\\st'));
     $this->assertEquals('file', StringHelper::basename('/path/to/filete\\st', 'te\\st'));
     $this->assertEquals('st', StringHelper::basename('/path/to/filete\\st', 'te/st'));
     // http://www.php.net/manual/en/function.basename.php#72254
     $this->assertEquals('foo', StringHelper::basename('/bar/foo/'));
     $this->assertEquals('foo', StringHelper::basename('\\bar\\foo\\'));
 }
开发者ID:rajanishtimes,项目名称:basicyii,代码行数:34,代码来源:StringHelperTest.php

示例15: getMetaData

 public function getMetaData()
 {
     $model = $this->getMetaModel();
     $title = $model->title ?: $this->title;
     $description = $model->description ?: StringHelper::truncate(strip_tags($this->content), 200);
     return [$title, $description, $model->keywords];
 }
开发者ID:rocketyang,项目名称:hasscms-app,代码行数:7,代码来源:Page.php


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