erikwang2013/season 问题修复 & 功能扩展

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

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

erikwang2013/season

Composer 安装命令:

composer require erikwang2013/season

包简介

PHP library / extension that resolves the current season from an ISO 3166-1 alpha-2 country code. Use it as a plain Composer package, or integrate with Laravel 7–11, ThinkPHP 6 / 8, Hyperf 2 / 3, and webman. Besides English season keys (spring, etc.) and Chinese names, it provides flag emoji, locali

README 文档

README

Language: English · 简体中文

PHP library / extension that resolves the current season from an ISO 3166-1 alpha-2 country code. Use it as a plain Composer package, or integrate with Laravel 7–11, ThinkPHP 6 / 8, Hyperf 2 / 3, and webman. Besides English season keys (spring, etc.) and Chinese names, it provides flag emoji, localized season names by BCP 47 locale, hemisphere detection, and optional date-based calculation.

  • Northern hemisphere: spring Mar–May, summer Jun–Aug, autumn Sep–Nov, winter Dec / Jan / Feb
  • Southern hemisphere: autumn Mar–May, winter Jun–Aug, spring Sep–Nov, summer Dec / Jan / Feb

Installation

composer require erikwang2013/season

webman plugin

After installing the dependency, from your webman project root (with webman/console installed):

php webman install erikwang2013/season

Or manually copy vendor/erikwang2013/season/src/config/plugin/erikwang2013/season to config/plugin/erikwang2013/season in your project.

Laravel 7–11

After composer require, unless you disable this package’s package discovery in composer.json, Erikwang2013\Season\Laravel\CountrySeasonServiceProvider is auto-registered and SeasonService is bound to the container (default country code comes from merged config).

Optional: publish default config:

php artisan vendor:publish --tag=country-season-config

This creates config/country_season.php; default_country_code maps to COUNTRY_SEASON_DEFAULT (default CN). Inject Erikwang2013\Season\SeasonService in controllers or services.

ThinkPHP 6 / 8

Composer’s think extension discovery registers Erikwang2013\Season\ThinkPHP\Service, binds SeasonService, and merges the package config/country_season.php into country_season. Resolve Erikwang2013\Season\SeasonService from the container or use dependency injection.

Hyperf 2 / 3

Hyperf ConfigProvider merges config: SeasonService is bound; default country code is read from country_season.default_country_code.

Optional: publish config:

php bin/hyperf.php vendor:publish erikwang2013/season

After config/autoload/country_season.php exists, adjust as needed; otherwise built-in default CN applies (override via COUNTRY_SEASON_DEFAULT or custom config).

Usage

1. Static API (any PHP project)

use Erikwang2013\Season\CountrySeason;

// English keys: spring | summer | autumn | winter
$season = CountrySeason::getSeason('CN');        // e.g. winter
$season = CountrySeason::getSeason('AU');        // Southern hemisphere, e.g. summer

// Chinese: 春 | 夏 | 秋 | 冬
$zh = CountrySeason::getSeasonNameZh('CN');

// Fixed date
$date = new \DateTimeImmutable('2026-06-15');
$season = CountrySeason::getSeason('US', $date);  // summer

// Hemisphere
$hemisphere = CountrySeason::getHemisphere('BR'); // south
$valid = CountrySeason::isValidCode('XX');        // true/false

Flag emoji (Unicode regional indicators)

$flag = CountrySeason::getCountryFlagEmoji('CN');  // 🇨🇳
$flag = CountrySeason::getCountryFlagEmoji('us');  // case-insensitive → 🇺🇸

Invalid or non–two-letter codes throw InvalidArgumentException (same as getSeason, etc.).

Localized season names (BCP 47)

getSeasonNameLocalized uses the country code for the season (including hemisphere) and the locale for the label:

// Second argument is locale: zh_CN, en_US, ja, de, fr_FR, etc. (- and _ both OK)
$name = CountrySeason::getSeasonNameLocalized('DE', 'de_DE');   // e.g. Frühling
$name = CountrySeason::getSeasonNameLocalized('US', 'en_US');   // fall (US English)
$name = CountrySeason::getSeasonNameLocalized('GB', 'en_GB');   // autumn (UK English)

// With a specific date
$date = new \DateTimeImmutable('2026-03-01');
CountrySeason::getSeasonNameLocalized('AU', 'en', $date);

