fei/filer-common 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

fei/filer-common

Composer 安装命令:

composer require fei/filer-common

包简介

Flash applicative filer - common components

关键字:

README 文档

README

GitHub license continuousphp Build Status GitHub issues

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 in RFC4122 prefixed by a backend id and separated by a :. Example: bck1:f6461366-a414-4b98-a76d-d7b190252e74
  • revision is an integer indicating the file's current revision.
  • category is an integer defining in which database the file will be stored in.
  • contentType defines the content type of the File object.
  • data contains the file's content.
  • filename contains the file's filename.
  • file is an SplFileObject instance. (see https://secure.php.net/manual/en/class.splfileobject.php for more details)
  • contexts is an ArrayCollection instance 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
  • key is a string defining the context's key.
  • value is a string defining the context's value
  • file is 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

统计信息

  • 总下载量: 7.11k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 24
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2018-05-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固