samluvanda/system 问题修复 & 功能扩展

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

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

samluvanda/system

最新稳定版本:v1.0.1

Composer 安装命令:

composer require samluvanda/system

包简介

A PHP utility library for environment variables, user context, and system information.

README 文档

README

A PHP utility library for accessing environment variables, user context, system settings, and runtime information.

Namespace: SamLuvanda\System

📦 Installation

Install via Composer:

composer require samluvanda/system

🚀 Features

  • Get and set environment variables
  • Access OS, hostname, PHP version, current user, working directory
  • Retrieve memory usage, processor count, and tick count
  • CLI argument support

🧪 Example Usage

use SamLuvanda\System\Environment;

echo Environment::phpVersion();          // "8.3.1"
echo Environment::getEnv('APP_ENV');     // "production"
echo Environment::cwd();                 // "/var/www/html"

🧩 Method Reference

getEnv(string $key, mixed $default = null): mixed

Returns the value of an environment variable or the default value if it's not set.

Example:

Environment::getEnv('APP_ENV', 'production');

setEnv(string $key, string $value): void

Sets an environment variable.

Example:

Environment::setEnv('APP_ENV', 'local');

hasEnv(string $key): bool

Checks whether an environment variable exists.

Example:

Environment::hasEnv('APP_ENV');

allEnv(): array

Returns all environment variables as an associative array.

Example:

Environment::allEnv();

machineName(): string

Returns the name of the current machine/host.

Example:

Environment::machineName();

userName(): string

Returns the name of the user running the PHP script.

Example:

Environment::userName();

userDomainName(): ?string

Returns the user domain name if available (Windows-specific).

Example:

Environment::userDomainName();

osVersion(): string

Returns the full operating system information string.

Example:

Environment::osVersion();

processorCount(): ?int

Returns the number of processor cores.

Example:

Environment::processorCount();

exit(int $code = 0): void

Terminates script execution with the specified exit code.

Example:

Environment::exit(1);

cwd(): string

Returns the current working directory.

Example:

Environment::cwd();

newLine(): string

Returns the newline character(s) for the current OS.

Example:

echo 'Line 1' . Environment::newLine() . 'Line 2';

phpVersion(): string

Returns the current PHP version.

Example:

Environment::phpVersion();

cliArgs(): array

Returns command-line arguments passed to the script.

Example:

print_r(Environment::cliArgs());

workingSet(): int

Returns the amount of memory allocated to the script in bytes.

Example:

Environment::workingSet();

tickCount(): int

Returns the number of milliseconds elapsed since script start.

Example:

Environment::tickCount();

📁 Directory Structure

src/
└── System/
    └── Environment.php

🤝 Contributing

Contributions are welcome! To contribute:

  1. Fork the repository
  2. Create a new branch (git checkout -b feature-name)
  3. Commit your changes (git commit -m "Add feature")
  4. Push to the branch (git push origin feature-name)
  5. Open a pull request

Please follow PSR-12 coding standards and ensure all code is tested.

📄 License

This project is open-sourced under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-22