承接 sgomez/simplesamlphp-module-dbal 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sgomez/simplesamlphp-module-dbal

最新稳定版本:2.0.3

Composer 安装命令:

composer require sgomez/simplesamlphp-module-dbal

包简介

A SimpleSAMLphp module adding support for Doctrine/DBAL.

README 文档

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.

统计信息

  • 总下载量: 23.41k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2015-05-04