/**
  * @param IdentityInterface|string $to
  */
 public function __construct($to)
 {
     $email = $to instanceof IdentityInterface ? $to->getEmail() : $to;
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         throw new \InvalidArgumentException('Invalid email');
     }
     $this->to = $to;
 }
 /**
  * {@inheritdoc}
  */
 public function translate(EntityInterface $meta, IdentityInterface $identity) : IdentityMatch
 {
     $query = (new Query())->match('entity', $meta->labels()->toPrimitive())->withProperty($meta->identity()->property(), '{entity_identity}')->withParameter('entity_identity', $identity->value())->with('entity');
     $variables = new Set('string');
     $meta->children()->foreach(function (string $property, ValueObject $child) use(&$query, &$variables) {
         $relName = (new Str('entity_'))->append($property);
         $childName = $relName->append('_')->append($child->relationship()->childProperty());
         $variables = $variables->add((string) $relName)->add((string) $childName);
         $query = $query->match('entity')->linkedTo((string) $childName, $child->labels()->toPrimitive())->through((string) $child->relationship()->type(), (string) $relName, Relationship::LEFT);
     });
     return new IdentityMatch($query->return('entity', ...$variables->toPrimitive()), (new Map('string', EntityInterface::class))->put('entity', $meta));
 }
Example #3
0
 /**
  * Add clause to match the node we want to delete and all of its children
  *
  * @param IdentityInterface $identity
  * @param object $entity
  * @param Query  $query
  *
  * @return Query
  */
 private function matchAggregate(IdentityInterface $identity, $entity, Query $query) : Query
 {
     $meta = $this->metadatas->get(get_class($entity));
     $name = $this->name->sprintf(md5($identity->value()));
     $this->variables = $this->variables->add((string) $name);
     $query = $query->match((string) $name, $meta->labels()->toPrimitive())->withProperty($meta->identity()->property(), (string) $name->prepend('{')->append('_identity}'))->withParameter((string) $name->append('_identity'), $identity->value());
     $meta->children()->foreach(function (string $property, ValueObject $child) use(&$query, $name) {
         $query = $query->match((string) $name)->linkedTo($childName = (string) $name->append('_')->append($child->relationship()->property())->append('_')->append($child->relationship()->childProperty()), $child->labels()->toPrimitive())->through((string) $child->relationship()->type(), $relName = (string) $name->append('_')->append($child->relationship()->property()));
         $this->variables = $this->variables->add($childName)->add($relName);
     });
     return $query;
 }
Example #4
0
 /**
  * Add the clause to create a relationship between nodes
  *
  * @param IdentityInterface $identity
  * @param object $entity
  * @param Query $query
  *
  * @return Query
  */
 private function createRelationship(IdentityInterface $identity, $entity, Query $query) : Query
 {
     $meta = $this->metadatas->get(get_class($entity));
     $data = $this->extractor->extract($entity);
     $start = $data->get($meta->startNode()->property());
     $end = $data->get($meta->endNode()->property());
     $varName = $this->name->sprintf(md5($identity->value()));
     $startName = $this->name->sprintf(md5($start));
     $endName = $this->name->sprintf(md5($end));
     $paramKey = $varName->append('_props');
     $properties = $this->buildProperties($meta->properties(), $paramKey);
     return $this->matchEdge($endName, $meta->endNode(), $end, $this->matchEdge($startName, $meta->startNode(), $start, $query))->create((string) $startName)->linkedTo((string) $endName)->through((string) $meta->type(), (string) $varName, DBALRelationship::RIGHT)->withProperty($meta->identity()->property(), (string) $paramKey->prepend('{')->append('}.')->append($meta->identity()->property()))->withProperties($properties->toPrimitive())->withParameters([(string) $paramKey => $data->keyIntersect($properties)->set($meta->identity()->property(), $identity->value())->toPrimitive()]);
 }
 /**
  * {@inheritdoc}
  */
 public function translate(EntityInterface $meta, IdentityInterface $identity) : IdentityMatch
 {
     $query = (new Query())->match('start')->linkedTo('end')->through((string) $meta->type(), 'entity', Relationship::RIGHT)->withProperty($meta->identity()->property(), '{entity_identity}')->withParameter('entity_identity', $identity->value())->return('start', 'end', 'entity');
     return new IdentityMatch($query, (new Map('string', EntityInterface::class))->put('entity', $meta));
 }
