2017 © Pedro Peláez
 

library imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

image

typisttech/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  • Monday, February 12, 2018
  • by TangRufus
  • Repository
  • 1 Watchers
  • 1 Stars
  • 32,183 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 14 Versions
  • 10 % Grown

The README.md

# Imposter
[![Packagist Version](https://img.shields.io/packagist/v/typisttech/imposter.svg?style=flat-square)](https://packagist.org/packages/typisttech/imposter) [![Packagist Downloads](https://img.shields.io/packagist/dt/typisttech/imposter.svg?style=flat-square)](https://packagist.org/packages/typisttech/imposter) [![PHP from Packagist](https://img.shields.io/packagist/php-v/TypistTech/imposter?style=flat-square)](https://packagist.org/packages/typisttech/imposter) [![CircleCI](https://img.shields.io/circleci/build/gh/TypistTech/imposter?style=flat-square)](https://circleci.com/gh/TypistTech/imposter) [![Codecov](https://img.shields.io/codecov/c/gh/typisttech/imposter?style=flat-square)](https://codecov.io/gh/TypistTech/imposter) [![License](https://img.shields.io/github/license/TypistTech/imposter.svg?style=flat-square)](https://github.com/TypistTech/imposter/blob/master/LICENSE) [![Twitter Follow @TangRufus](https://img.shields.io/twitter/follow/TangRufus?style=flat-square&color=1da1f2&logo=twitter)](https://twitter.com/tangrufus) [![Hire Typist Tech](https://img.shields.io/badge/Hire-Typist%20Tech-ff69b4.svg?style=flat-square)](https://www.typist.tech/contact/)

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins.

Built with ♥ by Typist Tech , (*1)


Imposter is an open source project and completely free to use., (*2)

However, 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:, (*3)

[![GitHub via Sponsor](https://img.shields.io/badge/Sponsor-GitHub-ea4aaa?style=flat-square&logo=github)](https://github.com/sponsors/TangRufus) [![Sponsor via PayPal](https://img.shields.io/badge/Sponsor-PayPal-blue.svg?style=flat-square&logo=paypal)](https://typist.tech/go/paypal-donate/) [![More Sponsorship Information](https://img.shields.io/badge/Sponsor-More%20Details-ff69b4?style=flat-square)](https://typist.tech/donate/imposter/)

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins., (*4)

Why?

Because of the lack of dependency management in WordPress, if two plugins bundled conflicting versions of the same package, hard-to-reproduce bugs arise. Monkey patching composer vendor packages, wrapping them inside your own namespace is a less-than-ideal solution to avoid such conflicts., (*5)

See: - A Narrative of Using Composer in a WordPress Plugin - A Warning About Using Composer With WordPress - Plugin Dependencies (Yet Another Plugin Dependencies Ticket), (*6)

Install

If you want to hook Imposter into composer command events, install Imposter Plugin instead. See: How can I integrate Imposter with composer?, (*7)

Installation should be done via composer, details of how to install composer can be found at https://getcomposer.org/., (*8)

composer require typisttech/imposter

Config

In your composer.json:, (*9)

"extra": {
    "imposter": {
        "namespace": "My\\App\\Vendor",
        "excludes": [
            "dummy/dummy-excluded"
        ]
    }
}

extra.imposter.namespace

Required String, (*10)

This is the namespace prefix to be added to vendor packages., (*11)

extra.imposter.excludes

Optional Array of strings, (*12)

Vendor packages which needs to be excluded from namespace prefixing. All composer-made packages are excluded by default. Besides, anything under the Composer namespace will be excluded., (*13)

Usage

After every $ composer install and $ composer update:, (*14)

<?php

use TypistTech\Imposter\ImposterFactory;

$imposter = ImposterFactory::forProject('/path/to/project/root');
$imposter->run();

The above snippet: 1. Look for /path/to/project/root/composer.json 1. Find out vendor-dir 1. Find out all required packages, including those required by dependencies 1. Find out all autoload paths for all required packages 1. Prefix all namespaces with the imposter namespace defined in your composer.json, (*15)

Before:, (*16)

<?php

namespace Dummy\File;

use AnotherDummy\{
    SubAnotherDummy, SubOtherDummy
};
use Composer;
use Composer\Plugin\PluginInterface;
use Dummy\SubOtherDummy;
use OtherDummy\SubOtherDummy;
use RuntimeException;
use \UnexpectedValueException;
use function OtherVendor\myFunc;
use const OtherVendor\MY_MAGIC_NUMBER;

$closure = function () use ($aaa) {
    // Just testing.
};

class DummyClass
{
    public function useClosure()
    {
        array_map(function () use ($xxx) {
            // Just testing.
        }, []);
    }
}

function dummyFunction(string $namespace = null, string $use = null): array
{
    if (! is_null($namespace) && $namespace === 'dummy string' && $use === 'dummy string') {
        // Just testing.
    }

    return [];
}

foreach ([] as $namespace => $prefix) {
    $aaaa = '{' . $namespace . '}' . $prefix;
}

/** Just a comment for testing $namespace transformation */

After:, (*17)

<?php

namespace MyPlugin\Vendor\Dummy\File;

use MyPlugin\Vendor\AnotherDummy\{
    SubAnotherDummy, SubOtherDummy
};
use Composer;
use Composer\Plugin\PluginInterface;
use MyPlugin\Vendor\Dummy\SubOtherDummy;
use MyPlugin\Vendor\OtherDummy\SubOtherDummy;
use RuntimeException;
use \UnexpectedValueException;
use function MyPlugin\Vendor\OtherVendor\myFunc;
use const MyPlugin\Vendor\OtherVendor\MY_MAGIC_NUMBER;

$closure = function () use ($aaa) {
    // Just testing.
};

class DummyClass
{
    public function useClosure()
    {
        array_map(function () use ($xxx) {
            // Just testing.
        }, []);
    }
}

function dummyFunction(string $namespace = null, string $use = null): array
{
    if (! is_null($namespace) && $namespace === 'dummy string' && $use === 'dummy string') {
        // Just testing.
    }

    return [];
}

foreach ([] as $namespace => $prefix) {
    $aaaa = '{' . $namespace . '}' . $prefix;
}

/** Just a comment for testing $namespace transformation */

Typist Tech is ready to build your next awesome WordPress site. Hire us! , (*18)


Known Issues

Help Wanted. Pull requests are welcomed., (*19)

  1. Traits are not transformed
  2. Virtual packages are not supported

Frequently Asked Questions

How can I integrate imposter with composer?

Use Imposter Plugin instead. It hooks imposter into composer command events., (*20)

Does imposter support PSR4, PSR0, Classmap and Files?

Yes for all. PSR-4 and PSR-0 autoloading, classmap generation and files includes are supported., (*21)

Can I exclude some of the packages from imposter?

Yes, see extra.imposter.excludes. All composer made packages are excluded by default., (*22)

How about require-dev packages?

Imposter do nothing on require-dev packages because imposter is intended for avoiding production environment., not for development environment., (*23)

How about PHP built-in classes?

Imposter skips classes that on global namespace, for example: \ArrayObject, \RuntimeException, (*24)

How about packages that don't use namespaces?

Not for now. Tell me your idea by opening an issue., (*25)

How about packages that use fully qualified name?

Not for now. We need a better regex(or something better than regex) in the Transformer class. Tell me your idea by opening an issue, (*26)

The whole imposter situation is horrible. What can we do about it?

Until WordPress core comes up with a solution on dependency managment, keep clam and carry on., (*27)

In the meantime, checkout these tools ~~to make WordPress suck less~~ modernizing WordPress development:, (*28)

Which composer versions are supported?

Both v1 and v2., (*29)

Will you add support for older PHP versions?

Never! This plugin will only work on actively supported PHP versions., (*30)

Don't use it on end of life or security fixes only PHP versions., (*31)

It looks awesome. Where can I find some more goodies like this

Where can I give 5-star reviews?

Thanks! Glad you like it. It's important to let me knows somebody is using this project. Please consider:, (*32)

Testing

composer test
composer style:check

Alternatives

Here is a list of alternatives that I found. However, none of these satisfied my requirements., (*33)

If you know other similar projects, feel free to edit this section!, (*34)

  • Mozart by Coen Jacobs, (*35)

    • Works with PSR0 and PSR4
    • Dependency packages store in a different directory
  • PHP Scoper, (*36)

    • Prefixes all PHP namespaces in a file/directory to isolate the code bundled in PHARs

Feedback

Please provide feedback! We want to make this project as useful as possible. Please submit an issue and point out what you do and don't like, or fork the project and send pull requests. No issue is too small., (*37)

Security Vulnerabilities

If you discover a security vulnerability within this project, please email us at imposter@typist.tech. All security vulnerabilities will be promptly addressed., (*38)

Credits

Imposter is a Typist Tech project and maintained by Tang Rufus, freelance developer for hire., (*39)

Full list of contributors can be found here., (*40)

License

Imposter is released under the MIT License., (*41)

The Versions

12/02 2018

dev-master

9999999-dev https://typist.tech/projects/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

wordpress composer dependency namespace monkey-patching

12/02 2018

dev-misc

dev-misc https://typist.tech/projects/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

wordpress composer dependency namespace monkey-patching

16/01 2018

dev-readme

dev-readme https://www.typist.tech/projects/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

wordpress composer dependency namespace monkey-patching

16/01 2018

0.3.0

0.3.0.0 https://www.typist.tech/projects/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

wordpress composer dependency namespace monkey-patching

16/01 2018

dev-version-bump

dev-version-bump https://www.typist.tech/projects/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

wordpress composer dependency namespace monkey-patching

16/01 2018

dev-use-global-namespace

dev-use-global-namespace https://www.typist.tech/projects/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

wordpress composer dependency namespace monkey-patching

16/01 2018

dev-composer-update

dev-composer-update https://www.typist.tech/projects/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

wordpress composer dependency namespace monkey-patching

22/10 2017

0.2.3

0.2.3.0 https://www.typist.tech/projects/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

wordpress composer dependency namespace monkey-patching

21/08 2017

dev-rename-conduct-md

dev-rename-conduct-md https://www.typist.tech/projects/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

wordpress composer dependency namespace monkey-patching

25/03 2017

0.2.2

0.2.2.0 https://www.typist.tech/projects/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

wordpress composer dependency namespace monkey-patching

25/03 2017

0.2.1

0.2.1.0 https://www.typist.tech/projects/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

wordpress composer dependency namespace monkey-patching

25/03 2017

0.2.0

0.2.0.0 https://www.typist.tech/projects/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

wordpress composer dependency namespace monkey-patching

24/03 2017

0.1.1

0.1.1.0 https://www.typist.tech/projects/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

wordpress composer dependency namespace monkey-patching

21/03 2017

0.1.0

0.1.0.0 https://www.typist.tech/projects/imposter

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress composer dependency namespace monkey-patching