amattu2/ini-parser
Composer 安装命令:
composer require amattu2/ini-parser
包简介
A PHP-7 .ini file parser built with error-redundancies
README 文档
README
This is a basic configuration/.ini file parser built with PHP. It's designed to be error-safe, and provides the opportunity to use a default value if one is not found.
Usage
Install
composer require amattu/IniParser
Setup
Composer project usage
require(__DIR__ . "/vendor/autoload.php"); $config = new amattu\IniParser(__DIR__ . "/conf.ini");
Without composer
require(__DIR__ . "/src/IniParser.php"); $config = new amattu\IniParser(__DIR__ . "/conf.ini");
construct
The class constructor accepts the file location (path + name), and an optional boolean argument on parsing the individual sections (usually denoted by [NAME]).
PHPDoc
/** * Configuration reader constructor * * @param string $file The path to the configuration file * @param ?bool $sections Whether to parse individual sections or not * @throws TypeError * @author Alec M. */ public function __construct(string $filename, ?bool $sections = false)
get
The get function will attempt to pull the value from the section specified (... if specified), and if not found, will return the default parameter. All of the arguments except $key are optional.
Usage
$usernameOrDefault = $config->get("USERNAME", "GMAIL_SECTION", "defaultUserName");
PHPDoc
/** * Get configuration file property * * @param string $key The property to get * @param string|null $section The section to get the property from * @param ?mixed $default value to return if the property is not found * @return $config[$key] || $default || null * @throws TypeError * @author Alec M. */ public function get(string $key, ?string $section = null, ?mixed $default = null) : mixed
Requirements & Dependencies
- PHP 7.x +
统计信息
- 总下载量: 29
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0-or-later
- 更新时间: 2022-06-05