示例#1
0
    echo "      No databases" . PHP_EOL;
}
$dbName = "test_php";
/// Adding new object to db "test_php"
$img = new Image("https://s3-eu-west-1.amazonaws.com/deepomatic-datasets/samples/image1.png");
$obj = new Object(array($img), array("name" => "puppy", "age" => 1));
$db = $client->db($dbName);
$task_index = $db->addObject($obj);
// an id has automatically been set to the object
// You need to wait for the task to complete before being able to use this object on the server side
$task_index->waitDone(true);
echo "*** Object " . $obj->id . " inserted to " . $db->dbName . PHP_EOL;
/// Retrieving our object in the db
echo "*** Getting object " . $obj->id . " from " . $db->dbName . PHP_EOL;
$obj_processed = $db->getObject($obj);
assert(compareObjects($obj_processed, $obj));
echo "*** Deleting object " . $obj->id . " from " . $db->dbName . PHP_EOL;
$task_delete = $db->deleteObject($obj_processed);
// use $task->refresh() to get the state of the task (waitDone call refresh in loop)
$task_delete->waitDone(true);
echo "*** Re-adding the object " . $obj->id . " to " . $db->dbName . PHP_EOL;
$db->addObject($obj)->waitDone(true);
$img2 = Image::fromFile("https://s3-eu-west-1.amazonaws.com/deepomatic-datasets/samples/image2.jpg");
// download file and send it as base64
$obj2 = new Object(array($img2), array("name" => "chiwawa", "age" => 2));
echo "*** Adding another object to " . $db->dbName . PHP_EOL;
$db->addObject($obj2)->waitDone(true);
$count_puppy = $db->count(array("name" => "puppy"));
echo "*** There is currently " . $count_puppy . " puppy in the db " . $db->dbName . PHP_EOL;
$count_total = $db->count();
echo "*** There is currently " . $count_total . " objects in the db " . $db->dbName . PHP_EOL;
示例#2
0
    echo 'o1 !== o2 : ' . bool2str($o1 !== $o2) . "\n";
}
class FlagSet
{
    var $set;
    function FlagSet($flagArr = array())
    {
        $this->set = $flagArr;
    }
    function addFlag($name, $flag)
    {
        $this->set[$name] = $flag;
    }
    function removeFlag($name)
    {
        if (array_key_exists($name, $this->set)) {
            unset($this->set[$name]);
        }
    }
}
$o = $p = $q = null;
$u = new FlagSet();
$u->addFlag('flag1', $o);
$u->addFlag('flag2', $p);
$v = new FlagSet(array('flag1' => $q, 'flag2' => $p));
$w = new FlagSet(array('flag1' => $q));
echo "\nComposite objects u(o,p) and v(q,p)\n";
compareObjects($u, $v);
echo "\nu(o,p) and w(q)\n";
compareObjects($u, $w);
示例#3
0
}
class Flag
{
    var $flag;
    function Flag($flag = true)
    {
        $this->flag = $flag;
    }
}
class SwitchableFlag extends Flag
{
    function turnOn()
    {
        $this->flag = true;
    }
    function turnOff()
    {
        $this->flag = false;
    }
}
$o = new Flag();
$p = new Flag(false);
$q = new Flag();
$r = new SwitchableFlag();
echo "Compare instances created with the same parameters\n";
compareObjects($o, $q);
echo "\nCompare instances created with different parameters\n";
compareObjects($o, $p);
echo "\nCompare an instance of a parent class with one from a subclass\n";
compareObjects($o, $r);