{"id":22374774,"url":"https://github.com/helingfeng/php2js-vars","last_synced_at":"2026-03-12T02:01:58.375Z","repository":{"id":62515657,"uuid":"118992676","full_name":"helingfeng/php2js-vars","owner":"helingfeng","description":"💻 将 `PHP` 变量输出为 `JavaScript` 变量声明定义脚本 https://packagist.org/packages/helingfeng/php-javascript-transformer","archived":false,"fork":false,"pushed_at":"2019-08-09T02:10:34.000Z","size":18,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-20T23:41:32.689Z","etag":null,"topics":["composer","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/helingfeng.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}},"created_at":"2018-01-26T02:05:10.000Z","updated_at":"2021-10-28T08:24:52.000Z","dependencies_parsed_at":"2022-11-02T13:03:31.244Z","dependency_job_id":null,"html_url":"https://github.com/helingfeng/php2js-vars","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/helingfeng/php2js-vars","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helingfeng%2Fphp2js-vars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helingfeng%2Fphp2js-vars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helingfeng%2Fphp2js-vars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helingfeng%2Fphp2js-vars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/helingfeng","download_url":"https://codeload.github.com/helingfeng/php2js-vars/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helingfeng%2Fphp2js-vars/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30412239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T00:40:14.898Z","status":"online","status_checked_at":"2026-03-12T02:00:07.260Z","response_time":114,"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":["composer","php"],"created_at":"2024-12-04T21:18:23.500Z","updated_at":"2026-03-12T02:01:58.360Z","avatar_url":"https://github.com/helingfeng.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP-JavaScript-Transformer\n\n将 `PHP` 变量输出为 `JavaScript` 变量声明定义脚本 扩展包\n\n## Usage\n\n```\ncomposer require helingfeng/php-javascript-transformer\n```\n\n\n### Laravel5.5 框架\n\n直接使用容器构建：\n\n```php\n\n// 包含特殊字符输出\napp('js.transformer')-\u003eput(['username' =\u003e \"'helingfeng\"]);\n# window.username = '\\'helingfeng';\n\n// 修改 namespace 输出\napp('js.transformer')-\u003esetNamespace('profile')-\u003eput(['username' =\u003e 'helingfeng']);\n# window.profile = window.profile || {};profile.username = 'helingfeng';\n\n// 输出包含 script 标签\napp('js.transformer')-\u003eincludeScript()-\u003eput(['username' =\u003e 'helingfeng']);\n# \u003cscript\u003e\n#    window.username = 'helingfeng';\n#\u003c/script\u003e\n```\n\n模板中使用 `{!!  !!}` 非转义输出\n\n### 其他方式\n\n- 字符串 String\n\n```\n$transfer = new JavaScriptTransformer();\n\n$script = $transfer-\u003eput(['username'=\u003e'helingfeng']);\n\necho $script;\n\n\n\n# output\n\nwindow.username = 'helingfeng';\n\n\n```\n\n- 数组 Array\n\n```\n$transfer = new JavaScriptTransformer();\n\n$script = $transfer-\u003eput(['person'=\u003e['name'=\u003e'helingfeng','age'=\u003e18]]);\n\necho $script;\n\n\n# output \n\nwindow.person = {\"name\":\"helingfeng\",\"age\":18};\n\n```\n\n### 使用不同的作用域，默认window\n\n```\n$transfer = new JavaScriptTransformer('home');\n\n$script = $transfer-\u003eput(['person'=\u003e['name'=\u003e'helingfeng','age'=\u003e18]]);\n\necho $script;\n\n# output \n\nwindow.home = window.home || {};home.person = {\"name\":\"helingfeng\",\"age\":18};\n\n```\n\n## Thanks\n\nTIM\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelingfeng%2Fphp2js-vars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhelingfeng%2Fphp2js-vars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelingfeng%2Fphp2js-vars/lists"}