Exemplo n.º 1
0
 public function annotationStampUpdatedOn(AnnotationEventArgs $eventArgs)
 {
     $metadata = $eventArgs->getMetadata();
     $stampMetadata = $this->getStampMetadata($metadata);
     $stampMetadata['updatedOn'] = $eventArgs->getReflection()->getName();
     $metadata->setStamp($stampMetadata);
 }
Exemplo n.º 2
0
 /**
  *
  * @param \Zoop\Shard\Annotation\AnnotationEventArgs $eventArgs
  */
 public function annotationChainValidator(AnnotationEventArgs $eventArgs)
 {
     $annotation = $eventArgs->getAnnotation();
     $eventManager = $eventArgs->getEventManager();
     $type = $eventArgs->getEventType();
     $reflection = $eventArgs->getReflection();
     $metadata = $eventArgs->getMetadata();
     $validators = [];
     foreach ($annotation->value as $validatorAnnotation) {
         $validatorEventArgs = new AnnotationEventArgs($metadata, $type, $validatorAnnotation, $reflection, $eventManager);
         $eventManager->dispatchEvent($validatorAnnotation::EVENT, $validatorEventArgs);
         $validatorMetadata = $this->getValidatorMetadata($metadata);
         if ($type == EventType::DOCUMENT && isset($validatorMetadata['document'])) {
             $validators[] = $validatorMetadata['document'];
         } elseif (isset($validatorMetadata['fields'][$reflection->getName()])) {
             $validators[] = $validatorMetadata['fields'][$reflection->getName()];
         }
     }
     if (count($validators) == 0) {
         $validator = null;
     } elseif (count($validators) == 1) {
         $validator = $validators[0];
     } elseif (count($validators) > 1) {
         $validator = ['class' => $annotation->class, 'options' => ['validators' => $validators]];
     }
     if ($type == EventType::DOCUMENT) {
         $this->setDocumentValidator($eventArgs, $validator);
     } else {
         $this->setFieldValidator($eventArgs, $validator);
     }
 }
Exemplo n.º 3
0
 /**
  *
  * @param \Zoop\Shard\Annotation\AnnotationEventArgs $eventArgs
  */
 public function annotationCryptBlockCipher(AnnotationEventArgs $eventArgs)
 {
     $annotation = $eventArgs->getAnnotation();
     $metadata = $eventArgs->getMetadata();
     $cryptMetadata = $this->getCryptMetadata($metadata);
     $cryptMetadata['blockCipher'][$eventArgs->getReflection()->getName()] = ['service' => $annotation->service, 'key' => $annotation->key, 'salt' => $annotation->salt];
     $metadata->setCrypt($cryptMetadata);
 }
Exemplo n.º 4
0
 /**
  *
  * @param \Zoop\Shard\Annotation\AnnotationEventArgs $eventArgs
  */
 public function annotationState(AnnotationEventArgs $eventArgs)
 {
     $field = $eventArgs->getReflection()->getName();
     $metadata = $eventArgs->getMetadata();
     $eventManager = $eventArgs->getEventManager();
     $metadata->addProperty('state', true);
     $metadata->setState([$field => $eventArgs->getAnnotation()->value]);
     //Add sythentic annotation to create extra permission that will allow
     //updates on the state field when access control is enabled.
     $permissionAnnotation = new Shard\Permission\Basic(['roles' => BasicPermission::WILD, 'allow' => Actions::update($field)]);
     // Raise annotation event
     $eventManager->dispatchEvent($permissionAnnotation::EVENT, new AnnotationEventArgs($metadata, EventType::DOCUMENT, $permissionAnnotation, $metadata->getReflectionClass(), $eventManager));
 }
