x-wp/wc-data-type 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

x-wp/wc-data-type

最新稳定版本:v1.4.1

Composer 安装命令:

composer require x-wp/wc-data-type

包简介

A library for working and standardizing working with WooCommerce data types.

README 文档

README

WC Data Type

Model-driven custom data objects for WooCommerce

Packagist Version Packagist PHP Version Static Badge Static Badge GitHub Actions Workflow Status

This library provides a standardized way to define and work with custom WooCommerce-style data objects. Define a model once, then reuse consistent property handling, factories, queries, and data-store behavior around it.

Key Features

  1. Model-driven setup: Define object shape with the #[Model] attribute.
  2. WooCommerce-style objects: Extend XWC_Data and keep a familiar CRUD workflow.
  3. Typed properties: Support for core props, meta props, and taxonomy props.
  4. Shared object helpers: Load single objects or collections through package utilities.
  5. Extensible architecture: Swap in custom data stores, factories, and meta stores when needed.
  6. WordPress-native integration: Designed for plugin code already built around WordPress and WooCommerce lifecycles.

Installation

You can install this package via Composer:

composer require x-wp/wc-data-type

Tip

We recommend using automattic/jetpack-autoloader with this package to reduce autoloading conflicts in WordPress environments.

Usage

Below is a simple example that defines a custom data object and loads it through the package helpers.

Defining a model

<?php

use XWC\Data\Decorators\Model;

#[Model(
    name: 'book',
    table: '{{PREFIX}}books',
    core_props: array(
        'title' => array(
            'default' => '',
            'type'    => 'string',
        ),
        'slug' => array(
            'default' => '',
            'type'    => 'slug',
        ),
        'price' => array(
            'default' => 0,
            'type'    => 'float',
        ),
    ),
)]
final class Book extends XWC_Data {
    protected $object_type = 'book';
}

Loading objects

<?php

$book = xwc_get_object(15, 'book', null);

$books = xwc_get_objects(
    'book',
    array(
        'limit'   => 10,
        'orderby' => 'title',
        'order'   => 'ASC',
    ),
);

Generated getters and setters follow the declared props, so classes like Book can expose methods such as get_title(), set_title(), get_slug(), and set_price().

Testing

The package ships with a PHPUnit suite that boots a WordPress test environment and exercises model definitions, object factories, queries, props, and runtime object behavior.

Run the suite with:

composer test

To prepare the local WordPress test environment first:

composer test:install
composer test

To clean the local test environment:

composer test:clean

Documentation

For package-specific usage, start with the public entrypoints used throughout the library:

  • XWC\Data\Decorators\Model
  • XWC_Data
  • xwc_get_object()
  • xwc_get_objects()

Additional project information is available in the repository.

For maintainers preparing prereleases or stable tags, see docs/release-process.md.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2024-07-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固