Skip to content
4 changes: 2 additions & 2 deletions src/Console/ActionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ protected function getDefaultNamespace($rootNamespace)

$segments = explode('\\', config('admin.route.namespace'));
array_pop($segments);
array_push($segments, 'Actions');
$segments[] = 'Actions';

if (isset($this->namespaceMap[$this->choice])) {
array_push($segments, $this->namespaceMap[$this->choice]);
$segments[] = $this->namespaceMap[$this->choice];
}

return implode('\\', $segments);
Expand Down
6 changes: 1 addition & 5 deletions src/Exception/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ public function report(\Throwable $e)
*/
protected function replaceBasePath(string $path)
{
return str_replace(
str_replace('\\', '/', base_path().'/'),
'',
str_replace('\\', '/', $path)
);
return str_replace(['\\', str_replace('\\', '/', base_path() . '/')], ['/', ''], $path);
}
}
3 changes: 2 additions & 1 deletion src/Form/Concerns/HasFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ protected function mergedFields()
foreach ($this->fields() as $field) {
if ($field instanceof FieldsCollection) {
/** @var Field $field */
$fields = array_merge($fields, $field->mergedFields());
// 使用array_push和展开运算符,避免重复的array_merge调用
array_push($fields, ...$field->mergedFields());
} else {
$fields[] = $field;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Form/Field/ArrayField.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ protected function buildRelatedForms()

foreach (Helper::array($this->value()) as $key => $data) {
if (isset($data['pivot'])) {
$data = array_merge($data, $data['pivot']);
// 使用展开运算符替代 array_merge,性能更优
$data = [...$data, ...$data['pivot']];
}

$forms[$key] = $this->buildNestedForm($key)->fill($data);
Expand Down
10 changes: 9 additions & 1 deletion src/Form/Field/Autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,20 @@ public function render()

protected function formatGroupOptions()
{
$groupOptions = [];

foreach ($this->groups as $group) {
if (! array_key_exists('options', $group) || ! array_key_exists('label', $group)) {
continue;
}

$this->options = array_merge($this->options, $this->formatOptions($group['options'], $group['label']));
// 先收集所有格式化的选项,避免在循环中重复合并数组
$groupOptions[] = $this->formatOptions($group['options'], $group['label']);
}

// 使用展开运算符一次性合并所有数组,性能更优
if ($groupOptions) {
$this->options = array_merge($this->options, ...$groupOptions);
}

$this->groups = [];
Expand Down
12 changes: 3 additions & 9 deletions src/Form/Field/Embeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,9 @@ public function getValidator(array $input)
* 'extra.end_atend' => "$label[end_at]"
* ]
*/
$attributes = array_merge(
$attributes,
$this->formatValidationAttribute($input, $field->label(), $column)
);

$messages = array_merge(
$messages,
$this->formatValidationMessages($input, $field->getValidationMessages())
);
$attributes += $this->formatValidationAttribute($input, $field->label(), $column);

$messages += $this->formatValidationMessages($input, $field->getValidationMessages());
}

if (empty($rules)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Field/Fieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Fieldset

public function __construct()
{
$this->name = uniqid('fieldset-');
$this->name = uniqid('fieldset-', true);
}

public function start($title)
Expand Down
12 changes: 3 additions & 9 deletions src/Form/Field/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,9 @@ public function getValidator(array $input)
$rules[$column] = $fieldRules;
}

$attributes = array_merge(
$attributes,
$this->formatValidationAttribute($input, $field->label(), $column)
);

$messages = array_merge(
$messages,
$this->formatValidationMessages($input, $field->getValidationMessages())
);
$attributes += $this->formatValidationAttribute($input, $field->label(), $column);

$messages += $this->formatValidationMessages($input, $field->getValidationMessages());
}

Arr::forget($rules, NestedForm::REMOVE_FLAG_NAME);
Expand Down
14 changes: 8 additions & 6 deletions src/Form/Field/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,18 @@ protected function formatOptions($options)
$original = [];
$toReplace = [];

foreach ($options as $key => &$value) {
foreach ($options as $key => $value) {
if (is_array($value)) {
$subArray = $this->formatOptions($value);
$value = $subArray['options'];
$original = array_merge($original, $subArray['original']);
$toReplace = array_merge($toReplace, $subArray['toReplace']);
$options[$key] = $subArray['options'];

// 使用array_push和展开运算符,避免重复的array_merge
array_push($original, ...$subArray['original']);
array_push($toReplace, ...$subArray['toReplace']);
} elseif (preg_match('/function.*?/', $value)) {
$original[] = $value;
$value = "%{$key}%";
$toReplace[] = "\"{$value}\"";
$options[$key] = "%{$key}%";
$toReplace[] = "\"%{$key}%\"";
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Field/UploadField.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public function sequenceName()
*/
protected function generateUniqueName(UploadedFile $file)
{
return md5(uniqid()).'.'.$file->getClientOriginalExtension();
return md5(uniqid('', true)).'.'.$file->getClientOriginalExtension();
}

/**
Expand Down
24 changes: 12 additions & 12 deletions src/Grid/Column/Filter/Between.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Between extends Filter
public function __construct()
{
$this->class = [
'start' => uniqid('column-filter-start-'),
'end' => uniqid('column-filter-end-'),
'start' => uniqid('column-filter-start-', true),
'end' => uniqid('column-filter-end-', true),
];
}

Expand Down Expand Up @@ -175,20 +175,20 @@ public function render()
</a>
<ul class="dropdown-menu" role="menu" style="min-width: 180px;padding: 10px;left: -70px;border-radius: 0;font-weight:normal;background:#fff">
<li class="dropdown-item">
<input type="text"
class="form-control input-sm {$this->class['start']}"
name="{$this->getQueryName()}[start]"
placeholder="{$this->trans('between_start')}"
value="{$value['start']}"
<input type="text"
class="form-control input-sm {$this->class['start']}"
name="{$this->getQueryName()}[start]"
placeholder="{$this->trans('between_start')}"
value="{$value['start']}"
autocomplete="off" />
</li>
<li style="margin: 5px;"></li>
<li class="dropdown-item">
<input type="text"
class="form-control input-sm {$this->class['end']}"
name="{$this->getQueryName()}[end]"
placeholder="{$this->trans('between_end')}"
value="{$value['end']}"
<input type="text"
class="form-control input-sm {$this->class['end']}"
name="{$this->getQueryName()}[end]"
placeholder="{$this->trans('between_end')}"
value="{$value['end']}"
autocomplete="off"/>
</li>
{$this->renderFormButtons()}
Expand Down
2 changes: 1 addition & 1 deletion src/Grid/Column/Filter/Equal.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(?string $placeholder = null)
{
$this->placeholder($placeholder ?: $this->trans('search'));

$this->class = uniqid('column-filter-');
$this->class = uniqid('column-filter-', true);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Grid/Column/Filter/In.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function __construct(array $options)
$this->options = $options;

$this->class = [
'all' => uniqid('column-filter-all-'),
'item' => uniqid('column-filter-item-'),
'all' => uniqid('column-filter-all-', true),
'item' => uniqid('column-filter-item-', true),
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Grid/Column/HasDisplayers.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function append($val)
}

if (is_array($v)) {
array_push($v, $val);
$v[] = $val;

return $v;
} elseif ($v instanceof Collection) {
Expand Down
10 changes: 5 additions & 5 deletions src/Grid/Concerns/HasComplexHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ protected function sortHeaders()
$headersColumns = $this->complexHeaders = $this->columns = [];

foreach ($originalHeaders as $header) {
$headersColumns = array_merge(
$headersColumns,
$tmp = $header->getColumnNames()->toArray()
);
foreach ($tmp as &$name) {
$columnNames = $header->getColumnNames();

// 直接使用Collection,避免转换为数组和重复的array_merge
foreach ($columnNames as $name) {
$headersColumns[] = $name;
if ($column = $originalColumns->get($name)) {
$this->columns[$name] = $column;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Grid/Displayers/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function append($action)
{
$this->prepareAction($action);

array_push($this->appends, $action);
$this->appends[] = $action;

return $this;
}
Expand Down Expand Up @@ -229,7 +229,7 @@ public function display(array $callbacks = [])
foreach ($this->actions as $action => $enable) {
if ($enable) {
$method = 'render'.ucfirst($action);
array_push($prepends, $this->{$method}());
$prepends[] = $this->{$method}();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Grid/Displayers/DropdownActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function prependDefaultActions()
continue;
}

array_push($this->default, $this->{'render'.ucfirst($action)}());
$this->default[] = $this->{'render' . ucfirst($action)}();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Grid/Displayers/Limit.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function display($limit = 100, $end = '...')

$value = array_slice($value, 0, $limit);

array_push($value, $end);
$value[] = $end;

return $value;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Grid/Filter/AbstractFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,7 @@ protected function buildCondition(...$params)
return;
}

$column = explode('.', $this->column);

if (count($column) == 1) {
if (!str_contains($this->column, '.')) {
return [$this->query => &$params];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Grid/Tools/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function url($column, $value = null, $add = false)
if ($add) {
$options = [];
}
array_push($options, $value);
$options[] = $value;
}

if (! empty($options)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/EditorMDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function upload(Request $request)

protected function generateNewName(UploadedFile $file)
{
return uniqid(md5($file->getClientOriginalName())).'.'.$file->getClientOriginalExtension();
return uniqid(md5($file->getClientOriginalName()), true).'.'.$file->getClientOriginalExtension();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Controllers/PermissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ protected function treeView()
$tree->disableEditButton();

$tree->branch(function ($branch) {
$branchName = htmlspecialchars($branch['name']);
$branchSlug = htmlspecialchars($branch['slug']);
$branchName = htmlspecialchars($branch['name'], ENT_QUOTES | ENT_HTML5);
$branchSlug = htmlspecialchars($branch['slug'], ENT_QUOTES | ENT_HTML5);
$payload = "<div class='pull-left' style='min-width:310px'><b>{$branchName}</b>&nbsp;&nbsp;[<span class='text-primary'>{$branchSlug}</span>]";

$path = array_filter($branch['http_path']);
Expand All @@ -46,7 +46,7 @@ protected function treeView()
$max = 3;
if (count($path) > $max) {
$path = array_slice($path, 0, $max);
array_push($path, '...');
$path[] = '...';
}

$method = $branch['http_method'] ?: [];
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/TinymceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function upload(Request $request)

protected function generateNewName(UploadedFile $file)
{
return uniqid(md5($file->getClientOriginalName())).'.'.$file->getClientOriginalExtension();
return uniqid(md5($file->getClientOriginalName()), true).'.'.$file->getClientOriginalExtension();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Show/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ public function json()
$content = is_string($value) ? json_decode($value, true) : $value;
if (is_array($content)) {
array_walk($content, function (&$v, $k) {
$v = htmlspecialchars($v);
$v = htmlspecialchars($v, ENT_QUOTES | ENT_HTML5);
});
} else {
$content = htmlspecialchars($content);
$content = htmlspecialchars($content, ENT_QUOTES | ENT_HTML5);
}
$field->wrap(false);

Expand Down Expand Up @@ -460,7 +460,7 @@ public function append($val)
}

if (is_array($v)) {
array_push($v, $val);
$v[] = $val;

return $v;
} elseif ($v instanceof Collection) {
Expand Down
6 changes: 3 additions & 3 deletions src/Support/DatabaseUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,16 @@ public function getClassFromFile($file)
// Prefix and suffix string to prevent unterminated comment warning
$tokens = token_get_all('/**/'.$buffer.'/**/');

if (strpos($buffer, '{') === false) {
if (!str_contains($buffer, '{')) {
continue;
}

for (; $i < count($tokens); $i++) {
for ($iMax = count($tokens); $i < $iMax; $i++) {
/*
* Namespace opening
*/
if ($tokens[$i][0] === T_NAMESPACE) {
for ($j = $i + 1; $j < count($tokens); $j++) {
for ($j = $i + 1, $jMax = count($tokens); $j < $jMax; $j++) {
if ($tokens[$j] === ';') {
break;
}
Expand Down
Loading