Get Validator class for data type.

@param string $entity
@param mixed $data
@return Validator|false
968935
public function validator($entity, $data)
    {
        return ValidationManager::validator(self::getInstance()->getEntityStructure($entity), $data);
    }
1340235
public function get($data = [])
	{
		// Process data given.
		$processPayload = $this->process(__FUNCTION__, $data);

		if( ! $processPayload->isStatus(Payload::STATUS_VALID))
		{
			return $processPayload;
		}

		// Get a properly formatted Entity Class string.
		$entityContext = $this->formatEntityType($processPayload->getData()['entity_type']);

		return $this->aggregate[$entityContext]->get($processPayload->getData()['filter'], $processPayload->getData()['sort'], $processPayload->getData()['field'], $processPayload->getData()['embed']);
	}
642349
protected function getEntityTable($entity)
    {
        if (!$entity instanceof EntityInterface) {
            $entity = $this->getEntityClass($entity);
        }
        return $this->tablePrefix . $entity::getTable() . $this->tableSuffix;
    }
900108
public static function validator (EntityStructure $entityStructure, $data)
    {
        switch (gettype($data)) {
            case 'array':
                return new ArrayValidator($entityStructure, $data);
            default:
                return false;
        }
    }
152433
public function getData($entity = array())
    {
        if ($this->accessor == null) {
            $this->accessor = new PropertyAccessor;
        }

        foreach ($this->getFields() as $name => $field) {
            if ($mapping = $field->getMappingName()) {
                if (is_array($entity)) {
                    $entity[$mapping] = $field->getMappingValue();
                } else {
                    $this->accessor->setValue($entity, $mapping, $field->getMappingValue());
                }
            }
        }

        return $entity;
    }
1298058
public function getEntityClassName($entity)
    {
        if (array_key_exists($entity, $this->entityMap)) {
            return $this->entityMap;
        }

        return $this->rootEntityNamespace . $entity;
    }
1261207
public function getServiceSpecification($entity)
    {
        if (!is_object($entity)) {
            if ((is_string($entity) && (!class_exists($entity))) // non-existent class
                    || (!is_string($entity)) // not an object or string
            ) {
                throw new Exception\InvalidArgumentException(sprintf(
                        '%s expects an object or valid class name; received "%s"',
                        __METHOD__,
                        var_export($entity, 1)
                ));
            }
        }
    
        $serviceSpec = new ArrayObject();
        $serviceSpec['operations'] = new ArrayObject();
    
        $reflection  = new ClassReflection($entity);
        $this->parseClassSpecifications($reflection, $serviceSpec);
        
        return $serviceSpec;
    }
1060290
public function materialize(array $data, $entity)
    {
        $key = $this->getColumn()->key();
        $value = null;
        if ($this->isMaterializable($data)) {
            if (!is_null($data[$key])) {
                if ($this->isScalar()) {
                    $value = $data[$key];
                    settype($value, $this->getType());
                } else {
                    $value = AnDomainAttribute::getInstance($this->getType());
                    $value->unserialize($data[$key]);
                }
            }
        } else {
            throw new AnDomainExceptionMapping($this->getName().' Mapping Failed');
        }

        return $value;
    }
1173276
protected function getValidator($data = null)
    {
        if (!$this->validator) {
            if ($data) {
                // Validate without key
                if ($this->lastKey === '') {
                    $data = ['' => $data];
                }

                $this->options['data'] = $data;
            }

            $this->validator = $this->wei->validate($this->options);
        }

        return $this->validator;
    }
886073
protected function validateEntity($entity)
    {
        $errors = Validation::createValidatorBuilder()
            ->enableAnnotationMapping()
            ->getValidator()
            ->validate($entity);

        if ($errors->count() > 0) {
            throw RestException::createFromConstraintViolationList($errors);
        }

        return $entity;
    }
1121329
public function respondValidationError($message = "Validation Error", $data = null)
    {
        return $this->setStatusCode(ResponseHTTP::HTTP_UNPROCESSABLE_ENTITY)
            ->respondWithError($message, null, $data);
    }
188923
public function getAdminType($entity)
    {
        if (null !== $this->type) {
            return $this->type;
        }

        if (method_exists($entity, 'getAdminType')) {
            return $entity->getAdminType();
        }

        throw new InvalidArgumentException(
            'You need to implement the getAdminType method in '.
            get_class($this).' or '.get_class($entity)
        );
    }
151372
public function getTypeOf($entity, $full = false): string
    {
        if ($entity instanceof DataInterface) {
            if ($full) {
                return (string) $entity->getFamilyCode();
            }

            return (string) $entity->getFamily();
        }

        $refl = new \ReflectionClass($entity);
        if ($full) {
            $refl->getName();
        }

        return $refl->getShortName();
    }
46410
protected function checkEntityType($entity)
    {
        if (get_class($entity) != $this->entityMap->getClass() && !is_subclass_of($entity, $this->entityMap->getClass())) {
            $expected = $this->entityMap->getClass();
            $actual = get_class($entity);

            throw new InvalidArgumentException("Expected : $expected, got $actual.");
        }
    }
