Code Monkey home page Code Monkey logo

vertx-lang-jphp's Introduction

Build Status maven-central vertx-lang-jphp Sonatype Nexus (Snapshots) license

vertx-lang-jphp

Vert.x JPHP support

phpdoc

怎么用 / How to use?

Maven配置 / Maven pom.xml:

<dependency>
  <groupId>tk.okou</groupId>
  <artifactId>vertx-lang-jphp</artifactId>
  <version>4.0.0-milestone1</version>
</dependency>

Gradle配置 / Gradle build.gradle file:

dependencies {
  compile 'tk.okou:vertx-lang-jphp:4.0.0-milestone1'
}

Hello from Vert.x!

$httpServer = $vertx->createHttpServer();
$httpServer->requestHandler(function ($res) {
    $res->response()->end("Hello from Vert.x!");
});
$httpServer->listen(8998);

创建Vertx 实例 / Create a Vert.x instance

如果你需要创建Vertx实例,可以按下面的代码创建:

use io\vertx\jphp\core\Vertx;

//create a vertx instance
$vertx = Vertx::vertx();

如果你是通过java来deploy一个php模块,那么你通常不需要自己创建,因为有一个全局的$vertx对象可以直接使用

Verticle

php脚本本身就是一个verticle,但如果你需要像java一样指定一个方法,那么你可以按下面方法:

function vertxStart(){
    //Called when verticle is deployed
}

function vertxStartAsync($future){
    //Called when verticle is deployed
}

function vertxStop($future){
    //Called when verticle is undeployed
}

function vertxStopAsync($future){
    //Called when verticle is undeployed
}

当Vert.x 部署这个Verticle脚本时,如果上下文环境中有vertxStart方法,会优先调用此方法,否则尝试调用异步的vertxStartAsync方法。vertxStartAsync方法接收一个io\vertx\jphp\core\Future类型的参数,在Verticle部署完成后,需要调用complete方法来显式的告诉Vert.x完成。

同理,Vert.x在移除一个Verticle脚本时,优先判断vertxStop并执行,如果没有vertxStop方法,会尝试调用异步的vertxStartAsync方法。vertxStartAsync方法也有一个io\vertx\jphp\core\Future类型的参数。

部署Verticle / Verticle Deployment

你可以使用php:前缀或者.php后缀来部署一个php verticle

    $vertx->deployVerticle("php:test");
    // 或者
    $vertx->deployVerticle("php:test.php");
    // 或者
    $vertx->deployVerticle("test.php");

或者使用java

    import io.vertx.core.Vertx;
    Vertx vertx = Vertx.vertx();
    vertx.deployVerticle("php:test");
    // 或者
    vertx.deployVerticle("php:test.php");
    // 或者
    vertx.deployVerticle("test.php");

DataObject

你可以直接创建需要的DataObject对象,比如HttpServerOption:

use io\vertx\jphp\core\http\HttpServerOptions;

$httpServerOptions = new HttpServerOptions();
$httpServerOptions->setPort(8080);
$httpServerOptions->setHost("localhost");

当然你也可以直接使用数组,比如Hello Vert.x!例子中

$httpServerOptions = [
    "port"  =>  8998,
    "host"  =>  "localhost",
];

$httpServer = $vertx->createHttpServer($httpServerOptions);
$httpServer->requestHandler(function ($res) {
    $res->response()->end("Hello from Vert.x!");
});
$httpServer->listen();

Note 注意,DataObject目前只支持类和接口,所以java的api中参数为接口的,php中不支持数组写法,只能创建实现类的对象

;TODO

  • 使用vertx-codegen自动生成JPHP的Wrapper类以及php的api文件
  • JPHPVerticleFactory和VerticleFactory
  • VertxExtension 读取jphp-vertx-extension.properties文件并注册wrapper类
  • 使用vertx-docgen自动生成对应的asciidoc文档
  • 测试

phpdoc

生成phpdoc需要phpDocumentor2,使用的皮肤需要开启xsl功能并下载graphviz

  • 下载phpDocumentor2改名为phpdoc放到vertx-lang-jphp目录下
  • 下载graphviz 并配置环境变量
  • 修改php.ini,开启xsl扩展(如果未开启)

vertx-lang-jphp's People

Contributors

dependabot[bot] avatar okou19900722 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

yinhe

vertx-lang-jphp's Issues

增加service proxy支持

增加service proxy支持
接口文件使用java写,需要依赖java的vertx-service-proxy模块,然后编写codegen模版,生成php文件

重构codegen

  • 1、新版本将不再使用mvel,而是使用java编写。
  • 2、将接口与抽象类暴露出来,要吧在php中继承

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.