Edit Extension class


Extension class example:

package org.jphp.mysuperext;

import php.runtime.env.CompileScope;
import php.runtime.ext.support.Extension;

public class MyExtension extends Extension {
    /**
     * Extension name
     * @since 0.3
     */
    @Override
    public String getName() {
        return "MyExtension";
    }

    /**
     * Extension version
     * @since 0.3
     */
    @Override
    public String getVersion() {
        return "1.0";
    }

    /**
     * Return extension status
     *
     * enum Status {
     *      EXPERIMENTAL,
     *      BETA,
     *      STABLE,
     *      LEGACY,
     *      ZEND_LEGACY,
     *      DEPRECATED
     * }
     *
     * @since 0.6
     */
    @Override
    public Status getStatus() {
        return Status.EXPERIMENTAL;
    }

    /**
     * Register extension classes
     */
    @Override
    public void onRegister(CompileScope scope) {
        /**
         * Register:
         *    class php.runtime.lang.BaseObject 
         *      or
         *    interface php.runtime.lang.IObject 
         */
        this.registerClass(scope, SomeClass.class);

        /**
         * Register php.runtime.lang.BaseWrapper class
         */
        this.registerWrapperClass(scope, OriginalJavaClass.class, YourWrapperClass.class);

        /**
         * 
         */
        this.registerMemoryOperation(MyMemoryOperation.class);
        
        /**
         * 
         */
        this.registerJavaException(scope, OriginalJavaExceptionClass.class, YourExceptionWrapper.class);

        /**
         * Register a global defines
         * container is instance of php.runtime.ext.support.compile.ConstantsContainer
         */
        this.registerConstants(container);

        /**
         * Register a global functions
         * container is instance of php.runtime.ext.support.compile.FunctionsContainer
         */
        this.registerFunctions(container);
    }
}

More examples: