定制 icanboogie/bind-activerecord 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

icanboogie/bind-activerecord

最新稳定版本:v5.0.0

Composer 安装命令:

composer require icanboogie/bind-activerecord

包简介

Binds ActiveRecord to ICanBoogie

README 文档

README

Release Code Coverage Downloads

The icanboogie/bind-activerecord package binds the icanboogie/activerecord package to ICanBoogie, using its Autoconfig feature. It provides configuration builders for active record connections and models, as well as getters for the connection provider and the model provider.

<?php
namespace ICanBoogie\Binding\ActiveRecord;

use ICanBoogie\Application;
use ICanBoogie\ActiveRecord\Config;
use ICanBoogie\ActiveRecord\Model;
use ICanBoogie\ActiveRecord\ConnectionProvider;
use ICanBoogie\ActiveRecord\ModelProvider;

/* @var Application $app */

$app = boot();

$config = $app->configs[Config::class];

echo count($config->connections);
echo count($config->models);

$primary_connection = $app->service_for_id('active_record.connection.primary', Connection::class);
# or
$primary_connection = $app->service_for_class(ConnectionProvider::class)->connection_for_id('primary');

$nodes = $app->service_for_class(ModelProvider::class)->model_for_record(Node::class);

Installation

composer require icanboogie/bind-activerecord

Autoconfig

The package provides a configuration builder for ICanBoogie\ActiveRecord\Config.

The activerecord config fragment

Currently activerecord fragments are used to configure connections and models, which are suitable to create ConnectionCollection and ModelCollection instances.

The following example demonstrates how to define connections and models. Two connections are defined: primary is a connection to the MySQL server;cache is a connection to a SQLite database. The nodes model is also defined.

<?php

// config/activerecord.php

use ICanBoogie\ActiveRecord\ConnectionOptions;
use ICanBoogie\ActiveRecord\Model;
use ICanBoogie\ActiveRecord\Schema;
use ICanBoogie\ActiveRecord\SchemaColumn;
use ICanBoogie\ActiveRecord\Config;
use ICanBoogie\ActiveRecord\ConfigBuilder;
use ICanBoogie\ActiveRecord\SchemaBuilder;

return fn(ConfigBuilder $config) => $config
    ->add_connection(
        id: Config::DEFAULT_CONNECTION_ID,
        dsn: 'mysql:dbname=mydatabase',
        username: 'root',
        password: 'root',
        table_name_prefix: 'myprefix',
        time_zone: '+02:00',
    )
    ->add_connection(
        id: 'cache',
        dsn: 'sqlite:' . ICanBoogie\REPOSITORY . 'cache.sqlite'
    )
    ->add_model(
        id: 'nodes',
        activerecord_class: Node::class,
        schema_builder: fn(SchemaBuilder $b) => $b
            ->add_serial('id',primary: true)
            ->add_varchar('title')
    );

Continuous Integration

The project is continuously tested by GitHub actions.

Tests Static Analysis Code Style

Code of Conduct

This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you're expected to uphold this code.

Contributing

See CONTRIBUTING for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-02-01