public function wrapResult($result, $wrappingRequired)
 {
     if ($result === null) {
         $actionResult = new ufront_web_result_EmptyResult(true);
         return tink_core__Future_Future_Impl_::sync(tink_core_Outcome::Success($actionResult));
     } else {
         $future = null;
         if (($wrappingRequired & 1 << ufront_web_result_ResultWrapRequired::$WRFuture->index) !== 0) {
             $future = $this->wrapInFuture($result);
         } else {
             $future = $result;
         }
         $surprise = null;
         if (($wrappingRequired & 1 << ufront_web_result_ResultWrapRequired::$WROutcome->index) !== 0) {
             $surprise = $this->wrapInOutcome($future);
         } else {
             $surprise = $future;
         }
         $finalResult = null;
         if (($wrappingRequired & 1 << ufront_web_result_ResultWrapRequired::$WRResultOrError->index) !== 0) {
             $finalResult = $this->wrapResultOrError($surprise);
         } else {
             $finalResult = $surprise;
         }
         return $finalResult;
     }
 }
 static function asSurpriseTypedError($err, $msg = null, $p = null)
 {
     if ($msg === null) {
         $msg = "Failure: " . Std::string($err);
     }
     return tink_core__Future_Future_Impl_::sync(tink_core_Outcome::Failure(ufront_web_HttpError::wrap($err, $msg, $p)));
 }
 public function deleteTemporaryFile()
 {
     try {
         @unlink($this->tmpFileName);
         return tink_core_Outcome::Success(tink_core_Noise::$Noise);
     } catch (Exception $__hx__e) {
         $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
         $e = $_ex_;
         return tink_core_Outcome::Failure(tink_core_TypedError::withData(null, "Error during TmpFileUpload.deleteTmpFile()", $e, _hx_anonymous(array("fileName" => "TmpFileUpload.hx", "lineNumber" => 165, "className" => "ufront.web.upload.TmpFileUpload", "methodName" => "deleteTemporaryFile"))));
     }
 }
 public function handleRequest($httpContext)
 {
     $doneTrigger = new tink_core_FutureTrigger();
     if (ufront_remoting_RemotingHandler_0($this, $doneTrigger, $httpContext)) {
         $r = $httpContext->response;
         $remotingResponse = null;
         $r->setOk();
         $path = null;
         $args = null;
         try {
             $this->initializeContext($httpContext->injector);
             $params = $httpContext->request->get_params();
             if (!$params->exists("__x")) {
                 throw new HException("Remoting call did not have parameter `__x` which describes which API call to make.  Aborting");
             }
             $remotingCall = null;
             $s = ufront_core__MultiValueMap_MultiValueMap_Impl_::get($params, "__x");
             $remotingCall = urldecode($s);
             $u = new haxe_Unserializer($remotingCall);
             $path = $u->unserialize();
             $args = $u->unserialize();
             $apiCallFinished = $this->executeApiCall($path, $args, $this->context, $httpContext->actionContext);
             $remotingResponse = tink_core__Future_Future_Impl_::map($apiCallFinished, array(new _hx_lambda(array(&$apiCallFinished, &$args, &$doneTrigger, &$httpContext, &$params, &$path, &$r, &$remotingCall, &$remotingResponse, &$u), "ufront_remoting_RemotingHandler_1"), 'execute'), null);
         } catch (Exception $__hx__e) {
             $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
             $e = $_ex_;
             $error = $e;
             $apiNotFoundMessages = new _hx_array(array("Invalid path", "No such object", "Can't access", "No such method"));
             if ($path !== null && $args !== null && Std::is($e, _hx_qtype("String")) && Lambda::exists($apiNotFoundMessages, array(new _hx_lambda(array(&$apiNotFoundMessages, &$args, &$doneTrigger, &$e, &$error, &$httpContext, &$path, &$r, &$remotingResponse), "ufront_remoting_RemotingHandler_2"), 'execute'))) {
                 $remotingResponse = tink_core__Future_Future_Impl_::sync("Unable to access " . _hx_string_or_null($path->join(".")) . " - API Not Found (" . _hx_string_or_null($error) . "). See " . Std::string($this->context->objects));
                 $r->setNotFound();
             } else {
                 $r->setInternalError();
                 $remotingResponse = tink_core__Future_Future_Impl_::sync($this->remotingError($e, $httpContext));
             }
         }
         $remotingResponse(array(new _hx_lambda(array(&$args, &$doneTrigger, &$e, &$httpContext, &$path, &$r, &$remotingResponse), "ufront_remoting_RemotingHandler_3"), 'execute'));
     } else {
         $result1 = tink_core_Outcome::Success(tink_core_Noise::$Noise);
         if ($doneTrigger->{"list"} === null) {
             false;
         } else {
             $list1 = $doneTrigger->{"list"};
             $doneTrigger->{"list"} = null;
             $doneTrigger->result = $result1;
             tink_core__Callback_CallbackList_Impl_::invoke($list1, $result1);
             tink_core__Callback_CallbackList_Impl_::clear($list1);
             true;
         }
     }
     return $doneTrigger->future;
 }
 static function catchExceptions($f, $report = null)
 {
     try {
         return tink_core_Outcome::Success(call_user_func($f));
     } catch (Exception $__hx__e) {
         $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
         if (($e = $_ex_) instanceof tink_core_TypedError) {
             return tink_core_Outcome::Failure($e);
         } else {
             $e1 = $_ex_;
             return tink_core_Outcome::Failure($report === null ? tink_core_TypedError::withData(null, "Unexpected Error", $e1, _hx_anonymous(array("fileName" => "Error.hx", "lineNumber" => 97, "className" => "tink.core.TypedError", "methodName" => "catchExceptions"))) : call_user_func_array($report, array($e1)));
         }
     }
 }
 public function executeResult($context)
 {
     try {
         return $context->actionContext->actionResult->executeResult($context->actionContext);
     } catch (Exception $__hx__e) {
         $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
         $e = $_ex_;
         $p_methodName = "executeResult";
         $p_lineNumber = -1;
         $p_fileName = "";
         $p_customParams = new _hx_array(array("actionContext"));
         $p_className = Type::getClassName(Type::getClass($context->actionContext));
         return tink_core__Future_Future_Impl_::sync(tink_core_Outcome::Failure(ufront_web_HttpError::wrap($e, null, _hx_anonymous(array("fileName" => "MVCHandler.hx", "lineNumber" => 70, "className" => "ufront.web.MVCHandler", "methodName" => "executeResult")))));
     }
 }
 public function getTemplateString($viewRelativePath)
 {
     $fullPath = _hx_string_or_null($this->get_viewDirectory()) . _hx_string_or_null($viewRelativePath);
     try {
         if (file_exists($fullPath)) {
             return tink_core__Future_Future_Impl_::sync(tink_core_Outcome::Success(haxe_ds_Option::Some(sys_io_File::getContent($fullPath))));
         } else {
             return tink_core__Future_Future_Impl_::sync(tink_core_Outcome::Success(haxe_ds_Option::$None));
         }
     } catch (Exception $__hx__e) {
         $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
         $e = $_ex_;
         return $e->asSurpriseError("Failed to load template " . _hx_string_or_null($viewRelativePath));
     }
 }
