fix:更新已知bug,优化代码
This commit is contained in:
@@ -18,9 +18,9 @@ namespace Symfony\Component\HttpFoundation\Session\Flash;
|
||||
*/
|
||||
class AutoExpireFlashBag implements FlashBagInterface
|
||||
{
|
||||
private $name = 'flashes';
|
||||
private $flashes = ['display' => [], 'new' => []];
|
||||
private $storageKey;
|
||||
private string $name = 'flashes';
|
||||
private array $flashes = ['display' => [], 'new' => []];
|
||||
private string $storageKey;
|
||||
|
||||
/**
|
||||
* @param string $storageKey The key used to store flashes in the session
|
||||
@@ -33,7 +33,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add(string $type, $message)
|
||||
public function add(string $type, mixed $message)
|
||||
{
|
||||
$this->flashes['new'][$type][] = $message;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function peek(string $type, array $default = [])
|
||||
public function peek(string $type, array $default = []): array
|
||||
{
|
||||
return $this->has($type) ? $this->flashes['display'][$type] : $default;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function peekAll()
|
||||
public function peekAll(): array
|
||||
{
|
||||
return \array_key_exists('display', $this->flashes) ? $this->flashes['display'] : [];
|
||||
}
|
||||
@@ -84,7 +84,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get(string $type, array $default = [])
|
||||
public function get(string $type, array $default = []): array
|
||||
{
|
||||
$return = $default;
|
||||
|
||||
@@ -103,7 +103,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function all()
|
||||
public function all(): array
|
||||
{
|
||||
$return = $this->flashes['display'];
|
||||
$this->flashes['display'] = [];
|
||||
@@ -122,7 +122,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set(string $type, $messages)
|
||||
public function set(string $type, string|array $messages)
|
||||
{
|
||||
$this->flashes['new'][$type] = (array) $messages;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has(string $type)
|
||||
public function has(string $type): bool
|
||||
{
|
||||
return \array_key_exists($type, $this->flashes['display']) && $this->flashes['display'][$type];
|
||||
}
|
||||
@@ -138,7 +138,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function keys()
|
||||
public function keys(): array
|
||||
{
|
||||
return array_keys($this->flashes['display']);
|
||||
}
|
||||
@@ -146,7 +146,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStorageKey()
|
||||
public function getStorageKey(): string
|
||||
{
|
||||
return $this->storageKey;
|
||||
}
|
||||
@@ -154,7 +154,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clear()
|
||||
public function clear(): mixed
|
||||
{
|
||||
return $this->all();
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ namespace Symfony\Component\HttpFoundation\Session\Flash;
|
||||
*/
|
||||
class FlashBag implements FlashBagInterface
|
||||
{
|
||||
private $name = 'flashes';
|
||||
private $flashes = [];
|
||||
private $storageKey;
|
||||
private string $name = 'flashes';
|
||||
private array $flashes = [];
|
||||
private string $storageKey;
|
||||
|
||||
/**
|
||||
* @param string $storageKey The key used to store flashes in the session
|
||||
@@ -33,7 +33,7 @@ class FlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class FlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add(string $type, $message)
|
||||
public function add(string $type, mixed $message)
|
||||
{
|
||||
$this->flashes[$type][] = $message;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ class FlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function peek(string $type, array $default = [])
|
||||
public function peek(string $type, array $default = []): array
|
||||
{
|
||||
return $this->has($type) ? $this->flashes[$type] : $default;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class FlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function peekAll()
|
||||
public function peekAll(): array
|
||||
{
|
||||
return $this->flashes;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class FlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get(string $type, array $default = [])
|
||||
public function get(string $type, array $default = []): array
|
||||
{
|
||||
if (!$this->has($type)) {
|
||||
return $default;
|
||||
@@ -94,7 +94,7 @@ class FlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function all()
|
||||
public function all(): array
|
||||
{
|
||||
$return = $this->peekAll();
|
||||
$this->flashes = [];
|
||||
@@ -105,7 +105,7 @@ class FlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set(string $type, $messages)
|
||||
public function set(string $type, string|array $messages)
|
||||
{
|
||||
$this->flashes[$type] = (array) $messages;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ class FlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has(string $type)
|
||||
public function has(string $type): bool
|
||||
{
|
||||
return \array_key_exists($type, $this->flashes) && $this->flashes[$type];
|
||||
}
|
||||
@@ -129,7 +129,7 @@ class FlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function keys()
|
||||
public function keys(): array
|
||||
{
|
||||
return array_keys($this->flashes);
|
||||
}
|
||||
@@ -137,7 +137,7 @@ class FlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStorageKey()
|
||||
public function getStorageKey(): string
|
||||
{
|
||||
return $this->storageKey;
|
||||
}
|
||||
@@ -145,7 +145,7 @@ class FlashBag implements FlashBagInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clear()
|
||||
public function clear(): mixed
|
||||
{
|
||||
return $this->all();
|
||||
}
|
||||
|
||||
@@ -22,50 +22,38 @@ interface FlashBagInterface extends SessionBagInterface
|
||||
{
|
||||
/**
|
||||
* Adds a flash message for the given type.
|
||||
*
|
||||
* @param mixed $message
|
||||
*/
|
||||
public function add(string $type, $message);
|
||||
public function add(string $type, mixed $message);
|
||||
|
||||
/**
|
||||
* Registers one or more messages for a given type.
|
||||
*
|
||||
* @param string|array $messages
|
||||
*/
|
||||
public function set(string $type, $messages);
|
||||
public function set(string $type, string|array $messages);
|
||||
|
||||
/**
|
||||
* Gets flash messages for a given type.
|
||||
*
|
||||
* @param string $type Message category type
|
||||
* @param array $default Default value if $type does not exist
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function peek(string $type, array $default = []);
|
||||
public function peek(string $type, array $default = []): array;
|
||||
|
||||
/**
|
||||
* Gets all flash messages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function peekAll();
|
||||
public function peekAll(): array;
|
||||
|
||||
/**
|
||||
* Gets and clears flash from the stack.
|
||||
*
|
||||
* @param array $default Default value if $type does not exist
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get(string $type, array $default = []);
|
||||
public function get(string $type, array $default = []): array;
|
||||
|
||||
/**
|
||||
* Gets and clears flashes from the stack.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all();
|
||||
public function all(): array;
|
||||
|
||||
/**
|
||||
* Sets all flash messages.
|
||||
@@ -74,15 +62,11 @@ interface FlashBagInterface extends SessionBagInterface
|
||||
|
||||
/**
|
||||
* Has flash messages for a given type?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has(string $type);
|
||||
public function has(string $type): bool;
|
||||
|
||||
/**
|
||||
* Returns a list of all defined types.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function keys();
|
||||
public function keys(): array;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user