public static function of($class)
    {
        $reflector = new \ReflectionClass($class);

        $name = Annotation::ofClass($class, 'entity') ?: strtolower($reflector->getShortName());
        $entity = new static($name, $class);

        $defaults = $reflector->getDefaultProperties();
        foreach ($defaults as $property => $default) {
            $annotations = Annotation::ofProperty($class, $property);
            $type = !empty($annotations['var']) ? $annotations['var'] : 'string';
            $field = new Entity\Field($property, $type);
            $field->nullable = $default !== null;
            $field->default = $default;
            $field->primary = isset($annotations['id']) ?: ($property === 'id');

            $entity->fields[$property] = $field;
        }

        return $entity;
    }
public static function of($class)
    {
        $reflector = new \ReflectionClass($class);

        $name = Annotation::ofClass($class, 'entity') ?: strtolower($reflector->getShortName());
        $entity = new static($name, $class);

        $defaults = $reflector->getDefaultProperties();
        foreach ($defaults as $property => $default) {
            $annotations = Annotation::ofProperty($class, $property);
            $type = !empty($annotations['var']) ? $annotations['var'] : 'string';
            $field = new Entity\Field($property, $type);
            $field->nullable = $default !== null;
            $field->default = $default;
            $field->primary = isset($annotations['id']) ?: ($property === 'id');

            $entity->fields[$property] = $field;
        }

        return $entity;
    }
public static function of ( $ class ) { $ reflector = new \ ReflectionClass ( $ class ) ; $ name = Annotation :: ofClass ( $ class , 'entity' ) ? : strtolower ( $ reflector -> getShortName ( ) ) ; $ entity = new static ( $ name , $ class ) ; $ defaults = $ reflector -> getDefaultProperties ( ) ; foreach ( $ defaults as $ property => $ default ) { $ annotations = Annotation :: ofProperty ( $ class , $ property ) ; $ type = ! empty ( $ annotations [ 'var' ] ) ? $ annotations [ 'var' ] : 'string' ; $ field = new Entity \ Field ( $ property , $ type ) ; $ field -> nullable = $ default !== null ; $ field -> default = $ default ; $ field -> primary = isset ( $ annotations [ 'id' ] ) ? : ( $ property === 'id' ) ; $ entity -> fields [ $ property ] = $ field ; } return $ entity ; }
Generate entity from model class

@param string $class
@return Entity
Generate entity from model class