public function controller()
{
if (!isset($this->_controllerRef)) {
if (is_callable($this->_controller)) {
$controller = new Controller(['closure' => $this->_controller, 'tipsy' => $this->tipsy()]);
$this->_controllerRef = $controller;
} elseif (is_object($this->_controller)) {
$this->_controllerRef = $this->_controller;
$this->_controllerRef->tipsy($this->tipsy());
} elseif (is_string($this->_controller) && $this->tipsy()->controller($this->_controller)) {
$this->_controllerRef = $this->tipsy()->controller($this->_controller);
} elseif (is_string($this->_controller) && class_exists($this->_controller)) {
$this->_controllerRef = new $this->_controller(['tipsy' => $this->tipsy()]);
}
if ($this->_controllerRef) {
$this->_controllerRef->tipsy()->route($this);
}
}
if (!$this->_controllerRef) {
throw new Exception('No controller attached to route.');
}
return $this->_controllerRef;
}