本文整理汇总了PHP中yii\helpers\StringHelper::explode方法的典型用法代码示例。如果您正苦于以下问题:PHP StringHelper::explode方法的具体用法?PHP StringHelper::explode怎么用?PHP StringHelper::explode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\StringHelper
的用法示例。
在下文中一共展示了StringHelper::explode方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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']]];
}
示例2: locationStringToGeometry
public static function locationStringToGeometry($location)
{
if (preg_match('/^(\\-?\\d+(\\.\\d+)?),(\\-?\\d+(\\.\\d+)?)$/', $location, $match)) {
$location = \yii\helpers\StringHelper::explode($location, ',');
return self::getPostgisFormatByCoordinate($location[0], $location[1]);
}
return null;
}
示例3: getFiles
protected function getFiles()
{
$value = $this->model[$this->attribute] ?: [];
if (empty($value)) {
return [];
}
if (is_string($value)) {
$value = StringHelper::explode($value);
}
$value = $this->multiple ? $value : [$value[0]];
return array_map(function ($fileModel) {
/** @var File $fileModel */
return $fileModel->getExtendedAttributes();
}, File::findAll($value));
}
示例4: beforeAction
public function beforeAction($action)
{
$route = Yii::$app->requestedRoute;
if ($this->identity) {
if ($this->identity->is_super) {
$allowAccess = true;
} else {
// 权限验证
$userMenuIdList = [];
$groupMenuIdList = [];
if ($this->identity->is_user_access) {
// 用户权限列表
$userMenuIdList = DpAdminUserMenuRelation::getAllMenuIdArrByUserId($this->identity->user_id);
}
if ($this->identity->is_group_access) {
// 用户组权限列表
$groupMenuIdList = DpAdminGroup::getMenuIdArrByGroupIdArr($this->identity->getGroupIdArr());
}
$this->menuIdList = array_merge($userMenuIdList, $groupMenuIdList);
$routeWhiteList = ['', 'admin/common/tree', 'admin/common/urls', 'admin/public/logout'];
$allowAccess = in_array($route, $routeWhiteList);
if (!$allowAccess) {
$queryParams = Yii::$app->request->queryParams;
$method = Yii::$app->request->method;
$urlRule = DpAdminMenuUrl::getUrlRuleByMenuIdArr($this->menuIdList);
$allowAccess = !!array_filter($urlRule, function ($item) use($route, $queryParams, $method) {
if (strpos($item['route'], '/') === 0) {
$ruleRoute = substr($item['route'], 1, strlen($item['route']));
} else {
$ruleRoute = $item['route'];
}
if ($ruleRoute == $route) {
// 请求方法验证
if (!in_array($method, StringHelper::explode($item['method'], ',', true, true))) {
return false;
}
if ($item['enable_rule']) {
// get参数规则验证
foreach ($queryParams as $qk => $qv) {
if (isset($item['rule'][$qk])) {
$pattern = '/' . $item['rule'][$qk] . '/';
if (preg_match($pattern, $qv)) {
return true;
}
}
}
return false;
} else {
return true;
}
}
return false;
});
}
}
if (!$allowAccess) {
// 权限不足
$response = Yii::$app->response;
$response->format = Response::FORMAT_JSON;
$response->data = ['success' => false, 'msg' => '权限不足', 'code' => 2];
return false;
} else {
return parent::beforeAction($action);
}
} else {
$routeWhiteList = ['', 'admin/public/login', 'admin/public/logout'];
$allowAccess = in_array($route, $routeWhiteList);
if (!$allowAccess) {
// 未登录
$response = Yii::$app->response;
$response->format = Response::FORMAT_JSON;
$response->data = ['success' => false, 'msg' => '请先登录系统', 'code' => 1];
return false;
}
}
return parent::beforeAction($action);
}
示例5: getFileBetweenCommits
/**
* 获取commit之间的文件
*
* @return array
*/
public function getFileBetweenCommits($branch, $star, $end)
{
// 先更新
$destination = Project::getDeployFromDir();
$this->updateRepo($branch, $destination);
$cmd[] = sprintf('cd %s ', static::getBranchDir($branch, $this->getConfig()->repo_mode == Project::REPO_TAG ?: false));
$cmd[] = $this->_getSvnCmd(sprintf('svn diff -r %d:%d --summarize', $star, $end));
$command = join(' && ', $cmd);
$result = $this->runLocalCommand($command);
if (!$result) {
throw new \Exception('获取提交历史失败:' . $this->getExeLog());
}
$list = [];
$files = StringHelper::explode($this->getExeLog(), PHP_EOL);
$files = array_map(function ($item) {
return trim(substr($item, strpos($item, " ")));
}, $files);
// 排除点文件
if (in_array('.', $files)) {
unset($files[array_search('.', $files)]);
}
foreach ($files as $key => $file) {
// 如果是目录,则目录下的文件则可以不带了
if (in_array(dirname($file), $files)) {
continue;
}
$list[] = $file;
}
return $list;
}
示例6: actionUpdateStatus
/**
* 更新状态
*
* @return array
*/
public function actionUpdateStatus()
{
$ids = \Yii::$app->request->post('ids');
$status = intval(\Yii::$app->request->post('status'));
if ($status != 0) {
$status = 1;
}
foreach (StringHelper::explode($ids, ',', true, true) as $id) {
$obj = DpAdminGroup::find()->findByGroupId($id)->one();
if ($obj) {
$obj->status = $status;
$obj->save();
}
}
return $this->renderSuccess('状态更新成功');
}
示例7: init
public function init()
{
parent::init();
if (is_string($this->data) || is_numeric($this->data)) {
$this->data = StringHelper::explode($this->data);
} elseif ($this->data === null) {
$this->data = [];
}
if (empty($this->mode)) {
$this->mode = static::MODE_POPOVER;
}
if (!is_callable([$this, 'renderButton' . Inflector::id2camel($this->mode)])) {
throw new InvalidValueException('Do not know, how to render button of this type');
}
if (is_string($this->button)) {
$this->button = ['label' => $this->button];
}
$this->button = ArrayHelper::merge(['tag' => 'a', 'id' => $this->id], $this->button);
if (!is_array($this->data)) {
throw new InvalidValueException('Input can not be processed as an array');
}
if (is_callable($this->formatter)) {
$this->data = array_map($this->formatter, $this->data, array_keys($this->data));
}
if (is_callable($this->button['label'])) {
$this->button['label'] = call_user_func($this->button['label'], $this);
}
}
示例8: setHorasHombre
public function setHorasHombre()
{
$horai = StringHelper::explode($this->hora_ini, ':', true, false);
$horaf = StringHelper::explode($this->hora_fin, ':', true, false);
if ($horaf[0] == $horai[0]) {
$this->HH = ($horaf[1] - $horai[1]) / 60;
} else {
$this->HH = (60 * ($horaf[0] - $horai[0]) - $horai[1] + $horaf[1]) / 60;
}
}
示例9: getGroupIdArr
/**
* 获取用户组id数组
*
* @return array
*/
public function getGroupIdArr()
{
$return = [];
if ($this->group_ids) {
$return = array_filter(StringHelper::explode($this->group_ids, ',', true, true), function ($groupId) {
return is_numeric($groupId) && DpAdminGroup::find()->findByGroupId($groupId)->exists();
});
}
return $return;
}
示例10: getFileAndVersionList
/**
* 获取文件和版本号列表
*
* @param TaskModel $task
* @return array
*/
public function getFileAndVersionList(TaskModel $task)
{
$fileList = GlobalHelper::str2arr($task->file_list);
$fileAndVersion = [];
foreach ($fileList as $file) {
list($file, $version) = array_pad(StringHelper::explode($file, ' ', true, true), 2, null);
$fileAndVersion[] = ['file' => $file, 'version' => $version];
}
return $fileAndVersion;
}
示例11: dragSort
/**
* 拖拽排序
*
* @return bool
*/
public function dragSort()
{
if ($this->validate()) {
$menuModel = DpAdminMenu::find()->findByMenuId($this->target_menu_id)->one();
// 调整排序的菜单id
$dropMenuIdArr = array_filter(StringHelper::explode($this->menu_ids, ',', true, true), function ($value) {
return is_numeric($value) && DpAdminMenu::find()->findByMenuId($value)->exists();
});
// 调整排序菜单数量
$dropCount = count($dropMenuIdArr);
if (static::POSITION_BEFORE == $this->position) {
// 节点之前
$menuAllObj = DpAdminMenu::find()->findByParentId($menuModel->parent_id)->orderBy('display_order asc')->all();
// 将要插入的菜单前面的排序向前移动
// 插入的开始排序号
$startOrder = $menuModel->display_order - 1;
$otherStartOrder = $startOrder - $dropCount;
foreach ($menuAllObj as $menuObj) {
if ($menuObj->menu_id == $menuModel->menu_id) {
break;
}
$menuObj->display_order = $otherStartOrder--;
$menuObj->save();
}
$dropStartOrder = $menuModel->display_order - $dropCount;
foreach ($dropMenuIdArr as $menuId) {
$dropMenu = DpAdminMenu::find()->findByMenuId($menuId)->one();
if ($dropMenu) {
$dropMenu->parent_id = $menuModel->parent_id;
$dropMenu->display_order = $dropStartOrder++;
$dropMenu->save();
}
}
return true;
} elseif (static::POSITION_AFTER == $this->position) {
// 节点之后
// 在菜单后插入
$menuAllObj = DpAdminMenu::find()->findByParentId($menuModel->parent_id)->andWhere('menu_id not in (' . join(',', $dropMenuIdArr) . ')')->all();
// 将要插入的菜单后面的排序向后移动
// 插入的开始排序号
$isStartOrder = false;
$startOrder = $menuModel->display_order + 1;
$otherStartOrder = $startOrder + $dropCount;
foreach ($menuAllObj as $menuObj) {
if ($menuObj->menu_id == $menuModel->menu_id) {
$isStartOrder = true;
continue;
}
if (!$isStartOrder) {
continue;
}
$menuObj->display_order = $otherStartOrder++;
$menuObj->save();
}
foreach ($dropMenuIdArr as $menuId) {
$dropMenu = DpAdminMenu::find()->findByMenuId($menuId)->one();
if ($dropMenu) {
$dropMenu->parent_id = $menuModel->parent_id;
$dropMenu->display_order = $startOrder++;
$dropMenu->save();
}
}
return true;
} elseif (static::POSITION_APPEND == $this->position) {
// 节点内
// 添加为子节点
$maxDisplayOrder = DpAdminMenu::find()->findByParentId($menuModel->menu_id)->max('display_order');
foreach ($dropMenuIdArr as $menuId) {
$dropMenu = DpAdminMenu::find()->findByMenuId($menuId)->one();
if ($dropMenu) {
$dropMenu->parent_id = $menuModel->menu_id;
$dropMenu->display_order = ++$maxDisplayOrder;
$dropMenu->save();
}
}
return true;
}
}
return false;
}
示例12: getIds
private function getIds($get_param_name)
{
$ids = null;
$get_ids = \Yii::$app->request->getQueryParam($get_param_name);
if (!empty($get_ids)) {
$ids = StringHelper::explode($get_ids, ',');
foreach ($ids as $key => $id) {
if (!(int) $id) {
throw new \yii\web\BadRequestHttpException();
}
$ids[$key] = (int) $id;
}
}
return $ids;
}
示例13: actionClonar
public function actionClonar($id)
{
$obj = Actividad::find()->where(['id_actividad' => $id])->one();
$fechar = StringHelper::explode(ArrayHelper::getValue($obj, 'fecha_requerimiento'), '-');
$fechaa = StringHelper::explode(ArrayHelper::getValue($obj, 'fecha_atencion'), '-');
$diar = $fechar[2] + 1;
$diaa = $fechaa[2] + 1;
$clone = new Actividad(['attributes' => $obj->getAttributes(), 'codigo_caso' => $obj->getCodigoActividad(), 'fecha_requerimiento' => $fechar[0] . '-' . $fechar[1] . '-' . $diar, 'fecha_atencion' => $fechaa[0] . '-' . $fechaa[1] . '-' . $diaa]);
$clone->save();
return $this->render('view', ['model' => $this->findModel($clone->id_actividad)]);
}
示例14: testExplode
public function testExplode()
{
$this->assertEquals(['It', 'is', 'a first', 'test'], StringHelper::explode("It, is, a first, test"));
$this->assertEquals(['It', 'is', 'a second', 'test'], StringHelper::explode("It+ is+ a second+ test", '+'));
$this->assertEquals(['Save', '', '', 'empty trimmed string'], StringHelper::explode("Save, ,, empty trimmed string", ','));
$this->assertEquals(['Здесь', 'multibyte', 'строка'], StringHelper::explode("Здесь我 multibyte我 строка", '我'));
$this->assertEquals(['Disable', ' trim ', 'here but ignore empty'], StringHelper::explode("Disable, trim ,,,here but ignore empty", ',', false, true));
}