List built-in locale tags (lowercase + underscore):

$locales = CountrySeason::getSupportedLocales();

Locale resolution: full tag first (e.g. zh_CN), then language only (e.g. zh), else fallback to en.

Built-ins cover common languages (EN/ZH/JA/KO, DE/FR/ES/IT/PT, RU/NL/PL/SV/UK, AR/HI/TH/VI/ID/TR, CS/DA/FI/NO, RO/EL/HE/HU, etc.); see getSupportedLocales() for the full set. For unlisted variants, try the language code (e.g. es) or map/extend externally.

2. Global helpers (when autoloaded)

country_season('JP');       // e.g. spring
country_season_zh('AU');    // Chinese name, e.g. 秋

country_season_flag('FR');  // 🇫🇷
country_season_locale('IT', 'it_IT');  // e.g. Primavera
country_season_locale('KR', 'ko', $date);  // optional date

3. Laravel / ThinkPHP / Hyperf — SeasonService

After integration, container SeasonService uses framework config (country_season.default_country_code, same as package config/country_season.php). getSeasonForDefault() uses that default country.

4. webman — SeasonService (after plugin install)

Register once (e.g. in config/bootstrap.php), then resolve from the container:

use Erikwang2013\Season\SeasonService;
use support\Container;

Container::singleton(SeasonService::class, function () {
    $code = config('plugin.erikwang2013.season.app.default_country_code', 'CN');

    return new SeasonService(\is_string($code) ? $code : 'CN');
});
use support\Container;
use Erikwang2013\Season\SeasonService;

/** @var SeasonService $seasonService */
$seasonService = Container::get(SeasonService::class);

$seasonService->getSeason('CN');
$seasonService->getSeasonNameZh('AU');
$seasonService->getCountryFlagEmoji('JP');
$seasonService->getSeasonNameLocalized('FR', 'fr_FR');
$seasonService->getSeasonForDefault();
$seasonService->getHemisphere('NZ');
$seasonService->isValidCode('AU');          // true
$seasonService->getSupportedLocales();       // ['ar', 'cs', 'da', ...]

5. Configuration (webman)

File: config/plugin/erikwang2013/season/app.php

return [
    'enable' => true,
    'default_country_code' => 'CN',  // or env('COUNTRY_SEASON_DEFAULT', 'CN')
];

Country codes

  • ISO 3166-1 alpha-2 two-letter codes (e.g. CN, US, JP, AU).
  • Southern countries (AU, AR, NZ, BR, etc.) are mapped; others are treated as northern hemisphere.

API summary

Method / function Description
CountrySeason::getSeason / country_season English season key
CountrySeason::getSeasonNameZh / country_season_zh Chinese season name
CountrySeason::getCountryFlagEmoji / country_season_flag Flag emoji
CountrySeason::getSeasonNameLocalized / country_season_locale Localized name
CountrySeason::getSupportedLocales Built-in locales
CountrySeason::getHemisphere north / south
SeasonService::getSeasonForDefault Uses configured default country
SeasonService::isValidCode Check code format
SeasonService::getSupportedLocales Built-in locales

Exceptions and validation

  • Country code must be two letters A–Z (case-insensitive); otherwise InvalidArgumentException from getSeason, getCountryFlagEmoji, etc.
  • isValidCode() only checks format; it does not validate real ISO country codes.

Extending CountrySeason

resolveSeasonNamesForLocale() and seasonToNameZh() are protected static — subclass CountrySeason to add or customize locale data without forking.

setDefaultCountryCode() validates eagerly

SeasonService::setDefaultCountryCode() now throws InvalidArgumentException immediately on an invalid code, instead of deferring the error to the next getSeasonForDefault() call.

Testing

composer test

44 tests covering season mapping, hemisphere detection, flag emoji, locale fallback, SeasonService defaults, and error handling.

Requirements

  • PHP >= 8.1
  • mbstring extension (flag emoji uses mb_chr)
  • Optional: workerman/webman-framework, illuminate/support, topthink/framework, hyperf/framework

开源不易,欢迎支持

微信 支付宝
微信 支付宝

License

MIT

erikwang2013/season 适用场景与选型建议

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

它主要适用于以下技术方向: 「php」 「laravel」 「country」 「ISO 3166-1」 「thinkphp」 「season」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 erikwang2013/season 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-07