Example #1
0
 public function save($useMasterKey = false)
 {
     if (!$this->getACL()) {
         throw new AVException("Roles must have an ACL.");
     }
     if (!$this->getName() || !is_string($this->getName())) {
         throw new AVException("Roles must have a name.");
     }
     return parent::save($useMasterKey);
 }
Example #2
0
<?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();
Example #3
0
 /**
  * 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;
 }