Shade/Inject composer dependencies into PocketMine-MP plugins.

Overview

ComposerShader

README for v0.2.0-dev


Important Note:

This is not perfect, nor will it ever be, with several checks for common uses of certain functions and namespacing we can attempt to shade these calls, but a package may do some dynamic requiring/defining and break at runtime.

You can however fork the library/package you want and modify if possible the way it does the dynamic calls so it can be shaded.

Why shade ?

As more advanced projects and plugins become readily available through github and poggit the chance of a namespace collision increases exponentially.

For example take the following structure

  • plugin A (JaxkDev\TestPlugin)

    • Promise v1.0 (React\Promise)
  • plugin B (AnotherPersons\TestPlugin)

    • Promise v2.0 (React\Promise)

Unshaded these plugins would collide, as you can see they both require React\Promise but two different versions. So not only do they have conflicts in namespace they also differ in behaviour and cannot be shared between them.

And that's where shading comes in, like poggit's virion scheme all the composer dependencies for a plugin gets put into a unique namespace covered by the plugins main class namespace,

In this case plugin A's dependency would be shaded to JaxkDev\TestPlugin\vendor12345678\React\Promise

and plugin B's shaded to AnotherPerson\TestPlugin\vendor87654321\React\Promise

Now each plugin has its own version of the same library/package so the plugins are using exactly what they expect and behaviour is constant because as you can see the namespaces no longer collide.

Requirements

  • PHP >= 8.0
  • PHP extension yaml
  • composer dependencies pre-installed (run composer install)
  • plugin source code

Usage & Docs

The script shade.php should be run via CLI (outside of pmmp) in the directory of the plugin.

Usage: php shade.php SHADE_PREFIX

SHADE_PREFIX Optional, 4+ chars (a-Z, 0-9)

Examples: php shade.php somePrefixHere shades to YourPlugin\NameSpace\somePrefixHere\

Usage in the plugin:

By default, it's more than likely shade.php will show: Plugin source does not require 'COMPOSER_AUTOLOAD' but XX autoload files have been found.

This is because your plugin does not call: require_once(\YourPlugin\NameSpace\COMPOSER_AUTOLOAD);

If your plugin uses the dependencies on the main thread you should call this in the main class. eg

Main.php

<?php /** @noinspection ALL */
/*
 * License and notes here if applicable.
 */

namespace YourPlugin\NameSpace;

//Your IDE won't see this constant declared. so its ok to ignore the warning.
/** @noinspection PhpUndefinedConstantInspection */
require_once(\YourPlugin\NameSpace\COMPOSER_AUTOLOAD);

use React\Promise;  //Composer libs can be use'd anywhere in your plugin
                    //see notes below for threading.

class Main extends PluginBase{

}

If you are using the composer libraries/packages in another Thread you must call the require_once(\YourPlugin\NameSpace\COMPOSER_AUTOLOAD); inside the thread.

Note the constant will only be available if the thread was started with PTHREADS_INHERIT_CONSTANTS.

To reduce possibility of duplicate constant definitions It's suggested to start threads with PTHREADS_INHERIT_NONE and pass the constant/path through the constructor.

PluginsThread.php

<?php  /** @noinspection ALL */

namespace YourPlugin\NameSpace;

class PluginsThread extends Thread{

    private $composerPath;

    public function __construct(string $composerPath, ...){
        $this->composerPath = $composerPath;
        //...
        //Dont reference any composer libs here.
    }

    public function run(){
        /** @noinspection PhpUndefinedConstantInspection */
        require_once($this->composerPath);
        //...
        //Composer libs are now available for use/reference from here onwards.
    }
}

Main.php

<?php /** @noinspection ALL */
//Somewhere in your Main class where appropriate
/** @noinspection PhpUndefinedConstantInspection */
$thread = new PluginsThread(\YourPlugin\NameSpace\COMPOSER_AUTOLOAD);
$thread->start(PTHREADS_INHERIT_NONE);

\YourPlugin\NameSpace\COMPOSER_AUTOLOAD Is the namespace to the plugins main file.

eg plugin.yml

main: Test\NameSpace\Main
# so here your namespace is \Test\NameSpace\COMPOSER_AUTOLOAD

# if main was: Hello\Another\NameSpace\ButLonger\MainClass
# It would be \Hello\Another\NameSpace\ButLonger\COMPOSER_AUTOLOAD
You might also like...
Ied plugin composer - Inspired Plugin Composer: Create, publish and edit plugins from within Textpattern CMS.

ied_plugin_composer Create, publish and edit plugins from within Textpattern CMS. Creates a new page under the Extensions tab where you can edit and e

Composer plugin that wraps all composer vendor packages inside your own namespace. Intended for WordPress plugins.

Imposter Plugin Composer plugin that wraps all composer vendor packages inside your own namespace. Intended for WordPress plugins. Built with ♥ by Typ

Developers tool for WordPress plugins: Wraps all your projects dependencies in your own namespace

Developers tool for WordPress plugins: Wraps all your projects dependencies in your own namespace, in order to prevent conflicts with other plugins loading the same dependencies in different versions.

Assets Manager for
Assets Manager for "Vitewind" Theme, will inject CSS and JS assets for "Vitewind" theme to work properly with viteJS in development and production

Vitewind Manager plugin 💨 Windi CSS and ⚡️ Vite, for 🍂 OctoberCMS & ❄️ WinterCMS Introduction This is a helper plugin for 💨 Vitewind theme, don't i

sqlscan is quick web scanner for find an sql inject point
sqlscan is quick web scanner for find an sql inject point

sqlscan sqlscan is quick web scanner for find an sql inject point. not for educational, this is for hacking. use sitemap for best result Simple to use

