fei/filer-common
Composer 安装命令:
composer require fei/filer-common
包简介
Flash applicative filer - common components
关键字:
README 文档
README
This is the Filer Common elements package which contains:
- File Entity and transformer
- File Entity validator
- Context Entity and transformer
- Context Entity validator
- Related classes
Installation and Requirement
Filer Client needs PHP 5.5 or higher.
Add this requirement to your composer.json: "fei/filer-common": : "^1.0"
Or execute composer.phar require fei/filer-common in your terminal.
Usage
Entities and classes
File entity
In addition to traditional ID and CreatedAt fields, File Entity has six important properties:
| Property | Type |
|---|---|
| uuid | string |
| revision | integer |
| category | integer |
| contentType | string |
| data | string |
| filename | string |
| file | SplFileObject |
| contexts | ArrayCollection |
$uuid(Universal Unique Identifier) is a unique id corresponding to a file. Its format is based on 36 characters as defined inRFC4122prefixed by a backend id and separated by a:. Example:bck1:f6461366-a414-4b98-a76d-d7b190252e74revisionis an integer indicating the file's current revision.categoryis an integer defining in which database the file will be stored in.contentTypedefines the content type of theFileobject.datacontains the file's content.filenamecontains the file's filename.fileis anSplFileObjectinstance. (see https://secure.php.net/manual/en/class.splfileobject.php for more details)contextsis anArrayCollectioninstance where each element is a Context entity
Context entity
In addition to traditional ID field, Context Entity has three important properties:
| Property | Type |
|---|---|
| key | string |
| value | string |
| file | File |
keyis a string defining the context's key.valueis a string defining the context's valuefileis a File object indicating the context's related file
Other tools
File validator
You have the possibility to validate a File entity with FileValidator class:
<?php use Fei\Service\Filer\Validator\FileValidator; use Fei\Service\Filer\Entity\File; $fileValidator = new FileValidator(); $file = new File(); //validate returns true if your File instance is valid, or false in the other case $isFileValid = $fileValidator->validate($file); //getErrors() allows you to get an array of errors if there are some, or an empty array in the other case $errors = $fileValidator->getErrors();
By default, all File properties must not be empty,
but you're also able to validate only a few properties of your entity, using validate methods:
<?php use Fei\Service\Filer\Validator\FileValidator; use Fei\Service\Filer\Entity\File; $fileValidator = new FileValidator(); $file = new File(); $file->setUuid('uuid'); $file->setRevision(1); $fileValidator->validateUuid($file->getUuid()); $fileValidator->validateRevision($file->getRevision()); // will return an empty array : all of our definitions are correct $errors = $fileValidator->getErrors(); echo empty($errors); // true // contentType can not be empty, let's try to set it as an empty string $file->setContentType(''); $fileValidator->validateContentType($file->getContentType()); // this time you'll get a non-empty array $errors = $fileValidator->getErrors(); echo empty($errors); // false print_r($errors); /** * print_r will return: * * Array * ( * ['contentType'] => Array * ( * 'Content-Type cannot be empty' * ) * ) **/
Context validator
You have the possibility to validate a Context entity with ContextValidator class:
<?php use Fei\Service\Filer\Validator\ContextValidator; use Fei\Service\Filer\Entity\File; use Fei\Service\Filer\Entity\Context; $contextValidator = new ContextValidator(); $file = new File(); $context = new Context([ 'key' => 'my_key', 'value' => 'my_value', 'file' => $file ]); //validate returns true if your Context instance is valid, or false in the other case $isContextValid = $contextValidator->validate($context); //getErrors() allows you to get an array of errors if there are some, or an empty array in the other case $errors = $contextValidator->getErrors();
By default, all Context properties must not be empty,
but you're also able to validate only a few properties of your entity, using validate methods:
<?php use Fei\Service\Filer\Validator\ContextValidator; use Fei\Service\Filer\Entity\Context; $contextValidator = new ContextValidator(); $context = new Context(); $context->setKey('key'); $context->setValue('value'); $contextValidator->validateKey($context->getKey()); $contextValidator->validateValue($context->getValue()); // will return an empty array : all of our definitions are correct $errors = $contextValidator->getErrors(); echo empty($errors); // true
fei/filer-common 适用场景与选型建议
fei/filer-common 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.11k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 05 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「filer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fei/filer-common 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fei/filer-common 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fei/filer-common 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 7.11k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2018-05-25