# \nre\agentsToplevelAgent

The ToplevelAgent assumes the task of a FrontController. There is only one per request.

## Summary

Methods
Properties
Constants
load()
factory()
run()
render()
getIntermediateAgent()
$controller
INLINEERROR_AGENT
STAGE_LOAD
STAGE_RUN
__construct()
actionConstruct()
loadController()
log()
addSubAgent()
_addSubAgent()
$log
$subAgents
N/A
getAgentType()
getClassName()
newSubAgent()
renderSubAgent()
errorInline()
newInlineError()
newInlineErrorService()
loadIntermediateAgent()
_loadIntermediateAgent()
_run()
runIntermediateAgent()
error()
$request
$response
$layout
$intermediateAgent
N/A

File
  agents/ToplevelAgent.inc
Package
  Default
Class hierarchy
  \nre\core\Agent
  \nre\agents\ToplevelAgent

## Tags

author | coderkun olli@coderkun.de

## Constants

### INLINEERROR_AGENT

    INLINEERROR_AGENT

Name of BottomlevelAgent for showing inline errors

#

Inherited from
  \nre\core\Agent

## Tags

None found

### STAGE_LOAD

    STAGE_LOAD

Stage: Load

#

## Tags

None found

### STAGE_RUN

    STAGE_RUN

Stage: Run

#

## Tags

None found

## Properties

### $controller

    $controller : \nre\core\Controller

Controller of this Agent

#### Type

\nre\core\Controller

#

Inherited from
  \nre\core\Agent

## Tags

None found

### $log

    $log : \nre\core\Logger

Log-system

#### Type

\nre\core\Logger

#

Inherited from
  \nre\core\Agent

## Tags

None found

### $subAgents

    $subAgents : array

SubAgents

#### Type

array

#

Inherited from
  \nre\core\Agent

## Tags

None found

### $request

    $request : \nre\core\Request

Current request

#### Type

\nre\core\Request

#

## Tags

None found

### $response

    $response : \nre\core\Response

Current response

#### Type

\nre\core\Response

#

## Tags

None found

### $layout

    $layout : \nre\core\Layout

Layout instace

#### Type

\nre\core\Layout

#

## Tags

None found

### $intermediateAgent

    $intermediateAgent : \nre\agents\IntermediateAgent

IntermediateAgent instance

#### Type

\nre\agents\IntermediateAgent

#

## Tags

None found

## Methods

### load()

    load(string  $agentName)

Load the class of an Agent.

#### Parameters

string | $agentName | Name of the Agent to load

#### Throws

\nre\exceptions\AgentNotFoundException
\nre\exceptions\AgentNotValidException

#

static

Inherited from
  \nre\core\Agent

## Tags

static |

### factory()

    factory(string  $agentName, \nre\core\Request  $request, \nre\core\Response  $response, \nre\core\Logger  $log = null)

Instantiate an Agent (Factory Pattern).

#### Parameters

string | $agentName | Name of the Agent to instantiate
\nre\core\Request | $request | Current request
\nre\core\Response | $response |
\nre\core\Logger | $log | Log-system

#### Throws

\nre\exceptions\DatamodelException
\nre\exceptions\DriverNotValidException
\nre\exceptions\DriverNotFoundException
\nre\exceptions\ViewNotFoundException
\nre\exceptions\ModelNotValidException
\nre\exceptions\ModelNotFoundException
\nre\exceptions\ControllerNotValidException
\nre\exceptions\ControllerNotFoundException

#

static

Inherited from
  \nre\core\Agent

## Tags

static |

### run()

    run(\nre\core\Request  $request, \nre\core\Response  $response) : \Exception

Run the Controller of this Agent and its SubAgents.

#### Parameters

\nre\core\Request | $request | Current request
\nre\core\Response | $response | Current response

#### Throws

\nre\exceptions\ServiceUnavailableException

#### Returns

\Exception —

Last occurred exception of SubAgents

#

## Tags

None found

### render()

    render(array  $data = array()) : string

Generate output of the Controller of this Agent and its SubAgents.

#### Parameters

array | $data | View data

#### Returns

string —

Generated output

#

## Tags

None found

### getIntermediateAgent()

    getIntermediateAgent() : \nre\agents\IntermediateAgent

Return the IntermediateAgent.

#### Returns

\nre\agents\IntermediateAgent —

IntermediateAgent

#

## Tags

None found

### __construct()

    __construct(\nre\core\Request  $request, \nre\core\Response  $response, \nre\core\Logger  $log = null)

Construct a ToplevelAgent.

#### Parameters

\nre\core\Request | $request | Current request
\nre\core\Response | $response | Current response
\nre\core\Logger | $log | Log-system

#### Throws

\nre\exceptions\ServiceUnavailableException
\nre\exceptions\DatamodelException
\nre\exceptions\DriverNotValidException
\nre\exceptions\DriverNotFoundException
\nre\exceptions\ViewNotFoundException
\nre\exceptions\ModelNotValidException
\nre\exceptions\ModelNotFoundException
\nre\exceptions\ControllerNotValidException
\nre\exceptions\ControllerNotFoundException

#

## Tags

None found

### actionConstruct()

    actionConstruct()

Construct SubAgents (per Action).

#

Inherited from
  \nre\core\Agent

## Tags

None found

