Exemplo n.º 1
0
 /**
  *  @postCreate
  */
 public static function postCreateId($doc, array $args, $conn, $annotation_args, $mapper)
 {
     $uuid = new UniversalDocument();
     $uuid->object = $doc;
     if (!empty($annotation_args['set_id'])) {
         $uuid->id = $args[0]['_id'];
     } else {
         if (!empty($annotation_args['auto_increment'])) {
             $uuid->id = Autoincrement::getId($conn, get_class($uuid));
         }
     }
     $conn->save($uuid);
     $mapper->updateProperty($doc, '@Universal', $uuid->id);
     $conn->save($doc);
 }
Exemplo n.º 2
0
/** 
 * @DefaultValue(AutoincrementBy) 
 * @DataType Int
 * @AwaysCheck
 */
function __autoincrement_field(array $docs, array $rargs, $conn, array $args)
{
    if (empty($args)) {
        throw new \Exception("@DefaultType expects at least one argument");
    }
    $ns = [];
    foreach ($args as $value) {
        if (empty($docs[$value])) {
            throw new \Exception("Cannot find {$value} property");
        }
        $ns[$value] = $docs[$value];
        if ($ns[$value] instanceof DocumentProxy) {
            $ns[$value] = $ns[$value]->getObject();
        }
        if (is_object($ns[$value])) {
            // remove silly
            $ns[$value] = clone $ns[$value];
        }
    }
    return Autoincrement::getId($conn, json_encode($ns));
}