A WordPress plugin that provides a programmatic interface to register data providers and display (inject) the data in templates asynchronously

A WordPress plugin that provides a programmatic interface to register data providers and display (inject) the data in templates asynchronously

This Plugin is used to install and activate multiple plugins in one go. I was facing problem uploading plugins one by one so I developed this to solve my problem. Hope you will enjoy using this plugin.

=== Bulk Plugin Installer === Contributors: jawadarshad Donate link: https://jawadarshad.io/ Tags: bulk plugin installer, import multiple plugins, up

A composer plugin, to install differenty types of composer packages in custom directories outside the default composer default installation path which is in the vendor folder.

composer-custom-directory-installer A composer plugin, to install differenty types of composer packages in custom directories outside the default comp

Check your Composer dependencies at runtime.

Composition Composition provides a lightweight and generic API, that you can use to check your environment at runtime, instead of manually go checking

Easily parse your project's Composer configuration, and those of its dependencies, at runtime

Composed This library provides a set of utility functions designed to help you parse your project's Composer configuration, and those of its dependenc

Detect unused composer dependencies
Detect unused composer dependencies

Project scanner for detect unused composer dependencies Versions Use 1.3.x@dev versions for projects with php 5.6, 7.0 Use 2.x versions for projects w

This composer plugin is a temporary implementation of using symbolic links to local packages as dependencies to allow a parallel work process

Composer symlinker A Composer plugin to install packages as local symbolic links. This plugin is a temporary implementation of using symbolic links to

Plugin for composer to apply patches onto dependencies.

composer-patches-plugin This plugin allows you to provide patches for any package from any package. If you don't want a patch package outside the root

Composer bin plugin — Isolate your bin dependencies

Composer bin plugin — Isolate your bin dependencies Table of Contents Why? How does this plugin work? Installation Usage Example The all bin namespace

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

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

WordPress Packagist — manage your plugins with Composer

WordPress Packagist This is the repository for wpackagist.org which allows WordPress plugins and themes to be managed along with other dependencies us

Generalized user interface framework for PocketMine plugins.

ActionApi Generalized user interface framework for PocketMine plugins. How does this work? ActionApi introduces the following concepts: Action Action

Plugins LevelSystem support Pocketmine-mp
Plugins LevelSystem support Pocketmine-mp

Plugins LevelSystem support Pocketmine-mp

Utilities for concurrent programming of PocketMine-MP plugins.
Utilities for concurrent programming of PocketMine-MP plugins.

Utilities for concurrent programming of PocketMine-MP plugins Overview Plugin that implements the pthreads channels and in the future, promises (which

Releases(0.1.0)
  • 0.1.0(Apr 19, 2021)

    First usable tag/release, hopefully it can be useful to someone out there, this was originally just an experiment but worked out pretty well and found it could be altered from my specific use case for https://github.com/JaxkDev/DiscordBot to something much more generic for everyone to use.

    Hopefully you understand the README if not contact details are attached somewhere, issues & PR's welcome.

    Source code(tar.gz)
    Source code(zip)
Owner
Jack Honour
Backend developer, No paid work everything you see is free forever.
Jack Honour
Anticheat for PocketMine-MP API-3.0.0.

Lunar AntiCheat for PocketMine-MP API 3.0.0 This project is in fast-development mode, anything may change. This anticheat is used in production server

TinyRick 19 Jan 4, 2023
A PocketMine-MP plugin which let's you whitelist specific commands on specific worlds.

LevelLimiter A PocketMine-MP plugin which let's you whitelist specific commands on specific worlds. Config.yml Set up the commands and the whitelisted

MCA7 7 Aug 6, 2022
HCF Plugin for PocketMine-MP

Notice This add-on is under development, if you want to test the add-on it is at you disposal see crashes, instabilities, addictions malfunction, etc.

SrDevYT 11 Jan 1, 2023
A fully customizable CPS plugin for PocketMine-MP servers.

CPS A fully customizable CPS plugin for PocketMine-MP servers. Features: CPS Limiter CPS Popup CPS Alerts Discord Webhook Fully Configurable If you ha

Austin Desrochers 3 May 10, 2022
A Pocketmine-MP Plugin that keeps track of Player Statistics

VecnaLeaderboards This plugin will be an advanced Leaderboards plugin, with tons of supported feature, simple fast and easy! This plugin's current fea

null 21 Nov 5, 2022
Manhunt plugin for PocketMine-MP

Manhunt Manhunt is a minigame that you can play with your friends. In this game there are runners and hunters. Hunters are trying to kill runners. If

Oğuzhan 3 Jul 16, 2021
A PHP script that converts PMMP-3 Plugins into PMMP-4 plugins

This script tries to convert pm3 plugins to pm4 as good as possible, but sadly not perfect. Please open issues if you find any unexpected behaviour, to help improving this script.

null 43 Dec 3, 2022
A Composer tool to show unused Composer dependencies by scanning your code.

composer-unused A Composer tool to show unused Composer dependencies by scanning your code. Created by Andreas Frömer and contributors, logo by Caneco

null 1.3k Jan 7, 2023
A CLI tool to check whether a specific composer package uses imported symbols that aren't part of its direct composer dependencies

A CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package. This will prevent you from using "soft" dependencies that are not defined within your composer.json require section.

Matthias Glaub 722 Dec 30, 2022
Composer plugin that wraps all composer vendor packages inside your own namespace. Intended for WordPress plugins.

Imposter Plugin Composer plugin that wraps all composer vendor packages inside your own namespace. Intended for WordPress plugins. Built with ♥ by Typ

Typist Tech 127 Dec 17, 2022