1320428
protected static function _getClass($data)
    {
        // check arg
        if (is_object($data)) {
            $className = get_class($data);
        } elseif (is_string($data)) {
            $className = $data;
        } else {
            return false;
        }

        if (!class_exists($className) && !interface_exists($className)) {
            return false;
        }

        // create ReflectionClass object
        $class = new ReflectionClass($data);

        // get basic class info
        $result['name'] = $class->name;
        $result['type'] = ($class->isInterface() ? 'interface' : 'class');
        if ($classComment = $class->getDocComment()) {
            $result['comment'] = $classComment;
        }
        if ($classPath = $class->getFileName()) {
            $result['path'] = $classPath . ' ' . $class->getStartLine() . '/' . $class->getEndLine();
        }
        if ($classExtName = $class->getExtensionName()) {
            $result['extension'] = $classExtName;
        }
        if ($class->isAbstract()) {
            $result['abstract'] = true;
        }
        if ($class->isFinal()) {
            $result['final'] = true;
        }

        // get all parents of class
        $class_tmp         = $class;
        $result['parents'] = array();
        while ($parent = $class_tmp->getParentClass()) {
            if (isset($parent->name)) {
                $result['parents'][] = $parent->name;
                $class_tmp           = $parent;
            }
        }
        if (count($result['parents']) == 0) {
            unset($result['parents']);
        }

        // reflecting class interfaces
        $interfaces = $class->getInterfaces();
        if (is_array($interfaces)) {
            foreach ($interfaces as $property) {
                $result['interfaces'][] = $property->name;
            }
        }

        // reflection class constants
        $constants = $class->getConstants();
        if (is_array($constants)) {
            foreach ($constants as $key => $property) {
                $result['constants'][$key] = $property;
            }
        }

        // reflecting class properties
        $properties = $class->getProperties();
        if (is_array($properties)) {
            foreach ($properties as $key => $property) {

                if ($property->isPublic()) {
                    $visible = "public";
                } elseif ($property->isProtected()) {
                    $visible = "protected";
                } elseif ($property->isPrivate()) {
                    $visible = "private";
                } else {
                    $visible = "public";
                }

                $propertyName = $property->getName();

                $result['properties'][$visible][$propertyName]['comment'] = $property->getDocComment();
                $result['properties'][$visible][$propertyName]['static']  = $property->isStatic();
                $result['properties'][$visible][$propertyName]['default'] = $property->isDefault();
                $result['properties'][$visible][$propertyName]['class']   = $property->class;
            }
        }

        // get source
        $source = null;
        if (isset($result['path']) && $result['path']) {
            $source = @file($class->getFileName());
            if (!empty($source)) {
                $result['source::source'] = implode('', $source);
            }
        }

        // reflecting class methods
        foreach ($class->getMethods() as $key => $method) {

            if ($method->isPublic()) {
                $visible = "public";
            } elseif ($method->isProtected()) {
                $visible = "protected";
            } elseif ($method->isPrivate()) {
                $visible = "protected";
            } else {
                $visible = "public";
            }

            $result['methods'][$visible][$method->name]['name'] = $method->getName();

            if ($method->isAbstract()) {
                $result['methods'][$visible][$method->name]['abstract'] = true;
            }
            if ($method->isFinal()) {
                $result['methods'][$visible][$method->name]['final'] = true;
            }
            if ($method->isInternal()) {
                $result['methods'][$visible][$method->name]['internal'] = true;
            }
            if ($method->isStatic()) {
                $result['methods'][$visible][$method->name]['static'] = true;
            }
            if ($method->isConstructor()) {
                $result['methods'][$visible][$method->name]['constructor'] = true;
            }
            if ($method->isDestructor()) {
                $result['methods'][$visible][$method->name]['destructor'] = true;
            }
            $result['methods'][$visible][$method->name]['declaringClass'] = $method->getDeclaringClass()->name;

            if ($comment = $method->getDocComment()) {
                $result['methods'][$visible][$method->name]['comment'] = $comment;
            }

            $startLine = $method->getStartLine();
            $endLine   = $method->getEndLine();
            if ($startLine && $source) {
                $from    = (int)($startLine - 1);
                $to      = (int)($endLine - $startLine + 1);
                $slice   = array_slice($source, $from, $to);
                $phpCode = implode('', $slice);

                $result['methods'][$visible][$method->name]['source::source'] = $phpCode;
            }

            if ($params = self::_getParams($method->getParameters(), $method->isInternal())) {
                $result['methods'][$visible][$method->name]['parameters'] = $params;
            }
        }

        // get all methods
        $result['all_methods'] = get_class_methods($className);
        sort($result['all_methods']);

        // sorting properties and methods
        if (isset($result['properties']['protected'])) {
            ksort($result['properties']['protected']);
        }
        if (isset($result['properties']['private'])) {
            ksort($result['properties']['private']);
        }
        if (isset($result['properties']['public'])) {
            ksort($result['properties']['public']);
        }
        if (isset($result['methods']['protected'])) {
            ksort($result['methods']['protected']);
        }
        if (isset($result['methods']['private'])) {
            ksort($result['methods']['private']);
        }
        if (isset($result['methods']['public'])) {
            ksort($result['methods']['public']);
        }

        return $result;
    }
286179
public function create($data, $entity = null)
    {
        $entity = $this->getEntity($entity);
        $fields = $this->getFields();

        // set fields
        foreach ($fields as $key => $mapping) {
            $fieldType = $this->fieldManager->get($mapping['fieldtype'], $mapping);

            // If we have a transformer setup then this takes precedence
            $mappedType = $mapping['fieldtype'];
            $handler = isset($this->transformers[$mappedType]) ? $this->transformers[$mappedType] : null;

            if ($handler) {
                $handler($entity, $data[$key]);
            } else {
                $val = isset($data[$key]) ? $data[$key] : null;
                if ($fieldType instanceof FieldTypeInterface) {
                    $fieldType->set($entity, $val);
                }
            }
        }

        return $entity;
    }
378063
public function validator($field, array $data)
    {
        $value = isset($data[$field]) ? $data[$field] : null;
        if ($this->validatorValue($value)) {
            return true;
        }

        return $this->message('{fieldName}不是链接！', [
            '{fieldName}' => $this->getName($field),
        ]);
    }