Validates an entity.

@param AnDomainEntityAbstract $entity The entity to be validatd

@return bool
4784
public function validate($entity)
    {
        //reset the error message
        $context = $this->getCommandContext();
        $context->entity = $entity;
        if ($entity->isValidatable()) {
            $entity->resetErrors();
        }
        $result = $this->getCommandChain()->run('on.validate', $context);

        return $result !== false;
    }
533465
public function valid(EntityContract $entity, $value)
    {
        return v::length($this->getMinLength(), $this->getMaxLength())->validate($value);
    }
678344
public function validate($data = null, $entity = null)
    {
        if (is_null($data)) {
            $data = $this->getData();
        }

        $this->data = $data;
        return !count(parent::validate($data, $entity));
    }
731644
protected function assertInstance($entity)
    {
        $entityClass = $this->definition->entity();
        if (!$entity instanceof $entityClass) {
            throw new RelationException(sprintf('Relation entity must be instance of %s, got %s', $entityClass, $this->getType($entity)));
        }

        return true;
    }
286809
public function validate(EntityInterface $entity)
    {
        if (!$entity instanceof Attribution) {
            throw new Exception(
                sprintf('The Entity to validate must be an instance of %s', Attribution::class)
            );
        }

        $this->validateSource($entity->getSource());
        $this->validateTarget($entity->getTarget());
        $this->validateRole($entity->getRole());
        $errors = $this->getErrors();

        return empty($errors);
    }
1197119
public function validate($entity, Constraint $constraint)
    {
        if (!$entity instanceof Review) {
            throw new \InvalidArgumentException('Expected instance of ' . Review::class);
        }
        
        $checker = new BadWordsChecker();
        
        if (false === $checker->isBadWord($entity->getReview())) {
            return;
        }
        
        if ($this->context instanceof ExecutionContextInterface) {
            $this->context->buildViolation($constraint->message)
                ->atPath('review')
                ->addViolation();
        }
    }
390516
public function isOrm($entity)
    {
        $annotation = $this->getClassAnnotation($entity, 'Doctrine\ORM\Mapping\Entity');

        if ($annotation === null) {
            return false;
        }

        return true;
    }
184195
public function remove($entity)
    {
        if ($entity->isValid() && is_numeric($entity['id']->value)) {
            $query = 'DELETE FROM `' . $this->tableName . '` WHERE `id`=:id';
            $statement = $this->database->prepare($query);
            $statement->bindParam(':id', $entity['id']->value);
            return $statement->execute();
            // #@todo throw and exception if $stmt->errorInfo() has an error?
            // var_dump($stmt->errorInfo());
        } else {
            // #@todo: handle invalid entity
            // #@todo: handle invalid id
        }
    }
864176
public function validate(EntityContract $entity, Bag $parameters)
    {
        $errors = new Collection();

        $value = $parameters->get($this->getRelationName());

        if ($this->required && !$entity->exists && !$parameters->exists($this->getRelationName())) {
            $errors->push($this->newException(Tokens::NOT_DEFINED, $parameters->get($this->getName())));
        }

        if ($this->unique && $parameters->exists($this->getRelationName()) && $this->isUnique($entity, $value)) {
            $errors->push($this->newException(Tokens::NOT_UNIQUE, $parameters->get($this->getName())));
        }

        if ($parameters->exists($this->getRelationName()) && ($value !== null || $this->required) && !$this->valid($entity, $value)) {
            $errors->push($this->newException(Tokens::NOT_VALID, $parameters->get($this->getName())));
        }

        return $errors;
    }
881326
protected function checkFlexibleEntity(FlexibleEntityInterface $entity)
    {
        if (!($entity instanceof $this->flexible_entity_class)) {
            throw new \InvalidArgumentException(sprintf(
                "Entity class '%s' is not a '%s'.",
                get_class($entity),
                $this->flexible_entity_class
            ));
        }

        return $this;
    }
143443
public function update($entity)
    {
        $data = $this->mapper->toDbTableRow($entity);
        $this->specificationQuery->update($data->toArray());
        return true;
    }
752573
public function valid(EntityContract $entity, $value)
    {
        foreach ($this->getOptions() as $option) {
            if (class_exists($value) && is_subclass_of($value, $option)) {
                return true;
            }
        }

        return false;
    }
358298
public function validate(EntityInterface $entity)
    {
        if (!$entity instanceof UserGroup) {
            throw new Exception(
                sprintf('The Entity to validate must be an instance of %s', Role::class)
            );
        }

        $this->validateName($entity->getName());
        $this->validateDefaultRole($entity->getDefaultRole());
        $errors = $this->getErrors();

        return empty($errors);
    }
712510
public function valid(EntityContract $entity, $value)
    {
        $key = $entity->{$this->getRelationKey()};

        if (!isset($this->relations[$key])) {
            return false;
        }

        $classMorphKey = Relation::getMorphedModel($key);

        if ($classMorphKey) {
            $key = $classMorphKey;
        }

        return class_exists($key) && $value instanceof $key;
    }
594135
public function validate(EntityInterface $entity)
    {
        if (!$entity instanceof Application) {
            throw new Exception(
                sprintf('The Entity to validate must be an instance of %s', Application::class)
            );
        }

        $this->validateName($entity->getName());
        $this->validateUrl($entity->getUrl());
        $this->validateStatus($entity->getStatus());
        $this->validateLogoUrl($entity->getLogoUrl());
        $this->validateAllowProfileAssociation($entity->getAllowProfileAssociation());
        $errors = $this->getErrors();

        return empty($errors);
    }
1144528
public function truncate($entity, $andCluster = false)
    {
        try {
            $validator = new RidValidator;
            $validator->check($entity);
            $commandClass = $this->getCommandClass('truncate.record');
        } catch (ValidationException $e) {
            $commandClass = $this->getCommandClass('truncate.class');

            if ($andCluster) {
                $commandClass = $this->getCommandClass('truncate.cluster');
            }
        }

        $this->command = new $commandClass($entity);

        return $this->command;
    }
243136
private function isValidResult($result, $entity)
    {
        return 0 === \count($result)
            || (1 === \count($result)
                && $entity === ($result instanceof \Iterator ? $result->current() : current($result)));
    }