PHPackages                             104corp/support - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. 104corp/support

AbandonedLibrary[Utility &amp; Helpers](/categories/utility)

104corp/support
===============

The 104corp support package.

2.0.0(2y ago)161.6k11BSD-3-ClausePHPPHP ^7.4 | ^8.0

Since Aug 3Pushed 2y ago4 watchersCompare

[ Source](https://github.com/104corp/php-support)[ Packagist](https://packagist.org/packages/104corp/support)[ RSS](/packages/104corp-support/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (7)Used By (1)

Support
=======

[](#support)

[![Build Status](https://camo.githubusercontent.com/aabfe72a88054e73dfc97787f418191f34c853830de0d8d9f43ff234685fd803/68747470733a2f2f7472617669732d63692e6f72672f313034636f72702f7068702d737570706f72742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/104corp/php-support)[![codecov](https://camo.githubusercontent.com/1b12b79c2c8d27140cf0bf5fbbcd71871147a39ccaf1fc9cd945aa1dbe36613d/68747470733a2f2f636f6465636f762e696f2f67682f313034636f72702f7068702d737570706f72742f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/104corp/php-support)[![Latest Stable Version](https://camo.githubusercontent.com/0eae252e5cb2d65e13f2ace9f8a5b77a297f2c6c184ff9b88f0d5b73e4cd656c/68747470733a2f2f706f7365722e707567782e6f72672f313034636f72702f737570706f72742f762f737461626c65)](https://packagist.org/packages/104corp/support)[![Total Downloads](https://camo.githubusercontent.com/8db48e49b1ba8bcb16de2869b270ab09122a70c081bdfa9d0f4518fef5fb82d0/68747470733a2f2f706f7365722e707567782e6f72672f313034636f72702f737570706f72742f642f746f74616c2e737667)](https://packagist.org/packages/104corp/support)[![License](https://camo.githubusercontent.com/df0310c2914ba1ba072a012446eb2097dae50dfbde633801a735beb7102041ac/68747470733a2f2f706f7365722e707567782e6f72672f313034636f72702f737570706f72742f6c6963656e7365)](https://packagist.org/packages/104corp/support)

The 104corp support package.

系統需求
----

[](#系統需求)

- PHP &gt;= 5.5

安裝
--

[](#安裝)

使用 [Composer](https://getcomposer.org/) 安裝

```
$ composer require 104corp/support

```

說明
--

[](#說明)

這裡是常用的工具實作成 Trait ，可以直接拿來使用，這樣能避免複製貼上所引發的問題。

### ContainerAwareTrait

[](#containerawaretrait)

ContainerAwareTrait 實作設定 PSR-11 的物件。

### GuzzleClientAwareTrait

[](#guzzleclientawaretrait)

GuzzleClientAwareTrait 實作了如何設定 [Guzzle](http://docs.guzzlephp.org/en/latest/) Client 的方法。

它的實作方法是：當 `getHttpClient()` 時，如果 $httpClient 已被 `setHttpClient()` 設定的話，就回傳現有的 $httpClient ；反之，就 new 一個新的。

這個做法可以在測試跟實際使用之間，取得一個較好的平衡。平常使用通常不需要很在意如何初始化 Guzzle ，但在測試需要使用 mock 的時候，這樣設計將能方便地替換真實物件。

### HttpClientAwareTrait

[](#httpclientawaretrait)

HttpClientAwareTrait 也是設定 [Guzzle](http://docs.guzzlephp.org/en/latest/) Client 的方法。不一樣的是，它只依賴 interface 而不是實作，這可以在需要替換 Guzzle 時，有個介面可以實作讓整個程式不需要大改。

### LoggerTrait

[](#loggertrait)

LoggerTrait 繼承了 [`Psr\Log\LoggerAwareTrait`](https://github.com/php-fig/log/blob/master/Psr/Log/LoggerAwareTrait.php) ，同時實作 log 方法去使用它提供的 logger 成員。另外 log 方法有做 logger 是否為 null 判斷。

使用它的 class 可以直接在任何角落使用 log 方法來操作 logger ，而且不需要在意 logger 物件是否存在。而要不要記 log 會由使用這個 class 的角色決定是否要 `setLogger()` 。因此可以在測試初始化的時候忽略，而在上線的時候傳入需要的 Logger 。

以下是簡單的範例：

```
use Corp104\Support\LoggerTrait;
use Psr\Log\LogLevel;

class MyClass {
    use LoggerTrait;

    public function doSomething() {
        $this->log(LogLevel::INFO, 'I do something');
    }
}

// --------------------------------------

$foo = new MyClass();
$foo->doSomething();  // 這裡不會記 log

$logger = new \Monolog\Logger('name');
$foo->setLogger($logger);
$foo->doSomething();  // 這裡會記 log
```

另外， `setLogger()` 是認 interface 的，代表包括自己寫的 logger 之外，還能傳入第三方所寫的 logger ，如 [Monolog](https://github.com/Seldaek/monolog) 。

Contributing
------------

[](#contributing)

開發相關資訊可以參考 [CONTRIBUTING](/CONTRIBUTING.md) ，有任何問題或建議，歡迎發 issue ；如果覺得程式碼可以修更好的話，也歡迎發 PR 修正。

PR 如何使用可以參考 [Git 官方文件](https://git-scm.com/book/zh-tw/v2/GitHub-%E5%8F%83%E8%88%87%E4%B8%80%E5%80%8B%E5%B0%88%E6%A1%88)。

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 95.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~438 days

Recently: every ~501 days

Total

6

Last Release

1019d ago

Major Versions

1.x-dev → 2.0.02023-08-03

PHP version history (2 changes)1.2.0PHP &gt;=5.5

2.0.0PHP ^7.4 | ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/20872dcc4b888075f03819d5470db8198ffcc5f9edb791aba5f007e34355a6c9?d=identicon)[MilesChou](/maintainers/MilesChou)

---

Top Contributors

[![MilesChou](https://avatars.githubusercontent.com/u/1258752?v=4)](https://github.com/MilesChou "MilesChou (23 commits)")[![Tai-ch0802](https://avatars.githubusercontent.com/u/8073199?v=4)](https://github.com/Tai-ch0802 "Tai-ch0802 (1 commits)")

---

Tags

php

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/104corp-support/health.svg)

```
[![Health](https://phpackages.com/badges/104corp-support/health.svg)](https://phpackages.com/packages/104corp-support)
```

###  Alternatives

[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[llm/mcp-server

PHP SDK for building MCP servers

431.1k](/packages/llm-mcp-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