Example #6
0
 /**
  * Sends an identity cookie.
  * This method is used when [[enableAutoLogin]] is true.
  * It saves [[id]], [[IdentityInterface::getAuthKey()|auth key]], and the duration of cookie-based login
  * information in the cookie.
  * @param IdentityInterface $identity
  * @param integer $duration number of seconds that the user can remain in logged-in status.
  * @see loginByCookie()
  */
 protected function sendIdentityCookie($identity, $duration)
 {
     $cookie = new Cookie($this->identityCookie);
     $cookie->value = json_encode([$identity->getId(), $duration], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     $cookie->expire = time() + $duration;
     Yii::$app->getResponse()->getCookies()->add($cookie);
 }
Example #7
0
 /**
  * Add the match clause for a relationship
  *
  * @param IdentityInterface $identity
  * @param object $entity
  * @param Relationship $meta
  * @param CollectionInterface $changeset
  * @param Query $query
  *
  * @return Query
  */
 private function matchRelationship(IdentityInterface $identity, $entity, Relationship $meta, CollectionInterface $changeset, Query $query) : Query
 {
     $name = $this->name->sprintf(md5($identity->value()));
     $this->variables = $this->variables->put($name, $this->buildProperties($changeset, $meta->properties()));
     return $query->match()->linkedTo()->through((string) $meta->type(), (string) $name)->withProperty($meta->identity()->property(), (string) $name->prepend('{')->append('_identity}'))->withParameter((string) $name->append('_identity'), $identity->value());
 }
 /**
  * Update relations between Identity entity and Contact Device entity
  *
  * @param IdentityInterface $model
  */
 protected function updateIdentityContactDeviceRelations($model)
 {
     foreach ($model->getContactDevices() as $identity_contact_device) {
         if (is_null($identity_contact_device->getId())) {
             $contact_device = $this->container->get('asf_contact.contact_device.manager')->createTypedInstance($identity_contact_device->getContactDevice()->getType());
             $contact_device->setType($identity_contact_device->getContactDevice()->getType())->setLabel($identity_contact_device->getContactDevice()->getLabel())->setValue($identity_contact_device->getContactDevice()->getValue());
             $identity_contact_device->setContactDevice($contact_device);
         }
     }
     $contact_devices = array();
     $form_identity_contact_devices = $model->getContactDevices();
     foreach ($form_identity_contact_devices as $identity_contact_device) {
         if (!isset($contact_devices[$identity_contact_device->getContactDevice()->getId()])) {
             $contact_devices[$identity_contact_device->getContactDevice()->getId()] = 1;
         } else {
             $model->removeAddress($identity_contact_device);
         }
     }
     // Detecte relations removed
     $relations = $this->container->get('asf_contact.identity_contact_device.manager')->getRepository()->findBy(array('identity' => $model->getId()));
     foreach ($relations as $relation) {
         $found = false;
         foreach ($model->getContactDevices() as $identity_contact_device) {
             if ($relation->getContactDevice()->getId() == $identity_contact_device->getContactDevice()->getId()) {
                 $found = true;
             }
         }
         if (false === $found) {
             $this->container->get('asf_contact.identity.manager')->getEntityManager()->remove($relation);
         }
     }
     // Detect new relations
     foreach ($model->getContactDevices() as $identity_contact_devices) {
         $found = false;
         foreach ($relations as $relation) {
             if ($relation->getContactDevice()->getId() == $identity_contact_devices->getContactDevice()->getId()) {
                 $found = true;
             }
         }
         if (false === $found) {
             $identity_contact_devices->setIdentity($model);
             $this->container->get('asf_contact.identity.manager')->getEntityManager()->persist($identity_contact_devices);
         }
     }
 }