承接 componenta/byte 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

componenta/byte

Composer 安装命令:

composer require componenta/byte

包简介

Byte, information unit, and bit-rate value objects

README 文档

README

Information-size and transfer-rate value objects.

The package contains:

  • Byte for data sizes stored internally as bytes
  • ByteUnit and InformationUnit enums for unit metadata
  • BitRate for transfer rates stored internally as bits per second
  • BitRateUnit for bit/byte-per-second labels and conversion factors

Installation

composer require componenta/byte

Related Packages

This package is standalone.

Package Why it may be used nearby
componenta/duration Transfer-time calculations pair naturally with typed durations.
componenta/validation Can validate user input before creating Byte or BitRate.
componenta/config Can store upload or bandwidth limits that are later converted to value objects.

Byte Usage

use Componenta\Stdlib\Byte;

$size = Byte::mb(1.5);

(string) $size;        // "1.5 MB"
$size->toBits();       // 12582912.0
$size->to('kB', 2);    // formatted string
$size->getValue('MB'); // numeric value in megabytes

Byte accepts numeric values and human-readable strings:

$a = Byte::fromHumanReadable('10 MB');
$b = Byte::fromBits(8_000);
$c = Byte::from(2, 'GB');

Byte Operations

Byte supports:

  • comparison: compare, equalTo, lessThan, greaterThan, range checks
  • arithmetic: increment, decrement, multiply, divide, modulo, abs
  • aggregation: sum, average, maximum, minimum
  • transfer estimates: getTransferTime, getFormattedTransferTime

Range generation is capped internally to avoid accidental huge allocations.

Bit Rate Usage

use Componenta\Stdlib\BitRate;
use Componenta\Stdlib\Byte;

$rate = BitRate::mbps(80);

$seconds = Byte::mb(10)->getTransferTime($rate);
$amount = $rate->calculateTransferAmount(1);

BitRate supports both bit and byte transfer units:

BitRate::fromHumanReadable('80 Mbps');
BitRate::fromHumanReadable('10 MBps');
BitRate::kilobytesPerSecond(512);

Unit Rules

  • Byte uses binary storage units based on 1024.
  • BitRate uses decimal transfer units based on 1000.
  • BitRate stores its internal value as bits per second.
  • Mbps and MBps are different labels: megabits per second vs megabytes per second.

Serialization

BitRate implements JsonSerializable. Byte implements Stringable and exposes explicit conversion methods for numeric values and formatted strings.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固