Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.
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
24 changes: 24 additions & 0 deletions .editorconfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
max_line_length = 120

[*.php]
indent_size = 4

[*.md]
trim_trailing_whitespace = false

[{*.html,*.blade.php,*.less,*.sass,*.scss,*.css,*.js,*.json}]
indent_size = 2

[*.{xml,yml,yaml}]
indent_size = 2

[composer.json]
indent_size = 4
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"require": {
"php": "^8.1",
"illuminate/session": "^10.0",
"mongodb/laravel-mongodb": "4.0.0-ALPHA2"
"mongodb/laravel-mongodb": "4.0.0-ALPHA2",
"ext-mongodb": "*"
},
"license": "MIT",
"authors": [
Expand Down
19 changes: 9 additions & 10 deletions src/MongoDbSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@ public function __construct($connection, $table = 'sessions', $minutes = 60)
/**
* {@inheritdoc}
*/
public function open($savePath, $sessionName)
public function open($path, $name): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public function close()
public function close(): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public function read($sessionId)
public function read($id): false|string
{
$session = $this->query()->find($sessionId);
$session = $this->query()->find($id);

return $session ? $session['payload'] : '';
}

/**
* {@inheritdoc}
*/
public function write($sessionId, $data)
public function write($id, $data): bool
{
try {
return (bool) $this->query()
->where('_id', $sessionId)
->where('_id', $id)
->update($this->buildPayload($data), ['upsert' => true]);
} catch (BulkWriteException $exception) {
// high concurrency exception
Expand All @@ -69,17 +69,17 @@ public function write($sessionId, $data)
/**
* {@inheritdoc}
*/
public function destroy($sessionId)
public function destroy($id): bool
{
$this->query()->where('_id', $sessionId)->delete();
$this->query()->where('_id', $id)->delete();

return true;
}

/**
* {@inheritdoc}
*/
public function gc($lifetime)
public function gc($max_lifetime): false|int
{
// Garbage collection is handled by ttl index in the database
return true;
Expand All @@ -88,7 +88,6 @@ public function gc($lifetime)
/**
* Returns the query builder
*
* @return \Jenssegers\Mongodb\Query\Builder
*/
protected function query()
{
Expand Down