function tink_core__Outcome_OutcomeMapper_Impl__1(&$f, $o)
{
    switch ($o->index) {
        case 0:
            $d = _hx_deref($o)->params[0];
            $_g = call_user_func_array($f, array($d));
            switch ($_g->index) {
                case 0:
                    $d1 = _hx_deref($_g)->params[0];
                    return tink_core_Outcome::Success($d1);
                    break;
                case 1:
                    $f1 = _hx_deref($_g)->params[0];
                    return tink_core_Outcome::Failure(tink_core_Either::Right($f1));
                    break;
            }
            break;
        case 1:
            $f2 = _hx_deref($o)->params[0];
            return tink_core_Outcome::Failure(tink_core_Either::Left($f2));
            break;
    }
}
 public function getTemplateString($path)
 {
     return tink_core__Future_Future_Impl_::sync(tink_core_Outcome::Failure(new tink_core_TypedError(null, "Attempting to fetch template " . _hx_string_or_null($path) . " with UFViewEngine.  This is an abstract class, you must use one of the ViewEngine implementations.", _hx_anonymous(array("fileName" => "UFViewEngine.hx", "lineNumber" => 208, "className" => "ufront.view.UFViewEngine", "methodName" => "getTemplateString")))));
 }
function tink_core__Future_Future_Impl__13(&$f, &$map, $o)
{
    switch ($o->index) {
        case 0:
            $a = _hx_deref($o)->params[0];
            return tink_core_Outcome::Success(call_user_func_array($map, array($a)));
            break;
        case 1:
            $f1 = _hx_deref($o)->params[0];
            return tink_core_Outcome::Failure($f1);
            break;
    }
}
 public function commit()
 {
     return tink_core__Future_Future_Impl_::sync(tink_core_Outcome::Success(tink_core_Noise::$Noise));
 }
