定制 cycle/schema-provider 二次开发

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

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

cycle/schema-provider

最新稳定版本:1.0.0

Composer 安装命令:

composer require cycle/schema-provider

包简介

Cycle ORM Schema providers

README 文档

README

PHP Version Require Latest Stable Version phpunit psalm Total Downloads psalm-level Scrutinizer Code Quality Codecov

Cycle ORM uses an object implementing the Cycle\ORM\SchemaInterface interface as a schema. This schema can be constructed from a PHP array with a specific structure. The package at hand offers a comprehensive solution for building a schema from different sources. It includes a collection of providers that implements the Cycle\Schema\Provider\SchemaProviderInterface interface. These providers are grouped in the Cycle\Schema\Provider\Support\SchemaProviderPipeline.

This pipeline orchestrates the execution of providers in a predetermined order, one after another. If one of the providers returns the schema, subsequent providers are not executed.

Requirements

Make sure that your server is configured with the following PHP versions and extensions:

  • PHP >=8.0

Installation

You can install the package via Composer:

composer require cycle/schema-provider

Usage

Let's explore a straightforward example of schema creation using this package. For example, we have a schema in two php files schema1.php and schema2.php. In this scenario, we can use the Cycle\Schema\Provider\FromFilesSchemaProvider to build the schema from multiple files. Before this provider, we can add a Cycle\Schema\Provider\SimpleCacheSchemaProvider, capable of caching the schema. Upon subsequent schema builds, this provider retrieves the schema from the cache, eliminating the need to build the schema using FromFilesSchemaProvider.

use Cycle\ORM\Schema;
use Cycle\Schema\Provider\FromFilesSchemaProvider;
use Cycle\Schema\Provider\SimpleCacheSchemaProvider;
use Cycle\Schema\Provider\Support\SchemaProviderPipeline;

$pipeline = (new SchemaProviderPipeline($container))->withConfig([
    SimpleCacheSchemaProvider::class => SimpleCacheSchemaProvider::config(key: 'cycle-schema'),
    FromFilesSchemaProvider::class => FromFilesSchemaProvider::config(files: [
        'runtime/schema1.php',
        'runtime/schema2.php',
    ]),
]);

$schema = new Schema($pipeline->read());

The SimpleCacheSchemaProvider requires an implementation of Psr\SimpleCache\CacheInterface, which must be defined in your container. It uses this interface to retrieve and store the schema array. Alternatively, you can use the Cycle\Schema\Provider\PhpFileSchemaProvider, which can save the schema to a PHP file.

Building DB schema from different providers

To merge schema parts obtained from different providers, use Cycle\Schema\Provider\MergeSchemaProvider.

use Cycle\ORM\Schema;
use Cycle\Schema\Provider\FromFilesSchemaProvider;
use Cycle\Schema\Provider\SimpleCacheSchemaProvider;
use Cycle\Schema\Provider\MergeSchemaProvider;
use Cycle\Schema\Provider\Support\SchemaProviderPipeline;

$pipeline = (new SchemaProviderPipeline($container))->withConfig([
    SimpleCacheSchemaProvider::class => SimpleCacheSchemaProvider::config(key: 'cycle-schema'),
    MergeSchemaProvider::class => [
        FromFilesSchemaProvider::class => FromFilesSchemaProvider::config(files: [
            'runtime/schema1.php',
            'runtime/schema2.php',
        ]),
        CustomSchemaProvider::class => ['some' => 'config'],
    ],
]);

$schema = new Schema($pipeline->read());

License

The MIT License (MIT). Please see LICENSE for more information. Maintained by Spiral Scout.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-01