Skip to content

Getting started

Dmitriy Zayceff edited this page Apr 27, 2015 · 33 revisions

Using with Gradle (Hello World)

This is a simple way to try JPHP.

Before we start, you need to download the Gradle distributive and add the Gradle bin path to your PATH variable.

Create the next directories and files:

build.gradle
src/
   JPHP-INF/
      .bootstrap.php
      launcher.conf

Change the gradle build file - build.gradle:

apply plugin: 'application'

repositories {
    jcenter()
    mavenCentral()
}

sourceSets {
    main.resources.srcDirs = ['src']
}

dependencies {
    compile 'org.develnext:jphp-core:0.6+' // include jphp with runtime and compiler

    compile 'org.develnext:jphp-zend-ext:0.6+' // legacy zend classes and functions
    compile 'org.develnext:jphp-json-ext:0.6+' // json support
    compile 'org.develnext:jphp-xml-ext:0.6+' // xml library
    compile 'org.develnext:jphp-gdx-ext:0.6+' // libgdx wrapper
    compile 'org.develnext:jphp-jsoup-ext:0.6+' // library for site parsing in jQuery style
}

mainClassName = 'php.runtime.launcher.Launcher'

In the JPHP-INF/.bootstrap.php write any php code:

<?php echo "Hello World";

Use the command line to run your app:

gradle run

What about class loading?

By default Launcher uses a special class loader to load your classes from the src directory, you still can use namespaces, for example - my\pack\AnyClass will be loaded from the src/my/pack/AnyClass.php file automatically. You still can register your class loader via spl_register_autoload in src/JPHP-INF/.bootstrap.php and disable the default class autoloader via the env.classLoader option in launcher.conf:

env.classLoader = 

Clone this wiki locally