{"id":18309032,"url":"https://github.com/tekintian/phpenv","last_synced_at":"2026-06-16T16:31:10.509Z","repository":{"id":193862524,"uuid":"689636751","full_name":"tekintian/phpenv","owner":"tekintian","description":"php环境下 evn环境解析处理工具类库, 支持自定义env文件加载， 自动类型过滤和转换，自动加载等功能。","archived":false,"fork":false,"pushed_at":"2023-09-22T07:40:52.000Z","size":319,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-28T10:28:13.555Z","etag":null,"topics":["env","helper","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tekintian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-10T12:50:49.000Z","updated_at":"2023-09-20T12:26:56.000Z","dependencies_parsed_at":"2023-09-22T13:48:29.905Z","dependency_job_id":null,"html_url":"https://github.com/tekintian/phpenv","commit_stats":null,"previous_names":["tekintian/phpenv"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/tekintian/phpenv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tekintian%2Fphpenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tekintian%2Fphpenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tekintian%2Fphpenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tekintian%2Fphpenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tekintian","download_url":"https://codeload.github.com/tekintian/phpenv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tekintian%2Fphpenv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34415240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["env","helper","php"],"created_at":"2024-11-05T16:10:01.498Z","updated_at":"2026-06-16T16:31:10.490Z","avatar_url":"https://github.com/tekintian.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP .ENV环境变量解析工具\n\n\n\nphp环境下 evn环境解析处理工具类库,  支持自定义env文件加载， 自动类型过滤和转换，自动加载等功能。\n\n\n\n## 使用方法： \n\n### Composer 方式\n\n1. Composer安装类库\n\n   ~~~sh\n   # 加载env类库\n   composer require  tekintian/phpenv\n   \n   # 本类库依赖 vlucas/phpdotenv 和 phpoption/phpoption 上面的命令执行后这2个依赖会自动加载\n   ~~~\n\n   \n\n2. 加载env环境配置文件和使用示例\n\n   注意 当前的入口文件位于 public 下，\n\n   ~~~php\n   # 在你的项目的入口中增加\n   require_once dirname(__DIR__) . '/vendor/autoload.php';\n   \n   # 加载自定义env文件\n   # Env::load(dirname(__DIR__), '.env');\n   # 直接使用 env 函数获取，支持默认数据和数据过滤和类型转换\n   $app_url = env(\"APP_URL\");\n   \n   var_dump($app_url);\n   \n   \n   # 获取int类型数据\n   $app_port = env(\"APP_PORT\",80,'int');\n   \n   # 获取 bool类型数据\n   $debug = env(\"APP_DEBUG\",false,'bool');\n   \n   # 其他还支持 int, float, bool, url ,ip, regexp, email, domain , string 数据过滤和验证，使用方法类似。\n   \n   ~~~\n   \n\n - 1.0.x版本使用方法\n\n   ~~~php\n   \n   # 在你的项目的入口中增加\n   require_once dirname(__DIR__) . '/vendor/autoload.php';\n   # 定义项目根目录\n   define('ROOT_PATH', dirname(__DIR__));\n   \n   use tekintian\\phpenv\\Env;\n   # 如果你的.env文件不在项目根路径中，则需要手动执行Env::load加载\n   # 加载环境变量配置文件 注意第一个参数为env环境配置文件的路径， 第二个参数为环境配置文件名mor  .env\n   #Env::load(dirname(__DIR__), '.env');\n   \n   # 使用自定义助手函数获取配置\n   // $app_url = env(\"APP_URL\", \"\");\n   \n   # 直接使用Env对象获取\n   $app_url = Env::get(\"APP_URL\");\n   \n   var_dump($app_url);\n   ~~~\n\n   \n\n3. .env 环境配置文件参考示例\n\n~~~env\nAPP_NAME=Laravel\nAPP_ENV=local\nAPP_DEBUG=true\nAPP_URL=http://localhost\n~~~\n\n\n\n\n## env 函数封装\n\n~~~php\n\u003c?php\n\nuse tekintian\\phpenv\\Env;\n\nif (!function_exists('env')) {\n\t/**\n\t * Gets the value of an environment variable.\n\t *\n\t * @param  string  $key\n\t * @param  mixed  $default\n\t * @return mixed\n\t */\n\tfunction env($key, $default = null) {\n\t\treturn Env::get($key, $default);\n\t}\n}\n~~~\n\n\n\n## 演示\n\n- 目录结构\n\n~~~txt\n├── composer.json\n├── composer.lock\n├── helper 帮助目录\n│   └── helper.php\n├── public 公共目录\n│   └── index.php  入口文件\n└── vendor 供应商目录\n    ├── autoload.php\n    ├── composer\n    ├── graham-campbell\n    ├── phpoption\n    ├── symfony\n    ├── tekintian\n    └── vlucas\n~~~\n\n\n\n- public/index.php 入口文件\n\n~~~php\n\u003c?php\n  \n// composer自动加载\nrequire_once dirname(__DIR__) . '/vendor/autoload.php';\n# 定义项目根目录\ndefine('ROOT_PATH', dirname(__DIR__));\n\n// 加载helper函数\nrequire_once dirname(__DIR__) . '/helper/helper.php';\n  \nuse tekintian\\phpenv\\Env;\n  \n// 加载.env配置文件\n#Env::load(dirname(__DIR__), '.env');\n  \n// 使用助手函数获取环境配置\n// $app_url = env(\"APP_URL\", \"\");\n\n// 直接使用Env对象获取配置\n$app_url = Env::get(\"APP_URL\", \"未知\");\n  \necho sprintf(\"Env环境变量\u003cbr\u003eAPP_URL=%s \u003cbr\u003eAPP_NAME=%s\", $app_url, env('APP_NAME'));\n\n~~~\n\n\n\nhelper/helper.php 文件\n\n~~~php\n\u003c?php\n\nuse tekintian\\phpenv\\Env;\n\nif (!function_exists('env')) {\n\t/**\n\t * Gets the value of an environment variable.\n\t *\n\t * @param  string  $key\n\t * @param  mixed  $default\n\t * @return mixed\n\t */\n\tfunction env($key, $default = null) {\n\t\treturn Env::get($key, $default);\n\t}\n}\n~~~\n\n\n\n- 运行演示\n\n~~~sh\n# 进入项目根目录执行 \nphp -S localhost:8080 -t public/\n\n# 访问测试地址 看到输出 http://localhost 即表示成功\nhttp://localhost:8080/index.php\n\n#输出：\nEnv环境变量\nAPP_URL=http://localhost\nAPP_NAME=MyApp\n~~~\n\n\n\n\n\nenv函数在配置文件中的使用示例：\n\n~~~php\n\u003c?php\n\nreturn [\n    'name' =\u003e env('APP_NAME', 'MyApp'),\n    'env' =\u003e env('APP_ENV', 'production'),\n    'debug' =\u003e (bool) env('APP_DEBUG', false),\n    'url' =\u003e env('APP_URL', 'http://localhost'),\n];\n\n\n~~~\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftekintian%2Fphpenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftekintian%2Fphpenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftekintian%2Fphpenv/lists"}