Skip to content

Commit 9ab84d3

Browse files
author
Jesse
committed
init
0 parents  commit 9ab84d3

29 files changed

+5612
-0
lines changed

README.md

+957
Large diffs are not rendered by default.

composer.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "wppd/laravel-mongodb-42",
3+
"description": "a slightly modified version of jenssegers/laravel-mongodb for laravel 4.2 using php7 mongodb driver",
4+
"keywords": ["laravel","eloquent","mongodb","mongo","database","model","moloquent"],
5+
"homepage": "https://github.com/wppd/laravel-mongodb-42",
6+
"authors": [
7+
{
8+
"name": "Jens Segers",
9+
"homepage": "https://jenssegers.com"
10+
}
11+
],
12+
"license" : "MIT",
13+
"require": {
14+
"mongodb/mongodb": "^1.0.0"
15+
},
16+
"require-dev": {
17+
"phpunit/phpunit": "^4.0|^5.0",
18+
"orchestra/testbench": "^3.1",
19+
"mockery/mockery": "^0.9",
20+
"satooshi/php-coveralls": "^1.0"
21+
},
22+
"autoload": {
23+
"psr-0": {
24+
"Jenssegers\\Mongodb": "src/",
25+
"Jenssegers\\Eloquent": "src/"
26+
}
27+
},
28+
"autoload-dev": {
29+
"classmap": [
30+
"tests/TestCase.php",
31+
"tests/models",
32+
"tests/seeds"
33+
]
34+
},
35+
"suggest": {
36+
"jenssegers/mongodb-session": "Add MongoDB session support to Laravel-MongoDB",
37+
"jenssegers/mongodb-sentry": "Add Sentry support to Laravel-MongoDB"
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php namespace Jenssegers\Mongodb\Auth;
2+
3+
use MongoDB\BSON\UTCDateTime;
4+
use DateTime;
5+
use DateTimeZone;
6+
7+
class DatabaseReminderRepository extends \Illuminate\Auth\Reminders\DatabaseReminderRepository {
8+
9+
/**
10+
* Build the record payload for the table.
11+
*
12+
* @param string $email
13+
* @param string $token
14+
* @return array
15+
*/
16+
protected function getPayload($email, $token)
17+
{
18+
return ['email' => $email, 'token' => $token, 'created_at' => new UTCDateTime(round(microtime(true) * 1000))];
19+
}
20+
21+
/**
22+
* Determine if the reminder has expired.
23+
*
24+
* @param object $reminder
25+
* @return bool
26+
*/
27+
protected function reminderExpired($reminder)
28+
{
29+
// Convert UTCDateTime to a date string.
30+
if ($token['created_at'] instanceof UTCDateTime) {
31+
$date = $token['created_at']->toDateTime();
32+
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
33+
$reminder['created_at'] = $date->format('Y-m-d H:i:s');
34+
} elseif (is_array($token['created_at']) and isset($token['created_at']['date'])) {
35+
$date = new DateTime($token['created_at']['date'], new DateTimeZone(isset($token['created_at']['timezone']) ? $token['created_at']['timezone'] : 'UTC'));
36+
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
37+
$reminder['created_at'] = $date->format('Y-m-d H:i:s');
38+
}
39+
40+
return parent::reminderExpired($reminder);
41+
}
42+
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php namespace Jenssegers\Mongodb\Auth;
2+
3+
use Jenssegers\Mongodb\Auth\DatabaseReminderRepository as DbRepository;
4+
5+
class ReminderServiceProvider extends \Illuminate\Auth\Reminders\ReminderServiceProvider {
6+
7+
/**
8+
* Register the reminder repository implementation.
9+
*
10+
* @return void
11+
*/
12+
protected function registerReminderRepository()
13+
{
14+
$this->app->bindShared('auth.reminder.repository', function($app)
15+
{
16+
$connection = $app['db']->connection();
17+
18+
// The database reminder repository is an implementation of the reminder repo
19+
// interface, and is responsible for the actual storing of auth tokens and
20+
// their e-mail addresses. We will inject this table and hash key to it.
21+
$table = $app['config']['auth.reminder.table'];
22+
23+
$key = $app['config']['app.key'];
24+
25+
$expire = $app['config']->get('auth.reminder.expire', 60);
26+
27+
return new DbRepository($connection, $table, $key, $expire);
28+
});
29+
}
30+
31+
}

src/Jenssegers/Mongodb/Collection.php

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php namespace Jenssegers\Mongodb;
2+
3+
use Exception;
4+
use MongoDB\Collection as MongoCollection;
5+
use MongoDB\BSON\ObjectID;
6+
7+
class Collection
8+
{
9+
/**
10+
* The connection instance.
11+
*
12+
* @var Connection
13+
*/
14+
protected $connection;
15+
16+
/**
17+
* The MongoCollection instance..
18+
*
19+
* @var MongoCollection
20+
*/
21+
protected $collection;
22+
23+
/**
24+
* Constructor.
25+
*/
26+
public function __construct(Connection $connection, MongoCollection $collection)
27+
{
28+
$this->connection = $connection;
29+
$this->collection = $collection;
30+
}
31+
32+
/**
33+
* Handle dynamic method calls.
34+
*
35+
* @param string $method
36+
* @param array $parameters
37+
* @return mixed
38+
*/
39+
public function __call($method, $parameters)
40+
{
41+
$start = microtime(true);
42+
$result = call_user_func_array([$this->collection, $method], $parameters);
43+
44+
if ($this->connection->logging()) {
45+
// Once we have run the query we will calculate the time that it took to run and
46+
// then log the query, bindings, and execution time so we will report them on
47+
// the event that the developer needs them. We'll log time in milliseconds.
48+
$time = $this->connection->getElapsedTime($start);
49+
50+
$query = [];
51+
52+
// Convert the query parameters to a json string.
53+
array_walk_recursive($parameters, function (&$item, $key) {
54+
if ($item instanceof ObjectID) {
55+
$item = (string) $item;
56+
}
57+
});
58+
59+
// Convert the query parameters to a json string.
60+
foreach ($parameters as $parameter) {
61+
try {
62+
$query[] = json_encode($parameter);
63+
} catch (Exception $e) {
64+
$query[] = '{...}';
65+
}
66+
}
67+
68+
$queryString = $this->collection->getCollectionName() . '.' . $method . '(' . implode(',', $query) . ')';
69+
70+
$this->connection->logQuery($queryString, [], $time);
71+
}
72+
73+
return $result;
74+
}
75+
}

0 commit comments

Comments
 (0)