summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Database/DatabaseServiceProvider.php3
-rw-r--r--src/Http/SessionServiceProvider.php32
-rw-r--r--src/Models/BaseModel.php16
3 files changed, 49 insertions, 2 deletions
diff --git a/src/Database/DatabaseServiceProvider.php b/src/Database/DatabaseServiceProvider.php
index cfdc89e7..b3c33588 100644
--- a/src/Database/DatabaseServiceProvider.php
+++ b/src/Database/DatabaseServiceProvider.php
@@ -31,8 +31,9 @@ class DatabaseServiceProvider extends ServiceProvider
$capsule->bootEloquent();
$capsule->getConnection()->useDefaultSchemaGrammar();
+ $pdo = null;
try {
- $capsule->getConnection()->getPdo();
+ $pdo = $capsule->getConnection()->getPdo();
} catch (PDOException $e) {
$this->exitOnError();
}
diff --git a/src/Http/SessionServiceProvider.php b/src/Http/SessionServiceProvider.php
index 59121a3b..66ff18cc 100644
--- a/src/Http/SessionServiceProvider.php
+++ b/src/Http/SessionServiceProvider.php
@@ -2,8 +2,10 @@
namespace Engelsystem\Http;
+use Engelsystem\Config\Config;
use Engelsystem\Container\ServiceProvider;
use Symfony\Component\HttpFoundation\Session\Session;
+use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
@@ -38,7 +40,35 @@ class SessionServiceProvider extends ServiceProvider
return $this->app->make(MockArraySessionStorage::class);
}
- return $this->app->make(NativeSessionStorage::class, ['options' => ['cookie_httponly' => true]]);
+ /** @var Config $config */
+ $config = $this->app->get('config');
+ $sessionConfig = $config->get('session');
+
+ $handler = null;
+ $driver = $sessionConfig['driver'];
+
+ switch ($driver) {
+ case 'pdo':
+ $handler = $this->app->make(PdoSessionHandler::class, [
+ 'pdoOrDsn' => $this->app->get('db.pdo'),
+ 'options' => [
+ 'db_table' => 'sessions',
+ 'db_id_col' => 'id',
+ 'db_data_col' => 'payload',
+ 'db_lifetime_col' => 'lifetime',
+ 'db_time_col' => 'last_activity',
+ ],
+ ]);
+ break;
+ }
+
+ return $this->app->make(NativeSessionStorage::class, [
+ 'options' => [
+ 'cookie_httponly' => true,
+ 'name' => $sessionConfig['name'],
+ ],
+ 'handler' => $handler,
+ ]);
}
/**
diff --git a/src/Models/BaseModel.php b/src/Models/BaseModel.php
index cf718e4f..d5ded428 100644
--- a/src/Models/BaseModel.php
+++ b/src/Models/BaseModel.php
@@ -2,6 +2,8 @@
namespace Engelsystem\Models;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
abstract class BaseModel extends Model
@@ -10,6 +12,8 @@ abstract class BaseModel extends Model
public $timestamps = false;
/**
+ * Create a new model
+ *
* @param array $attributes
* @return BaseModel
*/
@@ -20,4 +24,16 @@ abstract class BaseModel extends Model
return $instance;
}
+
+ /**
+ * Find a model by its primary key
+ *
+ * @param mixed $id
+ * @param array $columns
+ * @return Builder|Builder[]|Collection|Model|null
+ */
+ public static function find($id, $columns = ['*'])
+ {
+ return static::query()->find($id, $columns);
+ }
}