Overview

Namespaces

  • LeanCloud
    • Engine
    • Operation
    • Storage
    • Uploader

Classes

  • ACL
  • AppRouter
  • Bytes
  • Client
  • File
  • GeoPoint
  • LeanObject
  • MIMEType
  • Push
  • Query
  • Region
  • Relation
  • Role
  • RouteCache
  • SaveOption
  • SMS
  • User

Exceptions

  • BatchRequestError
  • CloudException
  • Overview
  • Namespace
  • Class

Class LeanObject

LeanObject interface to LeanCloud storage API

Direct known subclasses

LeanCloud\Role, LeanCloud\User
Namespace: LeanCloud
Located at LeanCloud/LeanObject.php
Methods summary
public
# __construct( string $className = null, string $objectId = null )

Make a new plain LeanObject.

Make a new plain LeanObject.

Parameters

$className
$objectId

Throws

InvalidArgumentException
public static LeanCloud\LeanObject
# create( string $className, string $objectId = null )

Make a new object for class

Make a new object for class

The returned object will be instance of sub-class, if className has been registered.

Parameters

$className
$objectId

Returns

LeanCloud\LeanObject
public static
# registerClass( )

Register a sub-class to LeanObject.

Register a sub-class to LeanObject.

When a sub-class extends LeanObject, it should specify a static string variable ::$className, which corresponds to a className on LeanCloud. It shall then invoke ->registerClass to register itself to LeanObject. Such that LeanObject maintains a map of className to sub-classes.

It is only callable on sub-class.

Throws

RuntimeException
public string
# getClassName( )

Get className of object

Get className of object

Returns

string
public
# disableBeforeHook( )
public
# disableAfterHook( )
public array
# getPointer( )

Pointer representation of object

Pointer representation of object

Returns

array
public array
# toJSON( )

Recursively encode object and its data to JSON

Recursively encode object and its data to JSON

Top level object are encoded to literal JSON, with __type and className stripped out.

Returns

array

See

self::toFullJSON
public array
# toFullJSON( array $seen = array() )

Recursively encode object and its data to full JSON

Recursively encode object and its data to full JSON

Recursively encode object and its (snapshot) data to full JSON, the __type and className will be included in the attributes.

Parameters

$seen
Objects that have been traversed

Returns

array

See

self::toJSON
public string
# getObjectId( )

Get objectId of object

Get objectId of object

Returns

string
public DateTime
# getCreatedAt( )

Returns

DateTime
public DateTime
# getUpdatedAt( )

Returns

DateTime
public LeanCloud\LeanObject
# set( string $key, mixed $val )

Set field value by key

Set field value by key

Parameters

$key
field key
$val
field value

Returns

LeanCloud\LeanObject

Throws

RuntimeException
public LeanCloud\LeanObject
# setACL( LeanCloud\ACL $acl )

Set ACL for object

Set ACL for object

Parameters

$acl

Returns

LeanCloud\LeanObject
public null|LeanCloud\ACL
# getACL( )

Get ACL for object

Get ACL for object

Returns

null|LeanCloud\ACL
public LeanCloud\LeanObject
# delete( string $key )

Delete field by key

Delete field by key

Parameters

$key
Field key

Returns

LeanCloud\LeanObject
public mixed
# get( string $key )

Get field value by key

Get field value by key

Parameters

$key
field key

Returns

mixed
field value
public LeanCloud\LeanObject
# increment( string $key, number $amount = 1 )

Increment a numeric field

Increment a numeric field

For decrement, provide a negative amount.

Parameters

$key
field key
$amount
amount to increment

Returns

LeanCloud\LeanObject
public LeanCloud\LeanObject
# addIn( string $key, miexed $val )

Add one object into array field

Add one object into array field

Parameters

$key
Field key
$val
Object to add

Returns

LeanCloud\LeanObject

Throws

RuntimeException
public LeanCloud\LeanObject
# addUniqueIn( string $key, mixed $val )

Add one object uniquely into array field

Add one object uniquely into array field

Parameters

$key
Field key
$val
Object to add

Returns

LeanCloud\LeanObject

Throws

RuntimeException
public LeanCloud\LeanObject
# removeIn( string $key, mixed $val )

Remove one object from array field

Remove one object from array field

Parameters

$key
Field key
$val
Object to remove

Returns

LeanCloud\LeanObject

Throws

RuntimeException
public boolean
# hasData( )

If object has data attributes.

If object has data attributes.

Returns

boolean
public boolean
# isDirty( )

If there are unsaved operations.

If there are unsaved operations.

Returns

boolean
public
# save( LeanCloud\SaveOption $option = null )

Save object and its children objects and files

Save object and its children objects and files

Parameters

$option

Throws

LeanCloud\CloudException
public
# mergeAfterSave( array $data )

Merge server data after save.

Merge server data after save.

All local changes will be cleared.

Parameters

$data
JSON decoded server response
public
# mergeAfterFetch( array $data )

Merge server data after fetch.

Merge server data after fetch.

Local changes will be cleared. Though it is different from megerAfterSave, that changes on new fields (which do not exist on server) will be preserved until saved to server.

Parameters

$data
JSON decoded server response
public
# fetch( )

Fetch data from server

Fetch data from server

Local unsaved changes will be discarded.

Throws

RuntimeException,
CloudException
public
# fetchAll( array $objects )

Fetch objects from server

Fetch objects from server

Parameters

$objects
Objects to fetch.

Throws

RuntimeException,
CloudException
public
# destroy( )

Destroy object on server

Destroy object on server

It does and only destroy current object.

Throws

LeanCloud\CloudException
public LeanCloud\Query
# getQuery( )

Return query object based on the object class

Return query object based on the object class

Returns

LeanCloud\Query
public LeanCloud\Relation
# getRelation( string $key )

Get (or build) relation on field

Get (or build) relation on field

Parameters

$key
Field key

Returns

LeanCloud\Relation

Throws

RuntimeException
public static
# traverse( array $value, function & $seen, $func )

Traverse value in a hierarchy of arrays and objects

Traverse value in a hierarchy of arrays and objects

Array and data attributes of LeanObject will be traversed, each time a non-array value found the func will be invoked with the value as arguement.

Parameters

$value
$seen Objects that have been traversed
$seen
$func A function to call when non-array value found.
$func
public array
# findUnsavedChildren( )

Find unsaved children (both files and objects) of object.

Find unsaved children (both files and objects) of object.

Returns

array
public static
# saveAll( array $objects )

Save objects and associated unsaved children and files.

Save objects and associated unsaved children and files.

Parameters

$objects
Array of objects to save

Throws

RuntimeException
public static
# destroyAll( array $objects )

Delete objects in batch

Delete objects in batch

Parameters

$objects
Array of Objects to destroy
Properties summary
public static array $PRESERVED_KEYS

Preserved keys

Preserved keys

# array("objectId", "updatedAt", "createdAt")
API documentation generated by ApiGen