sgomez/simplesamlphp-module-dbal

A SimpleSAMLphp module adding support for Doctrine/DBAL.

Installs: 19 602

Dependents: 1

Suggesters: 0

Security: 0

Stars: 3

Watchers: 0

Forks: 0

Open Issues: 2

Type:simplesamlphp-module

2.0.3 2017-06-13 16:36 UTC

This package is auto-updated.

Last update: 2024-03-27 18:09:33 UTC


README

This package add a new datastore with Doctrine/DBAL library through a SimpleSAMLphp module installable through Composer. Installation can be as easy as executing:

composer require sgomez/simplesamlphp-module-dbal ~1.0 # for SSP >= 1.14
composer require sgomez/simplesamlphp-module-dbal ~2.0 # for SSP >= 2.0|master

Configuring

You need to specify the next store.type on your config file:

    'store.type'                    => 'SimpleSAML\Modules\DBAL\Store\DBAL',

And copy the template config file from modules/dbal/config-templates/module_dbal.php to your config base directory. You must edit it with your database connection configuration.

This module supports the same engines than Doctrine/DBAL. See Doctrine DBAL configuration for the syntax.

$config = array (
    'store.dbal.url'                => 'mysql://user:password@localhost:3306/simplesamlphp?charset=utf8mb4&serverVersion=5.7',
    // 'store.dbal.url'                => 'sqlite:///simplesamlphp.sqlite',
);

If you want to clean old keys automatically, remember to enable and configure the cron module.

Creating the Schema

The schema is not created every time than Store is called (like SQL store). You need to created it manually. You need to run this every time you install or update a module than use DBAL Store:

bash$ vendor/bin/dbalschema

Creating new schemas

If you want to create your own schema to your module, you need to create a hook_dbal.php file on your hooks directory. This file will run every time than dbalschema is launched.

This is a template:

<?php

function modulename_hook_dbal(&$dbinfo)
{
    $store = SimpleSAML_Store::getInstance();
    
    if (! $store instanceof \SimpleSAML\Modules\DBAL\Store\DBAL ) {
        throw new \SimpleSAML_Error_Exception('OAuth2 module: Only DBAL Store is supported');
    }
    
    $schema = new \Doctrine\DBAL\Schema\Schema();
    
    $fooTable = $store->getPrefix().'_foo';
    $foo = $schema->createTable($fooTable);
    $foo->addColumn('id', 'string', [ 'length' => 255 ]);
    $foo->addColumn('name', 'string', [ 'length' => 255 ]);
    $foo->setPrimaryKey(['id']);
    
    $barTable = $store->getPrefix().'_bar';
    $bar = $schema->createTable($barTable);
    $bar->addColumn('id', 'string', [ 'length' => 255 ]);
    $bar->addColumn('expires_at', 'datetime');
    $bar->addColumn('foo_id', 'string', [ 'length' => 255 ]);
    $bar->setPrimaryKey(['id']);
    $bar->addForeignKeyConstraint($foo, ['foo_id'], ['id'], ['onDelete' => 'CASCADE']);
    
    $store->createOrUpdateSchema($schema, $store->getPrefix().'_modulename');
    
    $dbinfo['summary'][] = 'Created ModuleName Schema';
}

Doctrine DBAL is able to update your schema in almost any case without drop it. To know all types and options see Doctrine DBAL Documentation.