function ufront_web_upload_TmpFileUploadMiddleware_3(&$_g, &$ctx, &$dateStr, &$dir, &$file, &$onData, &$onEndPart, &$onPart, &$origFileName, &$postName, &$size, &$tmpFilePath, $result)
{
    switch ($result->index) {
        case 0:
            $s = _hx_deref($result)->params[0];
            return tink_core_Outcome::Success($s);
            break;
        case 1:
            $f = _hx_deref($result)->params[0];
            return tink_core_Outcome::Failure(ufront_web_HttpError::wrap($f, null, _hx_anonymous(array("fileName" => "TmpFileUploadMiddleware.hx", "lineNumber" => 101, "className" => "ufront.web.upload.TmpFileUploadMiddleware", "methodName" => "requestIn"))));
            break;
    }
}
 public function parseMultipart($onPart = null, $onData = null, $onEndPart = null)
 {
     $_g = $this;
     if (!$this->isMultipart()) {
         return ufront_core_SurpriseTools::success();
     }
     if ($this->_parsed) {
         throw new HException(ufront_web_HttpError::internalServerError("parseMultipart() has been called more than once.", null, _hx_anonymous(array("fileName" => "HttpRequest.hx", "lineNumber" => 93, "className" => "sys.ufront.web.context.HttpRequest", "methodName" => "parseMultipart"))));
     }
     $this->_parsed = true;
     if ($onPart === null) {
         $onPart = array(new _hx_lambda(array(&$_g, &$onData, &$onEndPart, &$onPart), "sys_ufront_web_context_HttpRequest_0"), 'execute');
     }
     if ($onData === null) {
         $onData = array(new _hx_lambda(array(&$_g, &$onData, &$onEndPart, &$onPart), "sys_ufront_web_context_HttpRequest_1"), 'execute');
     }
     if ($onEndPart === null) {
         $onEndPart = array(new _hx_lambda(array(&$_g, &$onData, &$onEndPart, &$onPart), "sys_ufront_web_context_HttpRequest_2"), 'execute');
     }
     $this->post = new haxe_ds_StringMap();
     $noParts = true;
     $isFile = false;
     $partName = null;
     $fileName = null;
     $currentContent = null;
     $callbackFutures = new _hx_array(array());
     $errors = new _hx_array(array());
     $processCallbackResult = array(new _hx_lambda(array(&$_g, &$callbackFutures, &$currentContent, &$errors, &$fileName, &$isFile, &$noParts, &$onData, &$onEndPart, &$onPart, &$partName), "sys_ufront_web_context_HttpRequest_3"), 'execute');
     $doEndOfPart = array(new _hx_lambda(array(&$_g, &$callbackFutures, &$currentContent, &$errors, &$fileName, &$isFile, &$noParts, &$onData, &$onEndPart, &$onPart, &$partName, &$processCallbackResult), "sys_ufront_web_context_HttpRequest_4"), 'execute');
     $doPart = array(new _hx_lambda(array(&$_g, &$callbackFutures, &$currentContent, &$doEndOfPart, &$errors, &$fileName, &$isFile, &$noParts, &$onData, &$onEndPart, &$onPart, &$partName, &$processCallbackResult), "sys_ufront_web_context_HttpRequest_5"), 'execute');
     $doData = array(new _hx_lambda(array(&$_g, &$callbackFutures, &$currentContent, &$doEndOfPart, &$doPart, &$errors, &$fileName, &$isFile, &$noParts, &$onData, &$onEndPart, &$onPart, &$partName, &$processCallbackResult), "sys_ufront_web_context_HttpRequest_6"), 'execute');
     try {
         sys_ufront_web_context__HttpRequest_WebOverride::parseMultipart($doPart, $doData);
     } catch (Exception $__hx__e) {
         $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
         $e = $_ex_;
         $stack = haxe_CallStack::toString(haxe_CallStack::exceptionStack());
         $err1 = "Failed to parse multipart data: " . Std::string($e) . "\n" . _hx_string_or_null($stack);
         $errors->push($err1);
     }
     if ($noParts === false) {
         call_user_func($doEndOfPart);
     }
     if ($callbackFutures->length > 0) {
         return tink_core__Future_Future_Impl_::flatMap(tink_core__Future_Future_Impl_::ofMany($callbackFutures, null), array(new _hx_lambda(array(&$_g, &$callbackFutures, &$currentContent, &$doData, &$doEndOfPart, &$doPart, &$e, &$errors, &$fileName, &$isFile, &$noParts, &$onData, &$onEndPart, &$onPart, &$partName, &$processCallbackResult), "sys_ufront_web_context_HttpRequest_7"), 'execute'), null);
     } else {
         $data5 = tink_core_Outcome::Success(tink_core_Noise::$Noise);
         return tink_core__Future_Future_Impl_::sync($data5);
     }
 }
 static function attempt($f, $report)
 {
     try {
         return tink_core_Outcome::Success(call_user_func($f));
     } catch (Exception $__hx__e) {
         $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
         $e = $_ex_;
         return tink_core_Outcome::Failure(call_user_func_array($report, array($e)));
     }
 }
