{"id":14954989,"url":"https://github.com/typisttech/imposter","last_synced_at":"2025-04-05T22:08:54.366Z","repository":{"id":18665102,"uuid":"84912533","full_name":"typisttech/imposter","owner":"typisttech","description":"Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins","archived":false,"fork":false,"pushed_at":"2023-04-19T20:50:58.000Z","size":723,"stargazers_count":109,"open_issues_count":12,"forks_count":16,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T21:06:43.666Z","etag":null,"topics":["composer","devtools","monkey-patching","namespace","php","wordpress","wordpress-development"],"latest_commit_sha":null,"homepage":"https://www.typist.tech/projects/imposter","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/typisttech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2017-03-14T06:17:18.000Z","updated_at":"2025-01-02T17:54:01.000Z","dependencies_parsed_at":"2024-06-18T17:00:03.540Z","dependency_job_id":null,"html_url":"https://github.com/typisttech/imposter","commit_stats":{"total_commits":332,"total_committers":5,"mean_commits":66.4,"dds":0.2831325301204819,"last_synced_commit":"0282df368b1862594f7ad09e50dbb264dbb146ec"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typisttech%2Fimposter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typisttech%2Fimposter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typisttech%2Fimposter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typisttech%2Fimposter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/typisttech","download_url":"https://codeload.github.com/typisttech/imposter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406091,"owners_count":20933803,"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":["composer","devtools","monkey-patching","namespace","php","wordpress","wordpress-development"],"created_at":"2024-09-24T13:10:20.993Z","updated_at":"2025-04-05T22:08:54.343Z","avatar_url":"https://github.com/typisttech.png","language":"PHP","readme":"\u003cdiv align=\"center\"\u003e\n\n# Imposter\n\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n\n[![Packagist Version](https://img.shields.io/packagist/v/typisttech/imposter.svg?style=flat-square)](https://packagist.org/packages/typisttech/imposter)\n[![Packagist Downloads](https://img.shields.io/packagist/dt/typisttech/imposter.svg?style=flat-square)](https://packagist.org/packages/typisttech/imposter)\n[![PHP from Packagist](https://img.shields.io/packagist/php-v/TypistTech/imposter?style=flat-square)](https://packagist.org/packages/typisttech/imposter)\n[![CircleCI](https://img.shields.io/circleci/build/gh/TypistTech/imposter?style=flat-square)](https://circleci.com/gh/TypistTech/imposter)\n[![Codecov](https://img.shields.io/codecov/c/gh/typisttech/imposter?style=flat-square)](https://codecov.io/gh/TypistTech/imposter)\n[![License](https://img.shields.io/github/license/TypistTech/imposter.svg?style=flat-square)](https://github.com/TypistTech/imposter/blob/master/LICENSE)\n[![Twitter Follow @TangRufus](https://img.shields.io/twitter/follow/TangRufus?style=flat-square\u0026color=1da1f2\u0026logo=twitter)](https://twitter.com/tangrufus)\n[![Hire Typist Tech](https://img.shields.io/badge/Hire-Typist%20Tech-ff69b4.svg?style=flat-square)](https://www.typist.tech/contact/)\n\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cstrong\u003eWrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins.\u003c/strong\u003e\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n  Built with ♥ by \u003ca href=\"https://www.typist.tech/\"\u003eTypist Tech\u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n**Imposter** is an open source project and completely free to use.\n\nHowever, the amount of effort needed to maintain and develop new features is not sustainable without proper financial backing. If you have the capability, please consider donating using the links below:\n\n\u003cdiv align=\"center\"\u003e\n\n[![GitHub via Sponsor](https://img.shields.io/badge/Sponsor-GitHub-ea4aaa?style=flat-square\u0026logo=github)](https://github.com/sponsors/TangRufus)\n[![Sponsor via PayPal](https://img.shields.io/badge/Sponsor-PayPal-blue.svg?style=flat-square\u0026logo=paypal)](https://typist.tech/go/paypal-donate/)\n[![More Sponsorship Information](https://img.shields.io/badge/Sponsor-More%20Details-ff69b4?style=flat-square)](https://typist.tech/donate/imposter/)\n\n\u003c/div\u003e\n\n---\n\nWrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins.\n\n## Why?\n\nBecause of the lack of dependency management in WordPress, if two plugins bundled conflicting versions of the same package, hard-to-reproduce bugs arise.\nMonkey patching composer vendor packages, wrapping them inside your own namespace is a less-than-ideal solution to avoid such conflicts.\n\nSee:\n- [A Narrative of Using Composer in a WordPress Plugin](https://wptavern.com/a-narrative-of-using-composer-in-a-wordpress-plugin)\n- [A Warning About Using Composer With WordPress](https://wppusher.com/blog/a-warning-about-using-composer-with-wordpress/)\n- [Plugin Dependencies (Yet Another Plugin Dependencies Ticket)](https://core.trac.wordpress.org/ticket/22316)\n\n## Install\n\n\u003e If you want to hook Imposter into [composer command events](https://getcomposer.org/doc/articles/scripts.md#command-events), install [Imposter Plugin](https://github.com/TypistTech/imposter-plugin) instead.\n\u003e See: [How can I integrate Imposter with composer?](#how-can-i-integrate-imposter-with-composer)\n\nInstallation should be done via composer, details of how to install composer can be found at [https://getcomposer.org/](https://getcomposer.org/).\n\n```bash\ncomposer require typisttech/imposter\n```\n\n## Config\n\nIn your `composer.json`:\n\n```json\n\"extra\": {\n    \"imposter\": {\n        \"namespace\": \"My\\\\App\\\\Vendor\",\n        \"excludes\": [\n            \"dummy/dummy-excluded\"\n        ]\n    }\n}\n```\n\n### extra.imposter.namespace\n\n*Required* String\n\nThis is the namespace prefix to be added to vendor packages.\n\n### extra.imposter.excludes\n\n*Optional* Array of strings\n\nVendor packages which needs to be excluded from namespace prefixing.\nAll [composer-made packages](https://packagist.org/packages/composer/) are excluded by default.\nBesides, anything under the `Composer` namespace will be excluded.\n\n## Usage\n\nAfter every `$ composer install` and `$ composer update`:\n\n```php\n\u003c?php\n\nuse TypistTech\\Imposter\\ImposterFactory;\n\n$imposter = ImposterFactory::forProject('/path/to/project/root');\n$imposter-\u003erun();\n```\n\nThe above snippet:\n1. Look for `/path/to/project/root/composer.json`\n1. Find out [vendor-dir](https://getcomposer.org/doc/06-config.md#vendor-dir)\n1. Find out all [required packages](https://getcomposer.org/doc/04-schema.md#require), including those required by dependencies\n1. Find out all [autoload paths](https://getcomposer.org/doc/04-schema.md#autoload) for all required packages\n1. Prefix all namespaces with the imposter namespace defined in your `composer.json`\n\nBefore:\n```php\n\u003c?php\n\nnamespace Dummy\\File;\n\nuse AnotherDummy\\{\n    SubAnotherDummy, SubOtherDummy\n};\nuse Composer;\nuse Composer\\Plugin\\PluginInterface;\nuse Dummy\\SubOtherDummy;\nuse OtherDummy\\SubOtherDummy;\nuse RuntimeException;\nuse \\UnexpectedValueException;\nuse function OtherVendor\\myFunc;\nuse const OtherVendor\\MY_MAGIC_NUMBER;\n\n$closure = function () use ($aaa) {\n    // Just testing.\n};\n\nclass DummyClass\n{\n    public function useClosure()\n    {\n        array_map(function () use ($xxx) {\n            // Just testing.\n        }, []);\n    }\n}\n\nfunction dummyFunction(string $namespace = null, string $use = null): array\n{\n    if (! is_null($namespace) \u0026\u0026 $namespace === 'dummy string' \u0026\u0026 $use === 'dummy string') {\n        // Just testing.\n    }\n\n    return [];\n}\n\nforeach ([] as $namespace =\u003e $prefix) {\n    $aaaa = '{' . $namespace . '}' . $prefix;\n}\n\n/** Just a comment for testing $namespace transformation */\n```\n\nAfter:\n```php\n\u003c?php\n\nnamespace MyPlugin\\Vendor\\Dummy\\File;\n\nuse MyPlugin\\Vendor\\AnotherDummy\\{\n    SubAnotherDummy, SubOtherDummy\n};\nuse Composer;\nuse Composer\\Plugin\\PluginInterface;\nuse MyPlugin\\Vendor\\Dummy\\SubOtherDummy;\nuse MyPlugin\\Vendor\\OtherDummy\\SubOtherDummy;\nuse RuntimeException;\nuse \\UnexpectedValueException;\nuse function MyPlugin\\Vendor\\OtherVendor\\myFunc;\nuse const MyPlugin\\Vendor\\OtherVendor\\MY_MAGIC_NUMBER;\n\n$closure = function () use ($aaa) {\n    // Just testing.\n};\n\nclass DummyClass\n{\n    public function useClosure()\n    {\n        array_map(function () use ($xxx) {\n            // Just testing.\n        }, []);\n    }\n}\n\nfunction dummyFunction(string $namespace = null, string $use = null): array\n{\n    if (! is_null($namespace) \u0026\u0026 $namespace === 'dummy string' \u0026\u0026 $use === 'dummy string') {\n        // Just testing.\n    }\n\n    return [];\n}\n\nforeach ([] as $namespace =\u003e $prefix) {\n    $aaaa = '{' . $namespace . '}' . $prefix;\n}\n\n/** Just a comment for testing $namespace transformation */\n```\n\n---\n\n\u003cp align=\"center\"\u003e\n  \u003cstrong\u003eTypist Tech is ready to build your next awesome WordPress site. \u003ca href=\"https://typist.tech/contact/\"\u003eHire us!\u003c/a\u003e\u003c/strong\u003e\n\u003c/p\u003e\n\n---\n\n## Known Issues\n\n**Help Wanted.** Pull requests are welcomed.\n\n1. Traits are not transformed\n1. Virtual packages are not supported\n\n## Frequently Asked Questions\n\n### How can I integrate imposter with composer?\n\nUse [Imposter Plugin](https://github.com/TypistTech/imposter-plugin) instead.\nIt hooks imposter into [composer command events](https://getcomposer.org/doc/articles/scripts.md#command-events).\n\n### Does imposter support `PSR4`, `PSR0`, `Classmap` and `Files`?\n\nYes for all. PSR-4 and PSR-0 autoloading, classmap generation and files includes are supported.\n\n### Can I exclude some of the packages from imposter?\n\nYes, see [`extra.imposter.excludes`](#extraimposterexcludes).\nAll [composer made packages](https://packagist.org/packages/composer/) are excluded by default.\n\n### How about `require-dev` packages?\n\nImposter do nothing on `require-dev` packages because imposter is intended for avoiding production environment., not for development environment.\n\n### How about PHP built-in classes?\n\nImposter skips classes that on global namespace, for example: `\\ArrayObject`, `\\RuntimeException`\n\n### How about packages that don't use namespaces?\n\nNot for now.\nTell me your idea by [opening an issue](https://github.com/TypistTech/imposter/issues/new).\n\n### How about packages that use fully qualified name?\n\nNot for now. We need a better regex(or something better than regex) in the [Transformer](src/Transformer.php) class.\nTell me your idea by [opening an issue](https://github.com/TypistTech/imposter/issues/new)\n\n### The whole imposter situation is horrible. What can we do about it?\n\nUntil WordPress core comes up with a [solution on dependency managment](https://core.trac.wordpress.org/ticket/22316), keep clam and carry on.\n\nIn the meantime, checkout these tools ~~to make WordPress suck less~~ modernizing WordPress development:\n\n- [bring OOP into WordPress](https://github.com/search?q=topic%3Awordpress-development+org%3ATypistTech\u0026type=Repositories)\n- [leveraging development practices from other languages and ecosystems, and applying them to WordPress](https://roots.io)\n\n### Which composer versions are supported?\n\nBoth v1 and v2.\n\n### Will you add support for older PHP versions?\n\nNever! This plugin will only work on [actively supported PHP versions](https://secure.php.net/supported-versions.php).\n\nDon't use it on **end of life** or **security fixes only** PHP versions.\n\n### It looks awesome. Where can I find some more goodies like this\n\n- Articles on [Typist Tech's blog](https://typist.tech)\n- [Tang Rufus' WordPress plugins](https://profiles.wordpress.org/tangrufus#content-plugins) on wp.org\n- More projects on [Typist Tech's GitHub profile](https://github.com/TypistTech)\n- Stay tuned on [Typist Tech's newsletter](https://typist.tech/go/newsletter)\n- Follow [Tang Rufus' Twitter account](https://twitter.com/TangRufus)\n- **Hire [Tang Rufus](https://typist.tech/contact) to build your next awesome site**\n\n### Where can I give 5-star reviews?\n\nThanks! Glad you like it. It's important to let me knows somebody is using this project. Please consider:\n\n- [tweet](https://twitter.com/intent/tweet?url=https%3A%2F%2Fgithub.com%2FTypistTech%2Fimposter\u0026via=tangrufus\u0026text=Wrapping%20all%20%23composer%20vendor%20packages%20inside%20your%20own%20namespace.%20Intended%20for%20%23WordPress%20plugins\u0026hashtags=php) something good with mentioning [@TangRufus](https://twitter.com/tangrufus)\n- ★ star [the Github repo](https://github.com/TypistTech/imposter)\n- [👀 watch](https://github.com/TypistTech/imposter/subscription) the Github repo\n- write tutorials and blog posts\n- **[hire](https://www.typist.tech/contact/) Typist Tech**\n\n## Testing\n\n```bash\ncomposer test\ncomposer style:check\n```\n\n## Alternatives\n\nHere is a list of alternatives that I found. However, none of these satisfied my requirements.\n\n*If you know other similar projects, feel free to edit this section!*\n\n* [Mozart](https://github.com/coenjacobs/mozart) by Coen Jacobs\n    - Works with PSR0 and PSR4\n    - Dependency packages store in a different directory\n\n* [PHP Scoper](https://github.com/humbug/php-scoper)\n    - Prefixes all PHP namespaces in a file/directory to isolate the code bundled in PHARs\n\n## Feedback\n\n**Please provide feedback!** We want to make this project as useful as possible.\nPlease [submit an issue](https://github.com/TypistTech/imposter/issues/new) and point out what you do and don't like, or fork the project and [send pull requests](https://github.com/TypistTech/imposter/pulls/).\n**No issue is too small.**\n\n## Security Vulnerabilities\n\nIf you discover a security vulnerability within this project, please email us at [imposter@typist.tech](mailto:imposter@typist.tech).\nAll security vulnerabilities will be promptly addressed.\n\n## Credits\n\n[Imposter](https://github.com/TypistTech/imposter) is a [Typist Tech](https://typist.tech) project and maintained by [Tang Rufus](https://twitter.com/TangRufus), freelance developer for [hire](https://www.typist.tech/contact/).\n\nFull list of contributors can be found [here](https://github.com/TypistTech/imposter/graphs/contributors).\n\n## License\n\n[Imposter](https://github.com/TypistTech/imposter) is released under the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":["https://github.com/sponsors/TangRufus"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypisttech%2Fimposter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypisttech%2Fimposter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypisttech%2Fimposter/lists"}