Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix php8.1 null parameter #469

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/AccessControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected function isActive($action)
}else if(is_string($user->loginUrl)){
$loginUrl = $user->loginUrl;
}
if(!is_null($loginUrl) && trim($loginUrl,'/') === $uniqueId)
if(!is_null($loginUrl) && trim((string)$loginUrl,'/') === $uniqueId)
{
return false;
}
Expand All @@ -127,7 +127,7 @@ protected function isActive($action)

foreach ($this->allowActions as $route) {
if (substr($route, -1) === '*') {
$route = rtrim($route, "*");
$route = rtrim(string)$route, "*");
if ($route === '' || strpos($id, $route) === 0) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/RouteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function actionCreate()
{
Yii::$app->getResponse()->format = 'json';
$routes = Yii::$app->getRequest()->post('route', '');
$routes = preg_split('/\s*,\s*/', trim($routes), -1, PREG_SPLIT_NO_EMPTY);
$routes = preg_split('/\s*,\s*/', trim((string)$routes), -1, PREG_SPLIT_NO_EMPTY);
$model = new Route();
$model->addNew($routes);
return $model->getRoutes();
Expand Down
16 changes: 8 additions & 8 deletions models/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function addNew($routes)
$r = explode('&', $route);
$item = $manager->createPermission($this->getPermissionName($route));
if (count($r) > 1) {
$action = '/' . trim($r[0], '/');
$action = '/' . trim((string)$r[0], '/');
if (($itemAction = $manager->getPermission($action)) === null) {
$itemAction = $manager->createPermission($action);
$manager->add($itemAction);
Expand Down Expand Up @@ -101,9 +101,9 @@ public function getRoutePrefix()
public function getPermissionName($route)
{
if (self::PREFIX_BASIC == $this->routePrefix) {
return self::PREFIX_BASIC . trim($route, self::PREFIX_BASIC);
return self::PREFIX_BASIC . trim((string)$route, self::PREFIX_BASIC);
} else {
return self::PREFIX_ADVANCED . ltrim(trim($route, self::PREFIX_BASIC), self::PREFIX_ADVANCED);
return self::PREFIX_ADVANCED . ltrim((string)trim((string)$route, self::PREFIX_BASIC), self::PREFIX_ADVANCED);
}
}

Expand All @@ -127,7 +127,7 @@ public function getRoutes()
// Step through each configured application
foreach ($advanced as $id => $configPaths) {
// Force correct id string.
$id = $this->routePrefix . ltrim(trim($id), $this->routePrefix);
$id = $this->routePrefix . ltrim((string)trim((string)$id), $this->routePrefix);
// Create empty config array.
$config = [];
// Assemble configuration for current app.
Expand Down Expand Up @@ -217,9 +217,9 @@ protected function getRouteRecursive($module, &$result)
$this->getControllerActions($type, $id, $module, $result);
}

$namespace = trim($module->controllerNamespace, '\\') . '\\';
$namespace = trim((string)$module->controllerNamespace, '\\') . '\\';
$this->getControllerFiles($module, $namespace, '', $result);
$all = '/' . ltrim($module->uniqueId . '/*', '/');
$all = '/' . ltrim((string)$module->uniqueId . '/*', '/');
$result[$all] = $all;
} catch (\Exception $exc) {
Yii::error($exc->getMessage(), __METHOD__);
Expand Down Expand Up @@ -253,7 +253,7 @@ protected function getControllerFiles($module, $namespace, $prefix, &$result)
} elseif (strcmp(substr($file, -14), 'Controller.php') === 0) {
$baseName = substr(basename($file), 0, -14);
$name = strtolower(preg_replace('/(?<![A-Z])[A-Z]/', ' \0', $baseName));
$id = ltrim(str_replace(' ', '-', $name), '-');
$id = ltrim((string)str_replace(' ', '-', $name), '-');
$className = $namespace . $baseName . 'Controller';
if (strpos($className, '-') === false && class_exists($className) && is_subclass_of($className, 'yii\base\Controller')) {
$this->getControllerActions($className, $prefix . $id, $module, $result);
Expand Down Expand Up @@ -308,7 +308,7 @@ protected function getActionRoutes($controller, &$result)
$name = $method->getName();
if ($method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0 && $name !== 'actions') {
$name = strtolower(preg_replace('/(?<![A-Z])[A-Z]/', ' \0', substr($name, 6)));
$id = $prefix . ltrim(str_replace(' ', '-', $name), '-');
$id = $prefix . ltrim((string)str_replace(' ', '-', $name), '-');
$result[$id] = $id;
}
}
Expand Down
4 changes: 2 additions & 2 deletions models/searchs/AuthItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public function search($params)
$this->load($params);
if ($this->validate()) {

$search = mb_strtolower(trim($this->name));
$desc = mb_strtolower(trim($this->description));
$search = mb_strtolower(trim((string)$this->name));
$desc = mb_strtolower(trim((string)$this->description));
$ruleName = $this->ruleName;
foreach ($items as $name => $item) {
$f = (empty($search) || mb_strpos(mb_strtolower($item->name), $search) !== false) &&
Expand Down
2 changes: 1 addition & 1 deletion models/searchs/BizRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function search($params)
/* @var \yii\rbac\Manager $authManager */
$authManager = Configs::authManager();
$models = [];
$included = !($this->load($params) && $this->validate() && trim($this->name) !== '');
$included = !($this->load($params) && $this->validate() && trim((string)$this->name) !== '');
foreach ($authManager->getRules() as $name => $item) {
if ($name != RouteRule::RULE_NAME && ($included || stripos($item->name, $this->name) !== false)) {
$models[$name] = new MBizRule($item);
Expand Down
2 changes: 1 addition & 1 deletion views/default/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
$link = $matches[1];
if (strpos($link, '://') === false) {
if ($link[0] == '/') {
$link = Url::current(['page' => ltrim($link, '/')], true);
$link = Url::current(['page' => ltrim((string)$link, '/')], true);
} else {
$link = Url::current(['page' => $baseDir . $link], true);
}
Expand Down
2 changes: 1 addition & 1 deletion views/layouts/left-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$menus = $controller->module->menus;
$route = $controller->route;
foreach ($menus as $i => $menu) {
$menus[$i]['active'] = strpos($route, trim($menu['url'][0], '/')) === 0;
$menus[$i]['active'] = strpos($route, trim((string)$menu['url'][0], '/')) === 0;
}
$this->params['nav-items'] = $menus;
?>
Expand Down
2 changes: 1 addition & 1 deletion views/layouts/right-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$menus = $controller->module->menus;
$route = $controller->route;
foreach ($menus as $i => $menu) {
$menus[$i]['active'] = strpos($route, trim($menu['url'][0], '/')) === 0;
$menus[$i]['active'] = strpos($route, trim((string)$menu['url'][0], '/')) === 0;
}
$this->params['nav-items'] = $menus;
?>
Expand Down
2 changes: 1 addition & 1 deletion views/layouts/top-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$menus = $controller->module->menus;
$route = $controller->route;
foreach ($menus as $i => $menu) {
$menus[$i]['active'] = strpos($route, trim($menu['url'][0], '/')) === 0;
$menus[$i]['active'] = strpos($route, trim((string)$menu['url'][0], '/')) === 0;
}
$this->params['nav-items'] = $menus;
$this->params['top-menu'] = true;
Expand Down