### php.java.bridge.http

# Class Context

- `java.lang.Object`

- `php.java.bridge.http.Context`

Implemented Interfaces:
  Invocable

Known Direct Subclasses:
  Context

`public class Context`
`extends java.lang.Object`
`implements Invocable`

Emulates a JSR223 script context when the JSR223 classes are not available. The method call(kont) returns false, so that it can be used to check if a script was called from java:
`function toString() {return "hello java, I am a php script, but in your eyes I am an ordinary java object...";}
java_context()->call(java_closure()) || die("This script must be called from java!");`

Author:
  jostb

See Also:
  `IPhpScriptContext`, `ScriptContext`, `PhpSimpleHttpScriptContext`, `PhpScriptContext`

## Field Summary

`static int`

`ENGINE_SCOPE`
  The engine scope

`static int`

`GLOBAL_SCOPE`
  The global scope

## Method Summary

`boolean`

`call(PhpProcedureProxy kont)`

`java.lang.Object`

`getAttribute(java.lang.String name)`
  Retrieves the value for getAttribute(String, int) for the lowest scope in which it returns a non-null value.

`java.lang.Object`

`getAttribute(java.lang.String name, int scope)`
  Retrieves the value associated with specified name in the specified level of scope.

`int`

`getAttributesScope(java.lang.String name)`
  Retrieves the lowest value of scopes for which the attribute is defined.

`java.util.Map`

`getMap(int scope)`
  Retrieves the Map instance associated with the specified level of scope.

`java.io.Writer`

`getWriter()`
  Retrieves an instance of java.io.Writer which can be used by scripts to display their output.

`java.lang.Object`

`removeAttribute(java.lang.String name, int scope)`
  Removes the specified attribute form the specified level of scope.

`void`

`setAttribute(java.lang.String name, java.lang.Object value, int scope)`
  Sets an attribute specified by the name in specified level of scope.

`void`

`setMap(java.util.Map map, int scope)`
  Associates the specified Map with specified level of scope.

### Methods inherited from class java.lang.Object

`equals`, `getClass`, `hashCode`, `notify`, `notifyAll`, `toString`, `wait`, `wait`, `wait`

## Field Details

### ENGINE_SCOPE

    public static final int ENGINE_SCOPE

> The engine scope

> Field Value:
>   100

### GLOBAL_SCOPE

    public static final int GLOBAL_SCOPE

> The global scope

> Field Value:
>   200

## Method Details

### call

    public boolean call(PhpProcedureProxy kont)

> Specified by:
>   call in interface Invocable

### getAttribute

    public java.lang.Object getAttribute(java.lang.String name)
                throws java.lang.IllegalArgumentException

> Retrieves the value for getAttribute(String, int) for the lowest scope in which it returns a non-null value.

> Parameters:
>   `name` - the name of the attribute

> Returns:
>   the value of the attribute

### getAttribute

    public java.lang.Object getAttribute(java.lang.String name,
                                         int scope)
                throws java.lang.IllegalArgumentException

> Retrieves the value associated with specified name in the specified level of scope. Returns null if no value is associated with specified key in specified level of scope.

> Parameters:
>   `name` - the name of the attribute
>   `scope` - the level of scope

> Returns:
>   the value value associated with the specified name in specified level of scope

### getAttributesScope

    public int getAttributesScope(java.lang.String name)

> Retrieves the lowest value of scopes for which the attribute is defined. If there is no associate scope with the given attribute (-1) is returned.

> Parameters:
>   `name` - the name of attribute

> Returns:
>   the value of level of scope

### getMap

    public java.util.Map getMap(int scope)

> Retrieves the Map instance associated with the specified level of scope.

> Parameters:
>   `scope` - the level of the scope

> Returns:
>   the Map associated with the specified level of scope

### getWriter

    public java.io.Writer getWriter()
                throws java.io.IOException

> Retrieves an instance of java.io.Writer which can be used by scripts to display their output.

> Returns:
>   an instance of java.io.Writer

### removeAttribute

    public java.lang.Object removeAttribute(java.lang.String name,
                                            int scope)
                throws java.lang.IllegalArgumentException

> Removes the specified attribute form the specified level of scope.

> Parameters:
>   `name` - the name of the attribute
>   `scope` - the level of scope

> Returns:
>   value which is removed

> Throws:
>   `java.lang.IllegalArgumentException` -

### setAttribute

    public void setAttribute(java.lang.String name,
                             java.lang.Object value,
                             int scope)
                throws java.lang.IllegalArgumentException

> Sets an attribute specified by the name in specified level of scope.

> Parameters:
>   `name` - the name of the attribute
>   `value` - the value of the attribute
>   `scope` - the level of the scope

### setMap

    public void setMap(java.util.Map map,
                       int scope)
                throws java.lang.IllegalArgumentException

> Associates the specified Map with specified level of scope.

> Parameters:
>   `map` - the Map to be associated with specified level of scope
>   `scope` - the level of scope