php gui库,php-gui:无扩展PHP图形用户界面库

48d95d372c76840bd4d8056093d057df.png

Extensionless PHP Graphic User Interface library

4ed027dd08c29c7c9b985caf4ba00d8a.gif

68747470733a2f2f7472617669732d63692e6f72672f6761627269656c72636f75746f2f7068702d6775692e7376673f6272616e63683d6d617374657268747470733a2f2f706f7365722e707567782e6f72672f6761627269656c72636f75746f2f7068702d6775692f762f737461626c6568747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c617468747470733a2f2f696d672e736869656c64732e696f2f62616467652f7061636b61676973742d696e7374616c6c2d627269676874677265656e2e737667

Table of Contents

Why

PHP can be more than a "Web Language", it's a fast language, with a cross platform interpreter and a good CLI. GUI is a natural step for completing this ecosystem.

For many years, GUI projects are being developed for PHP, like PHP-GTK, PHP-QT, wxPHP and so many others, but none of them became popular.

This project aims to solve the most common problems of existing "GUI Projects":

The need for installing an extension

Cross platform

No external dependencies

Easy to install (composer require php-gui) / Easy to use ($button = new Button)

Requirements

The following PHP versions are supported:

PHP 5.6

PHP 7

HHVM

And OS:

Linux x64

Windows x64

Mac OSX (tested on 10.10.x and 10.11.x)

Usage

Download the library using composer:

Stable version

$ composer require gabrielrcouto/php-gui

Latest version (development)

$ composer require gabrielrcouto/php-gui:dev-master

Now, you can build a GUI application. Let's do a Hello World!

Create the file 'myapp.php':

require 'vendor/autoload.php';

use Gui\Application;

use Gui\Components\Button;

$application = new Application();

$application->on('start', function() use ($application) {

$button = (new Button())

->setLeft(40)

->setTop(100)

->setWidth(200)

->setValue('Look, I\'m a button!');

$button->on('click', function() use ($button) {

$button->setValue('Look, I\'m a clicked button!');

});

});

$application->run();

Now, run it:

php myapp.php

Simple?

👏 You don't need to compile anything, just download the library via composer and use it!

😄

Documentation

But, if you want to see some examples, just follow the instructions below.

# clone the repository

git clone https://github.com/gabrielrcouto/php-gui.git

cd php-gui

# install dependencies

composer install

# run examples

php examples/01-basic/example.php

php examples/02-animation/example.php

php examples/03-window/example.php

php examples/04-multiple-windows/example.php

php examples/05-canvas/example.php

php examples/06-ping/example.php

php examples/07-php-internals/example.php

php examples/08-alert/example.php

php examples/09-3d-perspective/example.php

How it works

To create a GUI without the need for an extension, PHP executes a binary with proc_open and communicates with it using Stdin/Stdout Pipes--it's a fast and cross platform solution.

PHP <=> Stdin/Stdout Pipes <=> Lazarus Application <=> GUI

The binary is created using Lazarus (Free Pascal). After much research, I found a large advantage by using Lazarus over other desktop languages (like C#, Java...):

c6311ddfe50d1d53af4f016e45235a97.png

It doesn't have any dependencies (except for Linux, which needs GTK), has a good component library, is compiled, open source and has a nice slogan (Write Once, Compile Anywhere).

The communication (IPC) between PHP and Lazarus is performed using a protocol based on JSON RPC. You can view the specification here.

Contributors Guide

Components names

To be an easy to use library, this project will use HTML friendly names for the components, as PHP developers are more familiar with it.

Examples:

On Lazarus, the property "caption" is for the text of a button. On php-gui, the property name is "value".

On Lazarus, "Edit" is the component for text input, on php-gui, it's "InputText".

Compiling Lazarus App

On your Local Machine

First, you need to install Lazarus.

For compiling the lazarus binary:

lazbuild phpgui.lpr

Using Docker

If you are generating the Linux binary, you can use Docker:

lazarus/linux-docker.sh

cd lazarus/

lazbuild phpgui.lpr

Test

First install the dependencies, and after you can run:

bin/phing

TO-DO

The "Issues" page from this repository is being used for TO-DO management, just search for the "to-do" tag.

Credits

License

68747470733a2f2f6170702e636f646573706f6e736f722e696f2f656d6265642f6276657a5839423963544a5469646d63423469696b4e66662f6761627269656c72636f75746f2f7068702d6775692e737667

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值