/** * Create a AVRole object with a given name and ACL. * * @param string $name * @param AVACL $acl * * @return AVRole */ public static function createRole($name, AVACL $acl) { $role = AVObject::create(static::$avClassName); $role->setName($name); $role->setACL($acl); return $role; }
<?php ini_set("display_errors", "On"); error_reporting(E_ALL | E_STRICT); require 'vendor/autoload.php'; use Avos\AVClient; use Avos\AVSessionStorage; use Avos\AVUser; use Avos\AVException; use Avos\AVObject; session_start(); AVClient::initialize("app_id", "rest_key", "master_key"); AVClient::setStorage(new AVSessionStorage()); $object = AVObject::create("TestObject"); $objectId = $object->getObjectId(); $php = $object->get("elephant"); // Set values: $object->set("elephant", "php"); $object->set("today", new DateTime()); $object->setArray("mylist", [1, 2, 3]); $object->setAssociativeArray("languageTypes", array("php" => "awesome", "ruby" => "wtf")); // Save: $object->save(); echo "saved object id:" . $object->getObjectId();
/** * AVClient::_decode, internal method for decoding server responses. * * @param mixed $data The value to decode * * @return mixed * @ignore */ public static function _decode($data) { // The json decoded response from Avos will make JSONObjects into stdClass // objects. We'll change it to an associative array here. if ($data instanceof \stdClass) { $tmp = (array) $data; if (!empty($tmp)) { return self::_decode(get_object_vars($data)); } } if (!$data && !is_array($data)) { return null; } if (is_array($data)) { $typeString = isset($data['__type']) ? $data['__type'] : null; if ($typeString === 'Date') { return new \DateTime($data['iso']); } if ($typeString === 'Bytes') { return base64_decode($data['base64']); } if ($typeString === 'Pointer') { return AVObject::create($data['className'], $data['objectId']); } if ($typeString === 'File') { return AVFile::_createFromServer($data['name'], $data['url']); } if ($typeString === 'GeoPoint') { return new AVGeoPoint($data['latitude'], $data['longitude']); } if ($typeString === 'Object') { $output = AVObject::create($data['className']); $output->_mergeAfterFetch($data); return $output; } if ($typeString === 'Relation') { return $data; } $newDict = array(); foreach ($data as $key => $value) { $newDict[$key] = static::_decode($value); } return $newDict; } return $data; }