Search in sources :

Example 1 with Extension

use of php.runtime.ext.support.Extension in project jphp by jphp-compiler.

the class CompileScope method registerExtension.

public void registerExtension(Extension extension) {
    long t = System.currentTimeMillis();
    if (extensions.containsKey(extension.getName()))
        return;
    // required
    for (String dep : extension.getRequiredExtensions()) {
        try {
            Extension el = (Extension) Class.forName(dep).newInstance();
            registerExtension(el);
        } catch (Exception e) {
            throw new CriticalException(e);
        }
    }
    // optional
    for (String dep : extension.getOptionalExtensions()) {
        try {
            Extension el = (Extension) Class.forName(dep).newInstance();
            registerExtension(el);
        } catch (ClassNotFoundException e) {
        // do nothing ...
        } catch (Exception e) {
            throw new CriticalException(e);
        }
    }
    // conflicts
    for (String dep : extension.getConflictExtensions()) {
        if (extensions.containsKey(dep))
            throw new ConflictException("'" + dep + "' extension conflicts with '" + extension.getClass().getName() + "'");
    }
    extension.onRegister(this);
    compileConstantMap.putAll(extension.getConstants());
    compileFunctionSpecMap.putAll(extension.getFunctions());
    for (Class<?> clazz : extension.getClasses().values()) {
        registerLazyClass(extension, clazz);
    }
    for (CompileFunctionSpec function : extension.getFunctions().values()) {
        functionMap.put(function.getLowerName(), new CompileFunctionEntity(extension, function));
    }
    extensions.put(extension.getName().toLowerCase(), extension);
    if (Startup.isTracing()) {
        Startup.traceWithTime("Register extension '" + extension.getName() + "'", t);
    }
}
Also used : Extension(php.runtime.ext.support.Extension) JavaExtension(php.runtime.ext.JavaExtension) CoreExtension(php.runtime.ext.CoreExtension) NetExtension(php.runtime.ext.NetExtension) CompileFunctionSpec(php.runtime.ext.support.compile.CompileFunctionSpec) ConflictException(php.runtime.exceptions.ConflictException) CriticalException(php.runtime.exceptions.CriticalException) CriticalException(php.runtime.exceptions.CriticalException) JavaException(php.runtime.ext.java.JavaException) ErrorException(php.runtime.lang.spl.ErrorException) ConflictException(php.runtime.exceptions.ConflictException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with Extension

use of php.runtime.ext.support.Extension in project jphp by jphp-compiler.

the class ReflectionFunctionAbstract method getExtension.

@Signature
public Memory getExtension(Environment env, Memory... args) {
    if (getClosureEntity() != null)
        return Memory.NULL;
    Extension extension = getEntity().getExtension();
    if (extension == null)
        return Memory.NULL;
    else {
        ReflectionExtension ext = new ReflectionExtension(env, env.fetchClass("ReflectionExtension"));
        ext.setExtension(extension);
        return new ObjectMemory(ext);
    }
}
Also used : Extension(php.runtime.ext.support.Extension) ObjectMemory(php.runtime.memory.ObjectMemory) Signature(php.runtime.annotation.Reflection.Signature)

Example 3 with Extension

use of php.runtime.ext.support.Extension in project jphp by jphp-compiler.

the class InfoFunctions method get_defined_constants.

public static Memory get_defined_constants(Environment env, boolean capitalize) {
    Set<String> exists = new HashSet<String>();
    ArrayMemory result = new ArrayMemory();
    for (String ext : env.scope.getExtensions()) {
        Extension extension = env.scope.getExtension(ext);
        ArrayMemory item = result;
        if (capitalize)
            item = (ArrayMemory) result.refOfIndex(ext).assign(new ArrayMemory());
        for (CompileConstant constant : extension.getConstants().values()) {
            item.put(constant.name, constant.value);
            exists.add(constant.name);
        }
    }
    ArrayMemory item = result;
    if (capitalize)
        item = (ArrayMemory) result.refOfIndex("user").assign(new ArrayMemory());
    for (ConstantEntity constant : env.scope.getConstants()) {
        if (!exists.contains(constant.getName()))
            item.put(constant.getName(), constant.getValue());
    }
    for (ConstantEntity constant : env.getConstants().values()) {
        if (!exists.contains(constant.getName()))
            item.put(constant.getName(), constant.getValue());
    }
    return result;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Extension(php.runtime.ext.support.Extension) CompileConstant(php.runtime.ext.support.compile.CompileConstant) ConstantEntity(php.runtime.reflection.ConstantEntity) HashSet(java.util.HashSet)

Aggregations

Extension (php.runtime.ext.support.Extension)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashSet (java.util.HashSet)1 Signature (php.runtime.annotation.Reflection.Signature)1 ConflictException (php.runtime.exceptions.ConflictException)1 CriticalException (php.runtime.exceptions.CriticalException)1 CoreExtension (php.runtime.ext.CoreExtension)1 JavaExtension (php.runtime.ext.JavaExtension)1 NetExtension (php.runtime.ext.NetExtension)1 JavaException (php.runtime.ext.java.JavaException)1 CompileConstant (php.runtime.ext.support.compile.CompileConstant)1 CompileFunctionSpec (php.runtime.ext.support.compile.CompileFunctionSpec)1 ErrorException (php.runtime.lang.spl.ErrorException)1 ArrayMemory (php.runtime.memory.ArrayMemory)1 ObjectMemory (php.runtime.memory.ObjectMemory)1 ConstantEntity (php.runtime.reflection.ConstantEntity)1