-
Notifications
You must be signed in to change notification settings - Fork 0
Draft notes after a first review of the full code #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="MONGODB_URI" value="mongodb://mongodb/" /> | ||
<env name="MONGODB_URI" value="mongodb://127.0.0.1:27017/?serverSelectionTimeoutMS=100"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be necessary for the CI. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe it was CI that used the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The env var is actually updated in CI: |
||
<env name="MONGODB_DATABASE" value="unittest"/> | ||
<env name="MYSQL_HOST" value="mysql"/> | ||
<env name="MYSQL_PORT" value="3306"/> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ protected function getPayload($email, $token) | |
return [ | ||
'email' => $email, | ||
'token' => $this->hasher->make($token), | ||
// why is it necessary ? vs "new Carbon" in parent class | ||
'created_at' => new UTCDateTime(Date::now()->format('Uv')), | ||
]; | ||
} | ||
|
@@ -27,6 +28,7 @@ protected function getPayload($email, $token) | |
*/ | ||
protected function tokenExpired($createdAt) | ||
{ | ||
// Could be removed if Carbon was natively suported? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the writes are handled through the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
$createdAt = $this->convertDateTime($createdAt); | ||
|
||
return parent::tokenExpired($createdAt); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,7 +112,8 @@ public function getSchemaBuilder() | |
* | ||
* @return Database | ||
*/ | ||
public function getMongoDB() | ||
// Should be named getDatabase ? | ||
public function getDatabase() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I don't like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{ | ||
return $this->db; | ||
} | ||
|
@@ -132,7 +133,7 @@ public function getMongoClient() | |
*/ | ||
public function getDatabaseName() | ||
{ | ||
return $this->getMongoDB()->getDatabaseName(); | ||
return $this->getDatabase()->getDatabaseName(); | ||
} | ||
|
||
/** | ||
|
@@ -147,6 +148,7 @@ public function getDatabaseName() | |
protected function getDefaultDatabaseName(string $dsn, array $config): string | ||
{ | ||
if (empty($config['database'])) { | ||
// Use parse_url() to get the database name from dsn | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
if (preg_match('/^mongodb(?:[+]srv)?:\\/\\/.+\\/([^?&]+)/s', $dsn, $matches)) { | ||
$config['database'] = $matches[1]; | ||
} else { | ||
|
@@ -195,6 +197,8 @@ protected function createConnection($dsn, array $config, array $options): Client | |
*/ | ||
public function disconnect() | ||
{ | ||
// No need to explicitly disconnect? | ||
// What appens if a reference to the connection is kept somewhere? | ||
Comment on lines
+200
to
+201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this was done in an attempt to duplicate behaviour to relational databases. However, unless the client was created with disabled client persistence (which it isn't), this will keep connections open due to the underlying libmongoc client object being persisted for future use in the process. The drivers API also doesn't support disconnecting a client object. That said, this is probably the closest we'll get to disconnecting the database connection, so I'm fine keeping it as long as we document the caveats. |
||
unset($this->connection); | ||
} | ||
|
||
|
@@ -260,6 +264,9 @@ protected function getDsn(array $config): string | |
/** | ||
* @inheritdoc | ||
*/ | ||
// Should be @internal because the parent method is protected | ||
// and this method is use in Collection::__call | ||
// Otherwise reimplement the method in Collection | ||
Comment on lines
+267
to
+269
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I'm wondering why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For logging only. https://jira.mongodb.org/browse/PHPORM-56 |
||
public function getElapsedTime($start) | ||
{ | ||
return parent::getElapsedTime($start); | ||
|
@@ -302,6 +309,8 @@ protected function getDefaultSchemaGrammar() | |
* | ||
* @param \MongoDB\Database $db | ||
*/ | ||
// 1 more reason to rename getMongoDB to getDatabase, for consistency with the setter | ||
// this is not used in the codebase, use-case may be challenged as it allows to by-pass the connection | ||
Comment on lines
+312
to
+313
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'm very much in favour of removing this method or at least marking it as |
||
public function setDatabase(\MongoDB\Database $db) | ||
{ | ||
$this->db = $db; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
use Jenssegers\Mongodb\Relations\EmbedsMany; | ||
use Jenssegers\Mongodb\Relations\EmbedsOne; | ||
|
||
// Documentation ? | ||
trait EmbedsRelations | ||
{ | ||
/** | ||
|
@@ -23,7 +24,8 @@ protected function embedsMany($related, $localKey = null, $foreignKey = null, $r | |
// the calling method's name and use that as the relationship name as most | ||
// of the time this will be what we desire to use for the relationships. | ||
if ($relation === null) { | ||
[, $caller] = debug_backtrace(false); | ||
// Black magic. The call may be optimized to get only the method name. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is indeed black magic that's used elsewhere in Laravel as well to guess relation names: https://github.com/laravel/framework/blob/f882a45988dee457ed66279b6571d63d1f54f5be/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php#L356 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
[, $caller] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); | ||
|
||
$relation = $caller['function']; | ||
} | ||
|
@@ -58,7 +60,8 @@ protected function embedsOne($related, $localKey = null, $foreignKey = null, $re | |
// the calling method's name and use that as the relationship name as most | ||
// of the time this will be what we desire to use for the relationships. | ||
if ($relation === null) { | ||
[, $caller] = debug_backtrace(false); | ||
// Black magic. The call may be optimized to get only the method name. | ||
[, $caller] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); | ||
|
||
$relation = $caller['function']; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't need the custom provider, I'm all for it.