Exemplo n.º 5
0
 /**
  *
  * @param \Zoop\Shard\Annotation\AnnotationEventArgs $eventArgs
  */
 public function annotationAccessControl(AnnotationEventArgs $eventArgs)
 {
     $annotation = $eventArgs->getAnnotation();
     $metadata = $eventArgs->getMetadata();
     if ($annotation->value) {
         $eventManager = $eventArgs->getEventManager();
         foreach ($annotation->value as $permissionAnnotation) {
             if (defined(get_class($permissionAnnotation) . '::EVENT')) {
                 // Raise annotation event
                 $eventManager->dispatchEvent($permissionAnnotation::EVENT, new AnnotationEventArgs($metadata, EventType::DOCUMENT, $permissionAnnotation, $eventArgs->getReflection(), $eventManager));
             }
         }
     }
 }
 /**
  *
  * @param \Zoop\Shard\Annotation\AnnotationEventArgs $eventArgs
  */
 public function annotationStatePermission(AnnotationEventArgs $eventArgs)
 {
     $annotation = $eventArgs->getAnnotation();
     $metadata = $eventArgs->getMetadata();
     $config = ['factory' => 'Zoop\\Shard\\State\\AccessControl\\StatePermissionFactory', 'options' => []];
     if (is_array($annotation->states)) {
         $config['options']['states'] = $annotation->states;
     } else {
         $config['options']['states'] = [$annotation->states];
     }
     if (isset($annotation->roles)) {
         if (is_array($annotation->roles)) {
             $config['options']['roles'] = $annotation->roles;
         } else {
             $config['options']['roles'] = [$annotation->roles];
         }
     } else {
         $config['options']['roles'] = [];
     }
     if (isset($annotation->allow)) {
         if (is_array($annotation->allow)) {
             $config['options']['allow'] = $annotation->allow;
         } else {
             $config['options']['allow'] = [$annotation->allow];
         }
     } else {
         $config['options']['allow'] = [];
     }
     if (isset($annotation->deny)) {
         if (is_array($annotation->deny)) {
             $config['options']['deny'] = $annotation->deny;
         } else {
             $config['options']['deny'] = [$annotation->deny];
         }
     } else {
         $config['options']['deny'] = [];
     }
     if (!$metadata->hasProperty('permissions')) {
         $metadata->addProperty('permissions', true);
         $metadata->setPermissions([]);
     }
     $permissionsMetadata = $metadata->getPermissions();
     $permissionsMetadata[] = $config;
     $metadata->setPermissions($permissionsMetadata);
 }
Exemplo n.º 7
0
 public function annotationOwner(AnnotationEventArgs $eventArgs)
 {
     $metadata = $eventArgs->getMetadata();
     $metadata->addProperty('owner', true);
     $metadata->setOwner($eventArgs->getReflection()->getName());
 }
Exemplo n.º 8
0
 /**
  *
  * @param \Zoop\Shard\Annotation\AnnotationEventArgs $eventArgs
  */
 public function annotationSoftDeleteRestoredOn(AnnotationEventArgs $eventArgs)
 {
     $metadata = $eventArgs->getMetadata();
     $softDeleteMetadata = $this->getSoftDeleteMetadata($metadata);
     $softDeleteMetadata['restoredOn'] = $eventArgs->getReflection()->getName();
     $metadata->setSoftDelete($softDeleteMetadata);
 }
Exemplo n.º 9
0
 /**
  *
  * @param \Zoop\Shard\Annotation\AnnotationEventArgs $eventArgs
  */
 public function annotationFreezeThawedOn(AnnotationEventArgs $eventArgs)
 {
     $metadata = $eventArgs->getMetadata();
     $freezeMetadata = $this->getFreezeMetadata($metadata);
     $freezeMetadata['thawedOn'] = $eventArgs->getReflection()->getName();
     $metadata->setFreeze($freezeMetadata);
 }
Exemplo n.º 10
0
 /**
  *
  * @param \Zoop\Shard\Annotation\AnnotationEventArgs $eventArgs
  */
 public function annotationUnserializerCollection(AnnotationEventArgs $eventArgs)
 {
     $metadata = $eventArgs->getMetadata();
     $annotation = $eventArgs->getAnnotation();
     $serializeMetadata = $this->getSerializerMetadata($metadata);
     $serializeMetadata['fields'][$eventArgs->getReflection()->getName()]['collectionType'] = $annotation->type;
     $metadata->setSerializer($serializeMetadata);
 }
Exemplo n.º 11
0
 /**
  *
  * @param \Zoop\Shard\Annotation\EventArgs $eventArgs
  */
 public function annotationZones(AnnotationEventArgs $eventArgs)
 {
     $metadata = $eventArgs->getMetadata();
     $metadata->addProperty('zones', true);
     $metadata->setZones($eventArgs->getReflection()->getName());
 }