/**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     LaravelEngine::enableHttpsRedirect();
     // define cloud functions and/or hooks
     // /1.1/functions/sayHello
     Cloud::define("sayHello", function ($params, $user) {
         return "hello {$params['name']}";
     });
 }
예제 #2
0
 public function testOnInsight()
 {
     $count = 42;
     Cloud::onInsight(function ($job) use(&$count) {
         $count += 1;
     });
     Cloud::runOnInsight(null);
     $this->assertEquals(43, $count);
 }
예제 #3
0
파일: index.php 프로젝트: juvenn/php-sdk
});
Cloud::define("getMeta", function ($params, $user, $meta) {
    return array("remoteAddress" => $meta["remoteAddress"]);
});
Cloud::define("updateObject", function ($params, $user) {
    $obj = $params["object"];
    $obj->set("__testKey", 42);
    return $obj;
});
Cloud::onLogin(function ($user) {
    error_log("Logging a user");
    return;
});
Cloud::onInsight(function ($job) {
    return;
});
Cloud::onVerified("sms", function ($user) {
    return;
});
Cloud::beforeSave("TestObject", function ($obj, $user) {
    $obj->set("__testKey", 42);
    return $obj;
});
Cloud::afterSave("TestObject", function ($obj, $user) {
    return;
});
Cloud::beforeDelete("TestObject", function ($obj, $user) {
    return;
});
$engine = new LeanEngine();
$engine->start();
예제 #4
0
 /**
  * Dispatch onInsight hook
  *
  * @param array $body JSON decoded body params
  */
 private function dispatchOnInsight($body)
 {
     $meta["remoteAddress"] = $this->env["REMOTE_ADDR"];
     try {
         Cloud::runOnInsight($body, $meta);
     } catch (FunctionError $err) {
         $this->renderError($err->getMessage(), $err->getCode());
     }
     $this->renderJSON(array("result" => "ok"));
 }
예제 #5
0
 /**
  * Dispatch onInsight hook
  *
  * @param array $body JSON decoded body params
  */
 private function dispatchOnInsight($body)
 {
     if (!Client::verifyHookSign("__on_complete_bigquery_job", $body["__sign"])) {
         error_log("Invalid hook sign for onComplete Insight" . " from {$this->env['REMOTE_ADDR']}");
         $this->renderError("Unauthorized.", 401, 401);
     }
     $meta["remoteAddress"] = $this->env["REMOTE_ADDR"];
     try {
         Cloud::runOnInsight($body, $meta);
     } catch (FunctionError $err) {
         $this->renderError($err->getMessage(), $err->getCode());
     }
     $this->renderJSON(array("result" => "ok"));
 }
예제 #6
0
    return "hello {$params['name']}";
});
// /1.1/functions/sieveOfPrimes
Cloud::define("sieveOfPrimes", function ($params, $user) {
    $n = isset($params["n"]) ? $params["n"] : 1000;
    error_log("Find prime numbers less than {$n}");
    $primeMarks = array();
    for ($i = 0; $i <= $n; $i++) {
        $primeMarks[$i] = true;
    }
    $primeMarks[0] = false;
    $primeMarks[1] = false;
    $x = round(sqrt($n));
    for ($i = 2; $i <= $x; $i++) {
        if ($primeMarks[$i]) {
            for ($j = $i * $i; $j <= $n; $j = $j + $i) {
                $primeMarks[$j] = false;
            }
        }
    }
    $numbers = array();
    foreach ($primeMarks as $i => $mark) {
        if ($mark) {
            $numbers[] = $i;
        }
    }
    return $numbers;
});
/*
Cloud::onLogin(function($user) {
    // reject blocker user for login