{"id":27131881,"url":"https://github.com/rezen/proxyz","last_synced_at":"2025-07-03T18:33:59.366Z","repository":{"id":62535271,"uuid":"290341605","full_name":"rezen/proxyz","owner":"rezen","description":"Uses namespaced functions to replaced native functions","archived":false,"fork":false,"pushed_at":"2021-07-22T20:52:53.000Z","size":285,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T21:36:46.723Z","etag":null,"topics":["php","proxy","testing"],"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/rezen.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":"2020-08-25T22:58:26.000Z","updated_at":"2021-08-21T08:45:15.000Z","dependencies_parsed_at":"2022-11-02T14:47:25.739Z","dependency_job_id":null,"html_url":"https://github.com/rezen/proxyz","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/rezen/proxyz","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rezen%2Fproxyz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rezen%2Fproxyz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rezen%2Fproxyz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rezen%2Fproxyz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rezen","download_url":"https://codeload.github.com/rezen/proxyz/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rezen%2Fproxyz/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263379603,"owners_count":23457876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["php","proxy","testing"],"created_at":"2025-04-07T21:27:27.290Z","updated_at":"2025-07-03T18:33:59.343Z","avatar_url":"https://github.com/rezen.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# proxyz\n[![Latest Stable Version](https://poser.pugx.org/rezen/proxyz/v)](//packagist.org/packages/rezen/proxyz)\n\nIf you are trying to test a PHP application and want to override `file_get_contents` response, you're in for a heap of fun (okay, so not fun). Really, any function that interacts with stateful bits is annoying. PHP has so many functions (not objects) that are in the global namespace that make testing hard. Also if you are writing a plugin for WordPress, you are using functions in the global namespace which you can not overwrite. To mitigate some of this pain, what you need is a method proxy. A method proxy will allow you to override or watch the behaviour of a function in the global namespace effortlessly.\n\n\n\n## Install\n\n`composer require rezen/proxyz` \n\n## Example\nIn your app, wherever you init and configure things, add a wrapper  \n```php\n// Wrap around the file_get_contents method\n\\Proxyz\\addWrapper('file_get_contents', function($args, $fn) {\n    if ($args[0] === \"config.json\") {\n        return \"{}\";\n    }\n    return call_user_func_array($fn, $args);\n});\n\n// Force curl to pin the ip down\n\\Proxyz\\addOverride('curl_init', function($url=null) {\n    if (is_null($url)) {\n        return curl_init($url);\n    }\n\n    $host = parse_url($url, PHP_URL_HOST);\n    $ip = gethostbyname($host);\n\n    if (in_array($ip, ['127.0.0.1', '169.254.169.254'])) {\n        throw new \\Exception(\"Requests to internal IPs are not allowed\");\n    }\n    $resource = curl_init($url);\n    curl_setopt($resource, CURLOPT_RESOLVE, [\n        \"{$host}:443:{$ip}\",\n        \"{$host}:80:{$ip}\",\n    ]);\n    return $resource;\n});\n```\n\nWherever you need to override the `file_get_contents`, import the namespaced function.  \n```php\nuse function \\Proxyz\\Php\\Filesystem\\file_get_contents;\nuse function \\Proxyz\\Php\\Curl\\{curl_init, curl_setopt, curl_exec};\n\n$config = file_get_contents(\"config.json\");\n```\n\nOverride a class when need be!\n```php\n\\Proxyz\\addOverride(\\SplFileInfo::class, \\Sample\\Dance::class);\n$instance = \\Proxyz\\newInstance(\\SplFileInfo::class, [$first]);\n\\Sample\\Dance::class === get_class($instance);\n```\n\n## Testing\n```sh\ncomposer install\n# Unit tests\n./vendor/bin/phpunit  -d memory_limit=1024M --testdox ./test/tests/ \n\n# Performance of functions\nphp test/performance.php \n```\n\n## Todo\n- Code rewriter for detecting native functions and adding `use` imports \n- Improve WordPress references\n    - Currently ~20+ functions have variable references\n        - `ag --php '\\\u0026\\$' --ignore *class* --nofilename | awk '$1=$1'  | grep '^function' | grep '_' | grep -v 'tion _' | grep -v sodium | cut -d ' ' -f2 | cut -d'(' -f1 | sort | uniq`\n        - **Functions**\n          - add_comment_to_entry\n          - crypto_generichash_final\n          - crypto_generichash_update\n          - feed_start_element\n          - get_page_hierarchy\n          - merge_originals_with\n          - merge_with\n          - recurse_dirsize\n          - separate_comments\n          - translate_entry\n          - update_page_cache\n          - update_post_cache\n          - update_post_caches\n          - wp_add_id3_tag_data\n          - wp_cache_get\n          - wp_get_post_revision\n          - wp_getimagesize\n          - wp_handle_sideload\n          - wp_handle_upload\n          - wp_handle_upload_error\n          - wp_kses_attr_check\n          - wp_parse_str","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frezen%2Fproxyz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frezen%2Fproxyz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frezen%2Fproxyz/lists"}