Nextras\Orm\Repository\IdentityMap::check PHP Метод

check() публичный Метод

public check ( Nextras\Orm\Entity\IEntity $entity )
$entity Nextras\Orm\Entity\IEntity
    public function check(IEntity $entity)
    {
        if (!in_array(get_class($entity), $this->repository->getEntityClassNames(), true)) {
            throw new InvalidArgumentException("Entity '" . get_class($entity) . "' is not accepted by '" . get_class($this->repository) . "' repository.");
        }
    }

Usage Example

Пример #1
0
 /** @inheritdoc */
 public function remove($entity, $recursive = FALSE)
 {
     $entity = $entity instanceof IEntity ? $entity : $this->getById($entity);
     $this->identityMap->check($entity);
     if (isset($this->isProcessing[spl_object_hash($entity)])) {
         return $entity;
     }
     $this->isProcessing[spl_object_hash($entity)] = TRUE;
     $this->fireEvent($entity, 'onBeforeRemove');
     foreach ($entity->getMetadata()->getProperties() as $property) {
         if ($property->relationship !== NULL) {
             if (in_array($property->relationship->type, [PropertyRelationshipMetadata::MANY_HAS_ONE, PropertyRelationshipMetadata::ONE_HAS_ONE, PropertyRelationshipMetadata::ONE_HAS_ONE_DIRECTED])) {
                 $entity->getProperty($property->name)->set(NULL, TRUE);
             } elseif ($property->relationship->type === PropertyRelationshipMetadata::MANY_HAS_MANY) {
                 $entity->getValue($property->name)->set([]);
             } else {
                 $reverseRepository = $this->model->getRepository($property->relationship->repository);
                 $reverseProperty = $reverseRepository->getEntityMetadata()->getProperty($property->relationship->property);
                 if ($reverseProperty->isNullable || !$recursive) {
                     $entity->getValue($property->name)->set([]);
                 } else {
                     foreach ($entity->getValue($property->name) as $reverseEntity) {
                         $reverseRepository->remove($reverseEntity, $recursive);
                     }
                 }
             }
         }
     }
     if ($entity->isPersisted()) {
         $this->mapper->remove($entity);
         $this->identityMap->remove($entity->getPersistedId());
         $this->entitiesToFlush[1][] = $entity;
     }
     $this->detach($entity);
     $this->fireEvent($entity, 'onAfterRemove');
     unset($this->isProcessing[spl_object_hash($entity)]);
     return $entity;
 }
All Usage Examples Of Nextras\Orm\Repository\IdentityMap::check