Modern version of pocketmine forms API, ported to PHP 8.0+ with high quality code and phpstan integration

Overview

forms

build php api

Modern version of pocketmine forms API, ported to PHP 8.0+ with high quality code and phpstan integration

Code samples

ModalForm

Using ModalForm to represent "yes" / "no" button clicks as bool in closure

sendMessage($choice ? "Thank you" : "We will try to become better"); } )); ">
$player->sendForm(new ModalForm("A small question", "Is our server cool?",
	//result of pressing the "yes" / "no" button is written to a variable $choice
	function(Player $player, bool $choice) : void{
		$player->sendMessage($choice ? "Thank you" : "We will try to become better");
	}
));

modal1

Short version of ModalForm to confirm any action

sendMessage("*teleporting*"); } )); ">
$player->sendForm(ModalForm::confirm("Teleport request", "Do you want to accept it?",
	//called only when the player selects the "yes" button
	function(Player $player) : void{
		$player->sendMessage("*teleporting*");
	}
));

modal2

MenuForm

Using MenuForm to display buttons with icons from URL and path

sendMessage("You selected: " . $selected->text); $player->sendMessage("Index of button: " . $selected->getValue()); })); ">
$player->sendForm(new MenuForm("Select server", "Choose server", [
	//buttons without icon
	new Button("SkyWars #1"),
	new Button("SkyWars #2"),
	//URL and path are supported for image
	new Button("SkyWars #3", Image::url("https://static.wikia.nocookie.net/minecraft_gamepedia/images/f/f0/Melon_JE2_BE2.png")),
	new Button("SkyWars #4", Image::path("textures/items/apple.png")),
], function(Player $player, Button $selected) : void{
	$player->sendMessage("You selected: " . $selected->text);
	$player->sendMessage("Index of button: " . $selected->getValue());
}));

menu1

Creating MenuForm from array of strings (i.e. from string[]) with modern syntax of matching button clicks

match ($selected->getValue()) { 0 => $player->sendMessage("message #1"), //opt1 1 => $player->sendMessage("message #2"), //opt2 2 => $player->sendMessage("message #3"), //opt3 default => $player->sendMessage("You selected: " . $selected->text), })); ">
//MenuForm::withOptions is useful when you have a string[]
//syntax TIP: fn() added since PHP 7.4, match since PHP 8.0
$player->sendForm(MenuForm::withOptions("Select option", "List of options:", [
	"opt1", "opt2", "opt3",
	"default branch #1",
	"default branch #2",
], fn(Player $player, Button $selected) => match ($selected->getValue()) {
	0 => $player->sendMessage("message #1"), //opt1
	1 => $player->sendMessage("message #2"), //opt2
	2 => $player->sendMessage("message #3"), //opt3
	default => $player->sendMessage("You selected: " . $selected->text),
}));

menu2

Appending MenuForm with new options to handle different permissions

getName(), [ "view statistics", //accessible for all ], fn(Player $player, Button $selected) => match ($selected->getValue()) { 0 => $player->sendMessage("*statistics*"), 1 => $player->kick("kick message"), 2 => $player->sendMessage("*logs*"), default => throw new \AssertionError("unreachable code"), //shut phpstan }); $isOp = $player->hasPermission(DefaultPermissions::ROOT_OPERATOR); //since PM 4.0 if($isOp){ //accessible for ops $form->appendOptions("kick player", "view logs"); } $player->sendForm($form); ">
//appending form data if Player has enough permissions
$form = MenuForm::withOptions("Player info", "Username: " . $player->getName(), [
	"view statistics", //accessible for all
], fn(Player $player, Button $selected) => match ($selected->getValue()) {
	0 => $player->sendMessage("*statistics*"),
	1 => $player->kick("kick message"),
	2 => $player->sendMessage("*logs*"),
	default => throw new \AssertionError("unreachable code"), //shut phpstan
});

$isOp = $player->hasPermission(DefaultPermissions::ROOT_OPERATOR); //since PM 4.0
if($isOp){ //accessible for ops
	$form->appendOptions("kick player", "view logs");
}
$player->sendForm($form);

menu3

CustomForm

Using CustomForm with strict-typed API

() does not work with label new Slider("Select count", 0.0, 100.0, 1.0, 50.0), new StepSlider("Select product", ["beer", "cheese", "cola"]), new Toggle("Creative", $player->isCreative()), ], function(Player $player, CustomFormResponse $response) : void{ $dropdown = $response->getDropdown(); $player->sendMessage("You selected: " . $dropdown->getSelectedOption()); $input = $response->getInput(); $player->sendMessage("Your name is " . $input->getValue()); $slider = $response->getSlider(); $player->sendMessage("Count: " . $slider->getValue()); $stepSlider = $response->getStepSlider(); $player->sendMessage("You selected: " . $stepSlider->getSelectedOption()); $toggle = $response->getToggle(); $player->setGamemode($toggle->getValue() ? GameMode::CREATIVE() : GameMode::SURVIVAL()); })); ">
$player->sendForm(new CustomForm("Enter data", [
	new Dropdown("Select product", ["beer", "cheese", "cola"]),
	new Input("Enter your name", "Bob"),
	new Label("I am label!"), //Note: get() does not work with label
	new Slider("Select count", 0.0, 100.0, 1.0, 50.0),
	new StepSlider("Select product", ["beer", "cheese", "cola"]),
	new Toggle("Creative", $player->isCreative()),
], function(Player $player, CustomFormResponse $response) : void{
	$dropdown = $response->getDropdown();
	$player->sendMessage("You selected: " . $dropdown->getSelectedOption());

	$input = $response->getInput();
	$player->sendMessage("Your name is " . $input->getValue());

	$slider = $response->getSlider();
	$player->sendMessage("Count: " . $slider->getValue());

	$stepSlider = $response->getStepSlider();
	$player->sendMessage("You selected: " . $stepSlider->getSelectedOption());

	$toggle = $response->getToggle();
	$player->setGamemode($toggle->getValue() ? GameMode::CREATIVE() : GameMode::SURVIVAL());
}));

