PHP code example of mysoft / dmp

1. Go to this page and download the library: Download mysoft/dmp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mysoft / dmp example snippets



putenv('DMP_SECRET=1234567890123456');
\dmp\di\Container::getInstance()->set('dmp\extend\datasource\base\interfaces\DataSourceInterface', 'DataSourceService');



use dmp\extend\datasource\mysql\controllers\MysqlDataSourceController;

class DataSourceController extends MysqlDataSourceController
{
    
}




use dmp\extend\datasource\base\models\data\Condition;
use dmp\extend\datasource\base\models\data\DataQueryBuilder;
use dmp\extend\datasource\base\models\data\Property;
use dmp\extend\datasource\base\models\QueryBuilderBase;
use dmp\extend\datasource\base\models\struct\BizParameter;
use dmp\extend\datasource\mysql\services\MySQLDataSourceService;
use dmp\helper\db\mysql\Connection;

class DataSourceService extends MySQLDataSourceService
{
    /**
     * 向平台申明所需参数,在DMP数据源与数据集中可配置该参数的具体值。
     * 在接口调用时,会携带具体值。获取方式:$builder->getBizParamValue('parameter_name')
     * @return array
     */
    public function getBizParams()
    {
        $proCode = new BizParameter();
        $proCode->range = 'datasource';     //指定参数在定义数据源时进行配置
        $proCode->type = 'sys';             //DMP内置参数值
        $proCode->key = 'project_code'; //DMP平台内置租户代码
        $proCode->name = 'proj_code';       //参数名称
        $proCode->description = '租户代码'; //参数描述
        $proCode->name' => $tableName,
                    'prop_name' => 'user_id',
                ]),
                'operator' => '=',
                'right' => new Property([
                    'value' => $userID
                ]),
            ]);
        }
        return parent::getData($builder);
    }

    /**
     * 获取MySQL连接信息
     * @param QueryBuilderBase $builder
     * @return Connection
     */
    public function getDataSource(QueryBuilderBase $builder)
    {
        /*
         多租户需求:可以根据业务中定义的租户代码,返回不同的连接
         */
        $connParams = [
            'host' => '127.0.0.1',
            'db' => 'database',
            'user' => 'uid',
            'password' => 'pwd'
        ];
        return new Connection($connParams);
    }
}