liberty_code/attribute_model

v1.0.0 2024-02-27 18:23 UTC

This package is auto-updated.

Last update: 2024-09-27 19:50:30 UTC


README

描述

库包含属性模型组件,用于处理模型组件。

要求

  • 脚本语言:PHP:版本 7 || 8

框架库实现要求

  1. 库仓库:liberty_code/validation:版本 1.0

    • 标准规则实现(或等效)

      在实体上提供的验证器,必须包含其规则集合中添加的所有标准规则。

    • 验证器规则实现(或等效)

      在实体上提供的验证器,必须包含其规则集合中添加的所有验证器规则。每个验证器规则必须使用与实体上提供的验证器相同的实现。

  2. 库仓库:liberty_code/sql:版本 1.0

    • 验证 SQL 规则实现(或等效)

      在实体上提供的验证器,必须包含其规则集合中添加的所有 SQL 规则。

安装

有几种可能的方式

Composer

  1. 要求

    它需要安装 Composer。更多信息: https://getcomposer.org.cn

  2. 命令:移动到项目根路径

     cd "<project_root_path>"
    
  3. 命令:安装

     php composer.phar require liberty_code/attribute_model ["<version>"]
    
  4. 注意

    • 包含 vendor

      如果项目使用 Composer,必须包含 vendor

        require_once('<project_root_path>/vendor/autoload.php');
      
    • 配置

      安装命令允许在 composer 文件中添加

        {
            "require": {
                "liberty_code/attribute_model": "<version>"
            }
        }
      

包含

  1. 下载

    • 下载以下仓库。
    • 将其放在仓库根路径上。
  2. 包含源代码

     require_once('<repository_root_path>/include/Include.php');
    

用法

属性

属性实体允许使用实体设计属性。

元素

  • AttributeEntity

    扩展已配置实体的功能。使用实体来设计属性,可以在实体中使用。

  • AttributeEntityCollection

    扩展固定实体集合的功能。允许设计属性实体集合。允许提供实体属性配置。

  • AttributeEntityFactory

    扩展固定实体工厂的功能。允许设计属性工厂,从指定的配置中提供属性实体对象。

  • AttributeEntityRepository

    扩展固定多仓库的功能。允许设计属性实体仓库,以持久化中保存来自属性实体的数据。

  • AttributeEntityCollectionRepository

    扩展固定多集合仓库的功能。允许设计属性实体集合仓库,以持久化中保存来自属性实体集合的数据。

  • SqlAttributeEntity

    扩展属性实体功能。使用 SQL 规则进行属性验证。

  • SqlAttributeEntityFactory

    扩展属性实体工厂功能。提供 SQL 属性实体对象。

  • SqlAttributeEntityRepository

    扩展属性实体仓库功能。使用 SQL 表持久化器作为持久化。

  • SqlAttributeEntityCollectionRepository

    扩展属性实体集合仓库功能。使用 SQL 表持久化器作为持久化。

  • SaveAttributeEntity

    扩展属性实体功能。可以在保存实体时使用。

  • SaveAttributeEntityCollection

    扩展属性实体集合功能。允许提供保存实体属性配置。

  • SaveAttributeEntityFactory

    扩展属性实体工厂功能。提供保存属性实体对象。

  • SqlSaveAttributeEntity

    扩展保存属性实体功能。使用 SQL 规则进行属性验证。

  • SqlSaveAttributeEntityFactory

    扩展保存属性实体工厂功能。提供 SQL 保存属性实体对象。

// Get attribute entity factory
use liberty_code\attribute_model\attribute\model\AttributeEntityFactory;
$attributeEntityFactory = new AttributeEntityFactory($provider);
...
// Get attribute builder
use liberty_code\handle_model\attribute\build\model\DefaultBuilder;
$attributeBuilder = new DefaultBuilder($attributeFactory);
...
// Get attribute entity collection
use liberty_code\attribute_model\attribute\model\AttributeEntityCollection;
$attributeEntityCollection = new AttributeEntityCollection();
...
// Hydrate attribute entity collection
$attributeBuilder->setTabDataSrc(array(...));
$attributeBuilder->hydrateAttributeCollection($attributeEntityCollection);
...
foreach($attributeEntityCollection->getTabAttributeKey() as $attributeKey) {
    echo($attributeEntityCollection->getObjAttribute($attributeKey)->getStrAttributeKey() .'<br />');
}
/**
 * Show: 
 * Attribute key 1
 * ...
 * Attribute key N
 */
...

属性浏览器

浏览器允许从指定的浏览配置中提供属性实体。

  • AttributeBrowserEntity

    扩展验证器配置实体功能。允许定义属性,以搜索属性实体。

  • AttributeBrowserRepository

    允许从指定的属性浏览器实体或指定的浏览配置中加载属性实体。

  • SqlAttributeBrowserRepository

    扩展属性浏览器仓库功能。使用SQL表浏览器来加载属性实体。

// Get attribute browser entity
use liberty_code\attribute_model\attribute\browser\model\AttributeBrowserEntity;
$attributeBrowserEntity = new AttributeBrowserEntity(
    array(), 
    $validator,
    $dateTimeFactory
    $attrSpec
);
...
// Hydrate attribute browser entity
$roleBrowserEntity->intAttrItemCountPage = 50; // Select 50 roles per page
$roleBrowserEntity->intAttrPageIndex = 0; // Select Page 1
$roleBrowserEntity->strAttrCritLikeName = '...' // Select result where attribute name like '...'
$roleBrowserEntity->$strAttrSortName = 'asc' // Sort result by ascending attribute name
...
// Get attribute browser repository
use liberty_code\attribute_model\attribute\browser\sql\model\repository\SqlAttributeBrowserRepository;
$attributeBrowserRepository = new SqlAttributeBrowserRepository(
    $sqlTableBrowser, 
    $sqlAttributeEntityCollectionRepository
);
...
// Load attribute collection
$attributeBrowserRepository->loadFromEntity($attributeEntityCollection, $attributeBrowserEntity);
...

属性提供者

仓库属性提供者允许使用属性实体功能为实体提供属性信息。

元素

  • RepoAttrProvider

    扩展标准属性提供者功能。使用属性实体集合和属性实体集合仓库,为实体提供属性信息。

  • SqlRepoAttrProvider

    扩展仓库属性提供者功能。使用SQL属性实体集合仓库,为实体提供属性信息。

示例

// Get attribute provider
use liberty_code\attribute_model\provider\sql\model\SqlRepoAttrProvider;
$attrProvider = new AttrProvider(
    $attributeEntityCollection, 
    $sqlAttributeEntityCollectionRepository
);
...
// Get entity attribute configuration array
var_dump($attrProvider->getTabEntityAttrConfig());
...
// Get entity attribute rule configurations array
var_dump($attrProvider->getTabEntityAttrRuleConfig());
...