承接 packagefactory/atomicfusion-proptypes 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

packagefactory/atomicfusion-proptypes

Composer 安装命令:

composer require packagefactory/atomicfusion-proptypes

包简介

Fusion port of react-propTypes for the fusion-prototypes PackageFactory.AtomicFusion:Component and Neos.Fusion:Component

README 文档

README

Build Status

Validate the props passed to a component via @propType annotation. The syntax for the propType annotation is derived from react-propTypes.

ATTENTION: This package is by default only validating the props in development-context.

prototype(Vendor.Site:Example) < prototype(Neos.Fusion:Component) {
    @propTypes {
        # optional, enforce that only validated props exist
        @strict = true
        # validation rules for props
        title = ${PropTypes.string.isRequired}
        subtitle = ${PropTypes.string}
    }
}

This will validate the given props with the validator that created in the @propTypes section via.

Fusion Validator Prototypes

Proptypes can also be specified via fusion objects.

@propTypes {
    # all props can be marked as required via `@required = true`
    int = PropTypes:Int {
      @required = true
    }
    float = PropTypes:Float
    bool = PropTypes:Bool

    # strings allow to specify an optional `regularExpression`
    string = PropTypes:String {
        regularExpression = '/hello world/'
    }

    # allows array values that satisfy the `type`
    array = PropTypes:Array {
        type = PropTypes:Int
    }

    # allow values that satisfy one of the given validators
    union = PropTypes:Union {
        int = PropTypes:Int
        string = PropTypes:String
        ...
    }

    # allow exacly the values that are specified
    enum = PropTypes:Enum {     
      value1 = "foo"
      value2 = "bar"
      ...
    }

    # a nested structure that is valid once all children valídate
    dataStructure = PropTypes:DataStructure {
        title = PropTypes:String
        description = PropTypes:String
        ...
    }

    # a php object that satisfies the given interface
    instanceOf = PropTypes:InstanceOf {
        type = '\DateTimeInterface'
    }

    # data structure validator that uses the defined proptypes from another prototype
    fromPrototype = PropTypes:FromPrototype {
        prototypeName = "Vendor.Site:Prototype"
    }
}

Methods that are supported by the propTypes helper

  • PropTypes.any: Accepts any value including null.
  • PropTypes.boolean: Validate that a boolean value is given, accepts null.
  • PropTypes.integer: Validate that an integer is given, accepts null.
  • PropTypes.float:
    Validate that an float is given, accepts null.
  • PropTypes.string:
    Validate that an string is given, accepts null.
  • PropTypes.regex('/pattern/'): Validate that the given string matches the pattern
  • PropTypes.oneOf([123, "foo", "bar"]): Validate the value equals one of the given options.
  • PropTypes.arrayOf( PropTypes.string ): Validate an array was given and all validate with the given validator, accepts null.
  • PropTypes.anyOf( PropTypes.string, PropTypes.integer ): Validate the value validates at least with one of the given validators, accepts null.
  • PropTypes.dataStructure({'foo': PropTypes.integer, 'bar': PropTypes.string}): Validate the keys of the given array validate with the assigned Validator, accepts null and ignores all other keys. The key validators have to define wether a single key is required.
  • PropTypes.shape({'foo': PropTypes.integer, 'bar': PropTypes.string}): Validate the keys of the given array validate with the assigned Validator, accepts null and ignores all other keys. The key validators have to define wether a single key is required.
  • PropTypes.fileExists: Validate that a given value is an existing file.
  • PropTypes.instanceOf('Neos.Neos:Document'): Validate the value with the given type, if the value is a Node the NodeType is checked instead of the php-class, accepts null.

Making values mandatory

  • PropTypes.*.isRequired: To ensure a value is given the isRequired-method can be called after the type-validation. This adds an additional notEmpty validator to enforce that a value is given.

How it works

If the validation is enabled an aspect is wrapped around the evaluate method of Neos.Fusion:Component and PackageFactory.AtomicFusion:Component implementations.

This aspect will evaluated the keys in the @propTypes section wich are expected to return Flow-Validators (Neos\Flow\Validation\Validator\ValidatorInterface). Next the current prop-value ford each key is evaluated and passed to the validator. If any of the validation results contains errors a fusion-error is thrown.

The PropTypes-EelHelper is a wrapper around the PackageFactory\AtomicFusion\PropTypes\Validators\PropTypeValidator which is an EelHelper and Validator at the same time. This Object is creates an compound-validator that is controlled in a react-propTypes like syntax via eel.

By creating FusionObjects or EelHelpers that return custom validators you can extend this mechanism if needed.

Strict mode

In strict mode an error is thrown if an unvalidated prop is passed to a component in development context. This ensures that all props are validated.

To enable strict mode for a component add @strict = true to the @propTypes.

prototype(Vendor.Site:Example) < prototype(Neos.Fusion:Component) {
    @propTypes {
        @strict = true
        ...
    }
}

Settings

The propType-validation is enabled via settings. By default this setting is enabled for Development and Testing context but not enabled for Production.

PackageFactory:
  AtomicFusion:
    PropTypes:
      enable: false

Installation

PackageFactory.AtomicFusion.PropTypes is available via packagist. Just run composer require packagefactory/atomicfusion-proptypes.

We use semantic-versioning so every breaking change will increase the major-version number.

License

see LICENSE file

packagefactory/atomicfusion-proptypes 适用场景与选型建议

packagefactory/atomicfusion-proptypes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 212.1k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2018 年 01 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 packagefactory/atomicfusion-proptypes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 packagefactory/atomicfusion-proptypes 我们能提供哪些服务?
定制开发 / 二次开发

基于 packagefactory/atomicfusion-proptypes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 212.1k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 27
  • 依赖项目数: 4
  • 推荐数: 2

GitHub 信息

  • Stars: 12
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2018-01-31