定制 helsingborg-stad/acfservice 二次开发

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

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

helsingborg-stad/acfservice

Composer 安装命令:

composer require helsingborg-stad/acfservice

包简介

Simplifies ACF integration by providing a centralized AcfService that exposes global ACF functions in a streamlined manner. Simplify your development workflow and enhance ACF integration with ease.

README 文档

README

Contributors Forks Stargazers Issues License

Unit Tests PHP Versions

AcfService

Simplifies ACF integration by providing a centralized AcfService that exposes global ACF functions in a streamlined manner. Simplify your development workflow and enhance ACF integration with ease.

Report Bug · Request Feature

About AcfService

Enable the use of global ACF functions in plugins and themes where applying Interface Segregation. Different flavors of the ACF Service can be utilized by applying available decorators.

Getting Started

Installation

  1. Install the package via composer:
composer require helsingborg-stad/acfservice
  1. Use the AcfService in your plugin or theme:
use AcfService\Implementations\NativeAcfService;

$acfService = new NativeAcfService();
$fields = $acfService->getFields(123);

Built With

  • PHP

Tests

Run tests

Run composer test in the terminal.

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Using AcfService in tests

To make it easier when testing code that depends on the AcfService or parts of it, a FakeAcfService implementation is available. This implementation is useful when you want to test your code without having to rely on the ACF functions.

Example

Consider that you have the following class that utilizes a part of the AcfService:

use AcfService\Contracts\GetFields;

class MyService
{
    public function __construct(private GetFields $acfService)
    {
    }

    public function getFields(): int
    {
        return $this->acfService->getFields();
    }
}

You can then use FakeAcfService in your tests to fake the results of the AcfService as well as verifying the calls made to the AcfService functions:

use AcfService\Implementations\FakeAcfService;
use PHPUnit\Framework\TestCase;

class MyServiceTest extends TestCase
{
    public function testGetFields()
    {
        // Given
        $fakeAcfService = new FakeAcfService(['getFields' => ['fieldName' => 'fieldValue']]);
        $myService = new MyService($fakeAcfService);

        // When
        $fields = $myService->getFields();

        // Then
        $this->assertEquals([], $acfService->methodCalls['getFields'][0]);
        $this->assertEquals(['fieldName' => 'fieldValue'], $fields);
    }
}

Passing return values to the FakeAcfService

The FakeAcfService constructor accepts an array of key-value pairs where the key is the name of the method and the value is the return value of the method.

# Using a generic return value for all calls to the method.
$fakeAcfService = new FakeAcfService(['getFields' => ['field' => 'value']]);
$fakeAcfService->getFields(); // Returns ['field' => 'value']
$fakeAcfService->getFields(321); // Returns ['field' => 'value']
$fakeAcfService->getFields(123); // Returns ['field' => 'value']

# Using a callback to determine the return value based on the arguments passed to the method.
$return         = fn($postId) => $postId === 123 ? ['field' => 'value'] : [];
$fakeAcfService = new FakeAcfService(['getFields' => $return]);
$fakeAcfService->getFields(); // Returns false
$fakeAcfService->getFields(321); // Returns false
$fakeAcfService->getFields(123); // Returns ['field' => 'value']

License

Distributed under the MIT License.

helsingborg-stad/acfservice 适用场景与选型建议

helsingborg-stad/acfservice 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 51.6k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 helsingborg-stad/acfservice 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 helsingborg-stad/acfservice 我们能提供哪些服务?
定制开发 / 二次开发

基于 helsingborg-stad/acfservice 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-24