Overview

Namespaces

  • LeanCloud
    • Engine
    • Operation
    • Storage
    • Uploader

Classes

  • Cloud
  • LaravelEngine
  • LeanEngine
  • SlimEngine

Exceptions

  • FunctionError
  • Overview
  • Namespace
  • Class

Class Cloud

Cloud functions and hooks repository

Namespace: LeanCloud\Engine
Located at LeanCloud/Engine/Cloud.php
Methods summary
public static
# getKeys( )
public static
# define( string $funcName, callable $func )

Define a cloud function

Define a cloud function

The function shall take two arguments: the first is an array of parameters, the second is user in the session. Example:

Cloud::define("sayHello", function($params, $user) { return "Hello {$params['name']}!";
});

Parameters

$funcName
$func

See

self::run
public static
# beforeSave( string $className, callable $func )

Define before save hook for a class

Define before save hook for a class

The function shall take two arguments: the first one is class object, the second is user if available in session. If your $func throws FunctionError, the save will be rejected. Example:

Cloud::beforeSave("TestObject", function($object, $user) { $title = $object->get("title"); if (strlen($title) > 140) { // Throw error and reject the save operation. throw new FunctionError("Title is too long", 1); } // else object will be saved.
});

Parameters

$className
$func

See

LeanCloud\Engine\FunctionError
public static
# afterSave( string $className, callable $func )

Define after save hook for a class

Define after save hook for a class

The function shall take two arguments: the first one is class object, the second is user if available in session. Any error in after hook will be ignored.

Parameters

$className
$func

See

LeanCloud\Engine\FunctionError
public static
# beforeUpdate( string $className, callable $func )

Define before update hook for a class

Define before update hook for a class

The function shall take two arguments: the first one is class object, the second is user if available in session. If your $func throws FunctionError, the update will be rejected.

Parameters

$className
$func

See

LeanCloud\Engine\FunctionError
public static
# afterUpdate( string $className, callable $func )

Define after update hook for a class

Define after update hook for a class

The function shall take two arguments: the first one is class object, the second is user if available in session. Any error in $func will be ignored.

Parameters

$className
$func

See

LeanCloud\Engine\FunctionError
public static
# beforeDelete( string $className, callable $func )

Define before delete hook for a class

Define before delete hook for a class

The function shall take two arguments: the first one is class object, the second is user if available in session. If your $func throws FunctionError, the delete will be rejected.

Parameters

$className
$func

See

LeanCloud\Engine\FunctionError
public static
# afterDelete( string $className, callable $func )

Define after delete hook for a class

Define after delete hook for a class

The function shall take two arguments: the first one is class object, the second is user if available in session. Any error in $func will be ignored.

Parameters

$className
$func

See

LeanCloud\Engine\FunctionError
public static
# onLogin( callable $func )

Define hook for when user tries to login

Define hook for when user tries to login

The function takes one argument, the login user. A FunctionError could be thrown in the $func, which will reject the user for login.

Parameters

$func

See

self::runOnLogin
public static
# onVerified( string $type, callable $func )

Define hook for when user verified sms or email

Define hook for when user verified sms or email

The function takes one argument, the verified user.

Parameters

$type
Either "sms" or "email"
$func

See

self::runOnVerified
public static
# onInsight( callable $func )

Define on complete hook for big query

Define on complete hook for big query

The function takes one argument, the big query job info as array:

array( "id" => "job id", "status" => "OK/ERROR", "message" => "..."
);

Parameters

$func

See

self::runOnInsight
public static mixed
# run( string $funcName, array $params, User $user = null, array $meta = array() )

Run cloud function

Run cloud function

Example:

LeanEngine::run("sayHello", array("name" => "alice"), $user);
// sayHello(array("name" => "alice"), $user);

Parameters

$funcName
Name of defined function
$params
$data Array of parameters passed to function
$user
Request user
$meta

Optional parameters that will be passed to user function

Returns

mixed

Throws

LeanCloud\Engine\FunctionError

See

self::define
public static
# start( )

Start cloud function Stand-alone mode, start to process request.

Start cloud function Stand-alone mode, start to process request.

public static
# stop( )
public static mixed
# runHook( string $className, string $hookName, LeanObject $object, User $user = null, array $meta = array() )

Run cloud hook

Run cloud hook

Example:

LeanEngine::runHook("TestObject", "beforeUpdate", $object, $user);
// hook($object, $user);

Parameters

$className
Classname
$hookName
Hook name, e.g. beforeUpdate
$object
The object of attached hook
$user
Request user
$meta

Optional parameters that will be passed to user function

Returns

mixed

Throws

LeanCloud\Engine\FunctionError
public static
# runOnLogin( User $user, array $meta = array() )

Run hook when a user logs in

Run hook when a user logs in

Parameters

$user
The user object that tries to login
$meta

Optional parameters that will be passed to user function

Throws

LeanCloud\Engine\FunctionError

See

self::onLogin
public static
# runOnVerified( string $type, User $user, array $meta = array() )

Run hook when user verified by Email or SMS

Run hook when user verified by Email or SMS

Parameters

$type
Either "sms" or "email", case-sensitive
$user
The verifying user
$meta

Optional parameters that will be passed to user function

Throws

LeanCloud\Engine\FunctionError

See

self::onVerified
public static mixed
# runOnInsight( array $params, array $meta = array() )

Run hook on big query complete

Run hook on big query complete

Parameters

$params
Big query job info
$meta

Optional parameters that will be passed to user function

Returns

mixed

Throws

LeanCloud\Engine\FunctionError

See

self::onInsight
API documentation generated by ApiGen