### loadController()

    loadController()

Load the Controller of this Agent.

#### Throws

\nre\exceptions\DatamodelException
\nre\exceptions\DriverNotValidException
\nre\exceptions\DriverNotFoundException
\nre\exceptions\ViewNotFoundException
\nre\exceptions\ModelNotValidException
\nre\exceptions\ModelNotFoundException
\nre\exceptions\ControllerNotValidException
\nre\exceptions\ControllerNotFoundException

#

Inherited from
  \nre\core\Agent

## Tags

None found

### log()

    log(\Exception  $exception, integer  $logMode)

Log an error.

#### Parameters

\Exception | $exception | Occurred exception
integer | $logMode | Log mode

#

Inherited from
  \nre\core\Agent

## Tags

None found

### addSubAgent()

    addSubAgent(string  $agentName)

Load a SubAgent and add it.

#### Parameters

string | $agentName | Name of the Agent to load

#### Throws

\nre\exceptions\ServiceUnavailableException
\nre\exceptions\FatalDatamodelException
\nre\exceptions\AgentNotFoundException
\nre\exceptions\AgentNotValidException

#

## Tags

None found

### _addSubAgent()

    _addSubAgent(string  $agentName)

Load a SubAgent and add it.

#### Parameters

string | $agentName | Name of the Agent to load

#### Throws

\nre\exceptions\ServiceUnavailableException
\nre\exceptions\DatamodelException
\nre\exceptions\AgentNotFoundException
\nre\exceptions\AgentNotValidException

#

Inherited from
  \nre\core\Agent

## Tags

None found

### getAgentType()

    getAgentType() : string

Determine the type of an Agent.

#### Returns

string —

Agent type

#

static

Inherited from
  \nre\core\Agent

## Tags

static |

### getClassName()

    getClassName(string  $agentName, string  $agentType) : string

Determine the classname for the given Agent name.

#### Parameters

string | $agentName | Agent name to get classname of
string | $agentType | Agent type of given Agent name

#### Returns

string —

Classname for the Agent name

#

static

Inherited from
  \nre\core\Agent

## Tags

static |

### newSubAgent()

    newSubAgent(string  $agentName) : array

Create a new SubAgent.

#### Parameters

string | $agentName | Agent name

#### Throws

\nre\exceptions\DatamodelException

#### Returns

array —

SubAgent

#

Inherited from
  \nre\core\Agent

## Tags

None found

### renderSubAgent()

    renderSubAgent(array  $subAgent) : string

Render a SubAgent.

#### Parameters

array | $subAgent | SubAgent to render

#### Returns

string —

Generated output

#

Inherited from
  \nre\core\Agent

## Tags

None found

### errorInline()

    errorInline(array  $subAgent, \nre\core\Request  $request, \nre\core\Excepiton  $exception) : array

Handle the exception of a SubAgent.

#### Parameters

array | $subAgent | Original (Sub-) Agent
\nre\core\Request | $request | Current request
\nre\core\Excepiton | $exception | Occurred exception

#### Returns

array —

InlineError-SubAgent

#

Inherited from
  \nre\core\Agent

## Tags

None found

### newInlineError()

    newInlineError(string  $label, \Exception  $exception)

Create a new InlineError.

#### Parameters

string | $label | Name of the original Agent
\Exception | $exception | Occurred exception

#

Inherited from
  \nre\core\Agent

## Tags

None found

### newInlineErrorService()

    newInlineErrorService()

Handle a hardcore error that could not be handled by the system.

#

Inherited from
  \nre\core\Agent

## Tags

None found

### loadIntermediateAgent()

    loadIntermediateAgent()

Load IntermediateAgent defined by the current request.

#### Throws

\nre\exceptions\ServiceUnavailableException

#

## Tags

None found

### _loadIntermediateAgent()

    _loadIntermediateAgent()

Load IntermediateAgent defined by the current request.

#### Throws

\nre\exceptions\ServiceUnavailableException

#

## Tags

None found

### _run()

    _run(\nre\core\Request  $request, \nre\core\Response  $response) : \Exception

Run the Controller of this Agent and its SubAgents.

#### Parameters

\nre\core\Request | $request | Current request
\nre\core\Response | $response | Current response

#### Throws

\nre\exceptions\AccessDeniedException
\nre\exceptions\IdNotFoundException
\nre\exceptions\ServiceUnavailableException
\nre\exceptions\DatamodelException

#### Returns

\Exception —

Last occurred exception of SubAgents

#

## Tags

None found

### runIntermediateAgent()

    runIntermediateAgent()

Run IntermediateAgent.

#### Throws

\nre\exceptions\AccessDeniedException
\nre\exceptions\ParamsNotValidException
\nre\exceptions\IdNotFoundException
\nre\exceptions\ServiceUnavailableException
\nre\exceptions\DatamodelException

#

## Tags

None found

### error()

    error(\Exception  $exception, integer  $httpStatusCode, string  $stage = self::STAGE_LOAD)

Handle an error that occurred during loading/cnostructing/running of the IntermediateAgent.

#### Parameters

\Exception | $exception | Occurred exception
integer | $httpStatusCode | HTTP-statuscode
string | $stage | Stage of execution

#### Throws

\nre\exceptions\ServiceUnavailableException

#

## Tags

None found

### ToplevelAgent.inc