locomotivemtl/charcoal-contrib-filepond
Composer 安装命令:
composer require locomotivemtl/charcoal-contrib-filepond
包简介
Charcoal filepond server adaptor
关键字:
README 文档
README
A Charcoal service provider for FilePond.
FilePond is a JavaScript library that can upload anything you throw at it, optimizes images for faster uploads, and offers a great, accessible, silky smooth user experience.
This contrib act in fact as an upload server to go along with FilePond.
Table of Contents
Installation
The preferred (and only supported) method is with Composer:
$ composer require locomotivemtl/charcoal-contrib-filepond
Then add the module to your project's module list like so:
{
"modules": {
"charcoal/file-pond/file-pond": {}
}
}
Dependencies
Required
- PHP 5.6+: PHP 7 is recommended.
- ext-fileinfo: "*",
- league/flysystem ^1.0,
- locomotivemtl/charcoal-app >= 0.7
Service Provider
Charcoal\FilePond\ServiceProvider\FilePondServiceProvider
The service provider is automatically instantiated by the module.
Services
-
FilePondService.php FilePondService can be invoked with a server config ident to bind it to a server when needed :
$action = new RequestAction([ 'logger' => $container['logger'], 'filePondService' => $container['file-pond/service']($serverIdent), ]);
Configuration
The configuration for FilePond can be found here : FilePondConfig.php.
It uses the config file file-pond.json as default configset and can be overridden in your project's config.
getServer($ident) and getServers() can be called on the config to retrieve server configuration(s) : ServerConfig.php
The config defines a list of servers :
A server is a combination of an endpoint mapped with a filesystem and information regarding file paths.
Server options.
| Option | Description | Default value |
|---|---|---|
| route | The server endpoint url for the front-end app. Feeds the server option of FilePond.js | /file-pond |
| filesystem_ident | Which Filesystem to use. See charcoal-app. | private |
| upload_path | The definitive upload path root for files once the submission is completed. This path can be overridden in the submission action. The Helper FilePondAwareTrait will attempt to save the upload using the property's upload_path | uploads/file-pond |
| transfer_dir | The temporary file-pond folder root. Used while processing front-end file upload. Files from this directory will be transferred to there final location after the submission is completed. | tmp/file-pond |
Usage
Overrides the Module Config as needed by copying the file-pond.json structure in your project's config file as so:
{
"contrib": {
"file-pond": {
"config": {
"servers": {
"default": {
"route": "/file-pond",
"filesystem_ident": "private",
"upload_path": "uploads/file-pond",
"transfer_dir": "tmp/file-pond"
},
"s3": {
"route": "/file-pond/s3",
"filesystem_ident": "s3",
"upload_path": "uploads/file-pond",
"transfer_dir": "tmp/file-pond"
}
}
}
}
}
}
Set a route to give to the FilePond.js front-end framework. A slim route will automatically be created using the desired pattern. Once that is done, configure the front-end file-pond module using the correct FilePond documentation.
The key part of this process is that when the form is submitted, the server handles the transferring of previously uploaded files to their final paths. This allows to move uploads to folders that contains a user specific id and conceals the real path mapping of the server for security reasons.
You can use the FilePondAwareTrait on the action controller to handle filepond transfers. First set the required dependencies like that:
<?php // From 'charcoal-contrib-filepond' use Charcoal\FilePond\Service\Helper\FilePondAwareTrait; /** * Create a new instructor. */ class SomeAction extends AbstractAction { use FilePondAwareTrait; /** * Inject dependencies from a DI Container. * * @param Container $container A Pimple DI service container. * @return void */ public function setDependencies(Container $container) { parent::setDependencies($container); $this->setFilePondService($container['file-pond/service']('private')); } }
Then you can use the handleTransfer() method to facilitate the transfer upload process.
handleTransfer() for reference :
/** * Attempts to handle the transfer of uploads given the proper parameters. * If possible, it will try to : * - fetch the upload path from the property. * - fetch the filesystem based on the public access of the property. * - Pass it through the best processor depending on wether their were ids passed or not. * * @param string|array|null $ids The uploaded files ids. Let to null to force $_FILES and $_POST. * @param string|PropertyInterface|null $property The property ident or a property. * @param ModelInterface|string|null $context The context object as model or class ident. * @param string|null $pathSuffix Path suffix. * @return array */ protected function handleTransfer( $ids = null, $property = null, $context = null, $pathSuffix = null )
Example of usage :
/** Transfer uploaded files */ $files = $this->handleTransfer( $submissionData['someProp'], 'some_prop', $someModel, $someModel->property('id')->autoGenerate() );
Development
To install the development environment:
$ composer install
To run the scripts (phplint, phpcs, and phpunit):
$ composer test
API Documentation
- The auto-generated
phpDocumentorAPI documentation is available at:
https://locomotivemtl.github.io/charcoal-contrib-filepond/docs/master/ - The auto-generated
apigenAPI documentation is available at:
https://codedoc.pub/locomotivemtl/charcoal-contrib-filepond/master/
Development Dependencies
- [php-coveralls/php-coveralls][phpcov]
- [phpunit/phpunit][phpunit]
- [squizlabs/php_codesniffer][phpcs]
Coding Style
The charcoal-contrib-filepond module follows the Charcoal coding-style:
- PSR-1
- PSR-2
- PSR-4, autoloading is therefore provided by Composer.
- phpDocumentor comments.
- phpcs.xml.dist and .editorconfig for coding standards.
Coding style validation / enforcement can be performed with
composer phpcs. An auto-fixer is also available withcomposer phpcbf.
Credits
License
Charcoal is licensed under the MIT license. See LICENSE for details.
locomotivemtl/charcoal-contrib-filepond 适用场景与选型建议
locomotivemtl/charcoal-contrib-filepond 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 582 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 06 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「charcoal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 locomotivemtl/charcoal-contrib-filepond 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 locomotivemtl/charcoal-contrib-filepond 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 locomotivemtl/charcoal-contrib-filepond 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
UI tools (Dashboard, Layout, Form and Menu)
Charcoal Communicator standardizes email communications destined for users and administors.
Charcoal service provider for mailchimp implementation.
Utils for content builder style attachments, using group attachment widget.
Admin notification module.
Charcoal search module.
统计信息
- 总下载量: 582
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-28