Is a value valid ?

@param string                                $action
@param \Railken\Lem\Contracts\EntityContract $entity
@param mixed                                 $value

@return Collection
546557
public function authorizeByEntity(string $action, EntityContract $entity, $value)
    {
        $permission = $this->getPermission($action);

        $result = $this->getManager()->getAgent()->can($permission);

        if (!$result) {
            return Collection::make([$this->newException(Tokens::NOT_AUTHORIZED, $permission)]);
        }

        return Collection::make();
    }
232649
public function valid(EntityContract $entity, $value)
    {
        $class = $this->getRelationManager($entity)->getRepository()->getEntity();

        return $value instanceof $class;
    }
818791
public function isGranted($action, $entity, array $parameters = array())
    {
        $entityType = defined(get_class($entity) . '::ENTITY_TYPE') ? $entity::ENTITY_TYPE : null;

        if (!is_null($entityType) && array_key_exists($entityType, $this->strategies) && $this->strategies[$entityType]->support($action)) {
            return  $this->strategies[$entityType]->isGranted($action, $entity, $parameters);
        }

        return true;
    }
292799
public function save(EntityContract $entity)
    {
        $result = new Result();

        $saving = $entity->save();

        foreach ($this->getAttributes() as $attribute) {
            $result->addErrors($attribute->save($entity));
        }

        return $result;
    }
1273715
public function setEntityType(\AgentSIB\Diadoc\Api\Proto\Events\EntityType $value = null)
    {
        $this->EntityType = $value;
    }
836408
public function setContractDocumentDateAndNumber(\AgentSIB\Diadoc\Api\Proto\Docflow\DocumentDateAndNumber $value = null)
    {
        $this->ContractDocumentDateAndNumber = $value;
    }
1337813
protected function entityReferenceSearch($value, $entity) {
    if (!is_array($value) && !($value instanceof Traversable)) {
      return false;
    }
    if (!isset($entity)) {
      throw new Exceptions\InvalidParametersException();
    }
    // Get the GUID, if the passed $entity is an object.
    if (is_array($entity)) {
      foreach ($entity as &$curEntity) {
        if (is_object($curEntity)) {
          $curEntity = $curEntity->guid;
        }
      }
      unset($curEntity);
    } elseif (is_object($entity)) {
      $entity = [$entity->guid];
    } else {
      $entity = [(int) $entity];
    }
    if (isset($value[0]) && $value[0] === 'nymph_entity_reference') {
      return in_array($value[1], $entity);
    } else {
      // Search through multidimensional arrays looking for the reference.
      foreach ($value as $curValue) {
        if ($this->entityReferenceSearch($curValue, $entity)) {
          return true;
        }
      }
    }
    return false;
  }
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;
    }
1243972
public function setAction($action)
    {
        if (!in_array($action, $this->acceptedValues)) {
            $acceptedValuesString = implode(', ', $this->acceptedValues);
            throw new \Parable\ORM\Exception("Invalid action set, only {$acceptedValuesString} are allowed.");
        }
        $this->action = $action;
        return $this;
    }
63219
protected function normalizeValue($value)
    {
        if (is_null($value)) {
            return $value;
        }

        $entityClass = $this->getEntity();
        // Validate Many2many attribute value
        if (!$this->isArray($value) && !$this->isArrayObject($value) && !$this->isInstanceOf($value, EntityCollection::class)) {
            $exception = new ValidationException(ValidationException::DATA_TYPE, [
                'array, ArrayObject or EntityCollection',
                gettype($value)
            ]);
            $exception->setAttribute($this->getName());
            throw $exception;
        }

        /* @var $entityAttribute One2ManyAttribute */
        $values = [];
        foreach ($value as $item) {
            $itemEntity = false;

            // $item can be an array of data, AbstractEntity or a simple mongo ID string
            if ($this->isInstanceOf($item, $entityClass)) {
                $itemEntity = $item;
            } elseif ($this->isArray($item) || $this->isArrayObject($item)) {
                $itemEntity = $entityClass::findById(isset($item['id']) ? $item['id'] : false);
            } elseif ($this->isString($item) && Entity::getInstance()->getDatabase()->isId($item)) {
                $itemEntity = $entityClass::findById($item);
            }

            // If instance was not found, create a new entity instance
            if (!$itemEntity) {
                $itemEntity = new $entityClass;
            }

            // If $item is an array - use it to populate the entity instance
            if ($this->isArray($item) || $this->isArrayObject($item)) {
                $itemEntity->populate($item);
            }

            $values[] = $itemEntity;
        }

        return new EntityCollection($this->getEntity(), $values);
    }
631461
public function validate(EntityContract $entity, Bag $parameters)
    {
        $errors = new Collection();

        $this->callMethods('validate', [$entity, $parameters], function ($return) use (&$errors) {
            $errors = $errors->merge($return);
        });

        return $errors;
    }
1135132
public function authorize(string $action, $value)
    {
        $permission = $this->getPermission($action);

        $result = $this->getManager()->getAgent()->can($permission);

        if (!$result) {
            return Collection::make([$this->newException(Tokens::NOT_AUTHORIZED, $permission)]);
        }

        return Collection::make();
    }
617628
protected function validate($value)
    {
        foreach ($this->validators as $validator) {
            if (!$validator->validate($value)) {
                throw new InvalidValueException(
                    "Field {$this->name}, was set with invalid value: " . var_export($value, true)
                );
            }
        }
    }
470269
public function move($action, $entity)
    {
        $this->checkSortableGroupField(static::getSortableGroupField(), $entity);

        $this->_transaction(function () use ($entity, $action) {
            $sortableField = static::getSortableField();

            $oldPosition = $this->getAttribute($sortableField);
            $newPosition = $entity->getAttribute($sortableField);

            if ($oldPosition === $newPosition) {
                return;
            }

            $isMoveBefore = $action === 'moveBefore'; // otherwise moveAfter
            $isMoveForward = $oldPosition < $newPosition;

            if ($isMoveForward) {
                $this->queryBetween($oldPosition, $newPosition)->decrement($sortableField);
            } else {
                $this->queryBetween($newPosition, $oldPosition)->increment($sortableField);
            }

            $this->setAttribute($sortableField, $this->getNewPosition($isMoveBefore, $isMoveForward, $newPosition));
            $entity->setAttribute($sortableField, $this->getNewPosition(!$isMoveBefore, $isMoveForward, $newPosition));

            $this->save();
            $entity->save();
        });
    }
64606
public function filter($value)
    {
        return isset($this->actionToStatusMap[$value])
            ? $this->actionToStatusMap[$value]
            : false;
    }
809456
public function valid(EntityContract $entity, $value)
    {
        try {
            $value = Yaml::parse($value);
        } catch (ParseException $exception) {
            return false;
        }

        return true;
    }
1124875
public function setAction($action) {
        if (!is_string($action) || empty($action)) {
            $errMessage = "The action value must be a string and not be empty";
            throw new \InvalidArgumentException($errMessage, GeneralErrors::VALUE_IS_NOT_OF_EXPECTED_TYPE);
        }

        $this->action = $action;
    }