Using CustomForm with less strict-typed API

() does not work with label new Slider("Select count", 0.0, 100.0, 1.0, 50.0), new StepSlider("Select product", ["beer", "cheese", "cola"]), new Toggle("Creative", $player->isCreative()), ], function(Player $player, CustomFormResponse $response) : void{ /** @var bool $enableCreative */ //type-hint for phpstan [$product1, $username, $count, $product2, $enableCreative] = $response->getValues(); $player->sendMessage("You selected: $product1"); $player->sendMessage("Your name is $username"); $player->sendMessage("Count: $count"); $player->sendMessage("You selected: $product2"); $player->setGamemode($enableCreative ? GameMode::CREATIVE() : GameMode::SURVIVAL()); })); ">
$player->sendForm(new CustomForm("Enter data", [
	new Dropdown("Select product", ["beer", "cheese", "cola"]),
	new Input("Enter your name", "Bob"),
	new Label("I am label!"), //Note: get() does not work with label
	new Slider("Select count", 0.0, 100.0, 1.0, 50.0),
	new StepSlider("Select product", ["beer", "cheese", "cola"]),
	new Toggle("Creative", $player->isCreative()),
], function(Player $player, CustomFormResponse $response) : void{
	/** @var bool $enableCreative */ //type-hint for phpstan
	[$product1, $username, $count, $product2, $enableCreative] = $response->getValues();

	$player->sendMessage("You selected: $product1");
	$player->sendMessage("Your name is $username");
	$player->sendMessage("Count: $count");
	$player->sendMessage("You selected: $product2");
	$player->setGamemode($enableCreative ? GameMode::CREATIVE() : GameMode::SURVIVAL());
}));

custom1 custom2

Comments
Owner
Frago9876543210
Frago9876543210
Judge0 API integration for running/judging code with different languages

Laravel Judge0 Judge0 API integration for running/judging code with different languages use Mouadbnl\Judge0\Models\Submission; $submission = Submissi

Mouad Benali 10 Dec 6, 2022
Honeypot type for Symfony forms

EoHoneypotBundle Honeypot for Symfony2 forms. What is Honey pot? A honey pot trap involves creating a form with an extra field that is hidden to human

Eymen Gunay 33 Dec 19, 2022
💛 Modern API development in Laravel. ✍️ Developed by Gentrit Abazi.

Introduction Larapi is a package thats offers you to do modern API development in Laravel with support for new versions of Laravel. Larapi comes inclu

one2tek 93 Oct 28, 2022
PHP library for Qvapay API integration.

Php library for Qvapay API This PHP library facilitates the integration of the Qvapay API. Sign up on QvaPay Create your account to process payments t

Omar Villafuerte 9 Aug 20, 2022
PHP 8.1 like legacy enum (Experimental Alpha Version)

flux-legacy-enum PHP 8.1 like legacy enum Experimental Alpha Version Installation COPY --from=docker-registry.fluxpublisher.ch/flux-enum/legacy:latest

fluxlabs 1 Dec 12, 2022
PHP library/SDK for Crypto APIs 2.0 using Guzzle version 7

cryptoapis/sdk-guzzle7 Crypto APIs 2.0 is a complex and innovative infrastructure layer that radically simplifies the development of any Blockchain an

Crypto APIs 3 Oct 21, 2022
Airbrake.io & Errbit integration for Symfony 3/4/5. This bundle plugs the Airbrake API client into Symfony project

AmiAirbrakeBundle Airbrake.io & Errbit integration for Symfony 3/4/5. This bundle plugs the Airbrake API client into Symfony project. Prerequisites Th

Anton Minin 8 May 6, 2022
Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and / or RESTful API

Luracast Restler ![Gitter](https://badges.gitter.im/Join Chat.svg) Version 3.0 Release Candidate 5 Restler is a simple and effective multi-format Web

Luracast 1.4k Dec 14, 2022
A RESTful and extendable Backend as a Service that provides instant backend to develop sites and apps faster, with dead-simple integration for JavaScript, iOS, Android and more.

Welcome to hook ![Gitter](https://badges.gitter.im/Join Chat.svg) hook is a RESTful, extendable Backend as a Service that provides instant backend to

doubleleft 762 Dec 30, 2022
Pocketmine plugin API [4.0.0]

About /!\ Plugin in development [FR] Plugin de Mineral Contest [ENG] Mineral Contest Plugin Credit [FR] N'hésitez pas à donner votre avis sur le plugi

Achedon12 1 Jan 7, 2022
WordPress integration for globalis/chargebee-php-sdk

chargebee-php-sdk-wp Overview WordPress integration for globalis/chargebee-php-sdk Features Convert PSR-14 events into WordPress hooks Add query-monit

GLOBALIS media systems 7 Feb 17, 2022
This package makes it easy for developers to access WhatsApp Cloud API service in their PHP code.

The first PHP API to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

NETFLIE 135 Dec 29, 2022
Provides a Middleware to integration Tideways into Symfony Messenger Processing

Tideways Middleware for Symfony Messenger This package is currently under development and might be moved into the Tideways PHP Extension or stay indep

Tideways 6 Jul 5, 2022
Integration with your Symfony app & Vite

ViteBundle : Symfony integration with Vite This bundle helping you render all of the dynamic script and link tags needed. Essentially, he provide two

Hugues Tavernier 84 Dec 21, 2022
Fully unit tested Facebook SDK v5 integration for Laravel & Lumen

Laravel Facebook SDK A fully unit-tested package for easily integrating the Facebook SDK v5 into Laravel and Lumen 5.0, 5.1, 5.2, & 5.3. This is packa

Sammy Kaye Powers 697 Nov 6, 2022
Doctrine-like fixtures integration for Shopware 6.

Shopware 6 Fixtures Did you ever want to create and load Doctrine-like fixtures in your Shopware 6 plugin? Look no further! This plugin provides an ul

Familiy Office 0 Oct 29, 2021
Paynow SDK Laravel integration

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Alfred Tanaka Kudiwahove 2 Sep 20, 2021
This API provides functionality for creating and maintaining users to control a simple To-Do-List application. The following shows the API structure for users and tasks resources.

PHP API TO-DO-LIST v.2.0 This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science cours

Edson M. de Souza 6 Oct 13, 2022
A bundle providing routes and glue code between Symfony and a WOPI connector.

WOPI Bundle A Symfony bundle to facilitate the implementation of the WOPI endpoints and protocol. Description The Web Application Open Platform Interf

Champs-Libres 5 Aug 20, 2022