function ufront_core_CallbackTools_2(&$cb, &$pos, &$t, $error, $val1, $val2)
{
    if ($error !== null) {
        $e = tink_core_TypedError::withData(500, "" . Std::string($error), $pos, _hx_anonymous(array("fileName" => "AsyncTools.hx", "lineNumber" => 266, "className" => "ufront.core.CallbackTools", "methodName" => "asSurprisePair")));
        $result = tink_core_Outcome::Failure($e);
        if ($t->{"list"} === null) {
            false;
        } else {
            $list = $t->{"list"};
            $t->{"list"} = null;
            $t->result = $result;
            tink_core__Callback_CallbackList_Impl_::invoke($list, $result);
            tink_core__Callback_CallbackList_Impl_::clear($list);
            true;
        }
    } else {
        $result1 = tink_core_Outcome::Success(new tink_core_MPair($val1, $val2));
        if ($t->{"list"} === null) {
            false;
        } else {
            $list1 = $t->{"list"};
            $t->{"list"} = null;
            $t->result = $result1;
            tink_core__Callback_CallbackList_Impl_::invoke($list1, $result1);
            tink_core__Callback_CallbackList_Impl_::clear($list1);
            true;
        }
    }
}
 public function handleError($err, $ctx, $doneTrigger)
 {
     $_g = $this;
     if (!(($ctx->completion & 1 << ufront_web_context_RequestCompletion::$CErrorHandlersTriggered->index) !== 0)) {
         $ctx->completion |= 1 << ufront_web_context_RequestCompletion::$CErrorHandlersTriggered->index;
         $errHandlerModules = $this->errorHandlers->map(array(new _hx_lambda(array(&$_g, &$ctx, &$doneTrigger, &$err), "ufront_app_HttpApplication_10"), 'execute'));
         $resMidModules = $this->responseMiddleware->map(array(new _hx_lambda(array(&$_g, &$ctx, &$doneTrigger, &$err, &$errHandlerModules), "ufront_app_HttpApplication_11"), 'execute'));
         $logHandModules = $this->logHandlers->map(array(new _hx_lambda(array(&$_g, &$ctx, &$doneTrigger, &$err, &$errHandlerModules, &$resMidModules), "ufront_app_HttpApplication_12"), 'execute'));
         $allDone = tink_core__Future_Future_Impl_::_tryFailingFlatMap(tink_core__Future_Future_Impl_::_tryFailingFlatMap($this->executeModules($errHandlerModules, $ctx, ufront_web_context_RequestCompletion::$CErrorHandlersComplete), array(new _hx_lambda(array(&$_g, &$ctx, &$doneTrigger, &$err, &$errHandlerModules, &$logHandModules, &$resMidModules), "ufront_app_HttpApplication_13"), 'execute')), array(new _hx_lambda(array(&$_g, &$ctx, &$doneTrigger, &$err, &$errHandlerModules, &$logHandModules, &$resMidModules), "ufront_app_HttpApplication_14"), 'execute'));
         $callback = null;
         $f3 = null;
         $f4 = isset($doneTrigger->trigger) ? $doneTrigger->trigger : array($doneTrigger, "trigger");
         $a13 = tink_core_Outcome::Failure($err);
         $f3 = array(new _hx_lambda(array(&$_g, &$a13, &$allDone, &$callback, &$ctx, &$doneTrigger, &$err, &$errHandlerModules, &$f3, &$f4, &$logHandModules, &$resMidModules), "ufront_app_HttpApplication_15"), 'execute');
         $callback = array(new _hx_lambda(array(&$_g, &$allDone, &$callback, &$ctx, &$doneTrigger, &$err, &$errHandlerModules, &$f3, &$logHandModules, &$resMidModules), "ufront_app_HttpApplication_16"), 'execute');
         $allDone($callback);
     } else {
         $msg = "You had an error after your error handler had already run.  Last active module: " . _hx_string_or_null($this->currentModule->className) . "." . _hx_string_or_null($this->currentModule->methodName);
         Sys::println($msg);
         Sys::println("Error Data: " . Std::string($err->data));
         $err->throwSelf();
     }
 }
 public function commitSession()
 {
     if ($this->session !== null) {
         return $this->session->commit();
     } else {
         return tink_core__Future_Future_Impl_::sync(tink_core_Outcome::Success(tink_core_Noise::$Noise));
     }
 }
 public function _makeApiCall($method, $args, $flags, $pos = null)
 {
     if (!php_Boot::$skip_constructor) {
         $_g = $this;
         $remotingCallString = "" . _hx_string_or_null($this->className) . "." . _hx_string_or_null($method) . "(" . _hx_string_or_null($args->join(",")) . ")";
         $callApi = array(new _hx_lambda(array(&$_g, &$args, &$flags, &$method, &$pos, &$remotingCallString), "ufront_api_UFAsyncApi_0"), 'execute');
         $returnError = array(new _hx_lambda(array(&$_g, &$args, &$callApi, &$flags, &$method, &$pos, &$remotingCallString), "ufront_api_UFAsyncApi_1"), 'execute');
         if (($flags & 1 << ufront_api_ApiReturnType::$ARTVoid->index) !== 0) {
             try {
                 call_user_func($callApi);
                 return tink_core__Future_Future_Impl_::sync(tink_core_Outcome::Success(null));
             } catch (Exception $__hx__e) {
                 $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
                 $e1 = $_ex_;
                 return call_user_func_array($returnError, array($e1));
             }
         } else {
             if (($flags & 1 << ufront_api_ApiReturnType::$ARTFuture->index) !== 0 && ($flags & 1 << ufront_api_ApiReturnType::$ARTOutcome->index) !== 0) {
                 try {
                     $surprise = call_user_func($callApi);
                     return tink_core__Future_Future_Impl_::map($surprise, array(new _hx_lambda(array(&$_g, &$args, &$callApi, &$flags, &$method, &$pos, &$remotingCallString, &$returnError, &$surprise), "ufront_api_UFAsyncApi_2"), 'execute'), null);
                 } catch (Exception $__hx__e) {
                     $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
                     $e2 = $_ex_;
                     return call_user_func_array($returnError, array($e2));
                 }
             } else {
                 if (($flags & 1 << ufront_api_ApiReturnType::$ARTFuture->index) !== 0) {
                     try {
                         $future = call_user_func($callApi);
                         return tink_core__Future_Future_Impl_::map($future, array(new _hx_lambda(array(&$_g, &$args, &$callApi, &$flags, &$future, &$method, &$pos, &$remotingCallString, &$returnError), "ufront_api_UFAsyncApi_3"), 'execute'), null);
                     } catch (Exception $__hx__e) {
                         $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
                         $e3 = $_ex_;
                         return call_user_func_array($returnError, array($e3));
                     }
                 } else {
                     if (($flags & 1 << ufront_api_ApiReturnType::$ARTOutcome->index) !== 0) {
                         try {
                             $outcome = call_user_func($callApi);
                             switch ($outcome->index) {
                                 case 0:
                                     $data2 = _hx_deref($outcome)->params[0];
                                     return tink_core__Future_Future_Impl_::sync(tink_core_Outcome::Success($data2));
                                     break;
                                 case 1:
                                     $err1 = _hx_deref($outcome)->params[0];
                                     return tink_core__Future_Future_Impl_::sync(tink_core_Outcome::Failure(ufront_web_HttpError::remotingError(ufront_remoting_RemotingError::RApiFailure($remotingCallString, $err1), $pos)));
                                     break;
                             }
                         } catch (Exception $__hx__e) {
                             $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
                             $e4 = $_ex_;
                             return call_user_func_array($returnError, array($e4));
                         }
                     } else {
                         try {
                             $result1 = call_user_func($callApi);
                             return tink_core__Future_Future_Impl_::sync(tink_core_Outcome::Success($result1));
                         } catch (Exception $__hx__e) {
                             $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
                             $e5 = $_ex_;
                             return call_user_func_array($returnError, array($e5));
                         }
                     }
                 }
             }
         }
     }
 }