imanaging-document / check-format-bundle
此包允许您检查格式并提供映射文件系统
v2.0
2022-06-08 14:07 UTC
Requires
- php: ^7.1.3
- symfony/templating: ^5.2
- twig/twig: ^3.3
- viest/php-ext-xlswriter-ide-helper: dev-master
This package is auto-updated.
Last update: 2024-09-08 09:34:09 UTC
README
此包是一个允许您检查数组格式的工具。
您必须提供一个结构,描述您想要检查的格式以及您想要检查的数据。它可以是一个简单的数组,或者是一个数组数组。
此包内部提供了一个映射函数,您需要实现一些必要的接口使其工作。您可以在readme中找到更多关于如何使用它的信息。
此包应在imanaging-document应用程序内部使用。
使用以下命令安装此包:
$ composer require imanaging-document/check-format-bundle
配置
您必须创建一个 config/packages/imanaging_check_format.yaml 文件
imanaging_check_format: bar: ~
此配置是可选的。
检查格式
用法
您可以在项目中的任何地方访问名为 checkFormatFile 和 getObjLine 的两个静态方法,就像这样:
use Imanaging\CheckFormatBundle\CheckFormatFile; class MyBeautifulService { /** * ... */ public function myBeautifulFunction(...){ ... $result = CheckFormatFile::checkFormatLine($structureDescription, $myLineToCheckFormat)); ... } ... }
示例
检查行结构
$structure = [ // Type, Column Name, Nullable new FieldCheckFormat("string", "Name", false), new FieldCheckFormat("integer", "Age", true), new FieldCheckFormat("integer", "Height", true), new FieldCheckFormat("string", "City", true), ]; $myLine = ['Rémi', '26', '170', 'San Francisco']; $result = CheckFormatFile::checkFormatLine($structure, $myLine)); // In this case, error equals false and the errors list is empty because there is no error // $result['error'] = false; // $result['errors_list'] = [];
检查文件结构
$structure = [ // Type, Column Name, Nullable new FieldCheckFormat("string", "Name", false), new FieldCheckFormat("integer", "Age", true), new FieldCheckFormat("integer", "Height", true), new FieldCheckFormat("string", "City", true), ]; $lines = [ ['Rémi', '26', '170', 'San Francisco'], ['Antonin', '26', '181', 'Miami'], ]; $result = CheckFormatFile::checkFormatFile($structure, $lines)); // In this case, error equals false and the errors list is empty because there is no error // $result['error'] = false; // $result['errors_list'] = [];
映射
要求
- Symfony 4
- JQuery
- Bootstrap 4
- FontAwesome
配置
接口
您必须在您的 config/packages/doctrine.yaml 文件中实现以下接口
Imanaging\CheckFormatBundle\Interfaces\MappingConfigurationInterface: App\Entity\MappingConfiguration Imanaging\CheckFormatBundle\Interfaces\MappingConfigurationTypeInterface: App\Entity\MappingConfigurationType Imanaging\CheckFormatBundle\Interfaces\MappingChampPossibleInterface: App\Entity\MappingChampPossible Imanaging\CheckFormatBundle\Interfaces\MappingConfigurationValueAvanceFileInterface: App\Entity\MappingConfigurationValueAvanceFile Imanaging\CheckFormatBundle\Interfaces\MappingConfigurationValueAvanceInterface: App\Entity\MappingConfigurationValueAvance Imanaging\CheckFormatBundle\Interfaces\MappingConfigurationValueAvanceTextInterface: App\Entity\MappingConfigurationValueAvanceText Imanaging\CheckFormatBundle\Interfaces\MappingConfigurationValueAvanceTypeInterface: App\Entity\MappingConfigurationValueAvanceType Imanaging\CheckFormatBundle\Interfaces\MappingConfigurationValueInterface: App\Entity\MappingConfigurationValue Imanaging\CheckFormatBundle\Interfaces\MappingConfigurationValueTransformationInterface: App\Entity\MappingConfigurationValueTransformation Imanaging\CheckFormatBundle\Interfaces\MappingConfigurationValueTranslationInterface: App\Entity\MappingConfigurationValueTranslation
用法和示例
您可以通过ajax调用调用映射页面
<div id="mappingDiv"> <div class="text-center mt-5"> <h4><i class="fa fa-spinner fa-spin fa-fw"></i>Chargement en cours ...</h4> </div> </div>
let data = {files_directory: '/public/database/attestation/fichier_client*.csv', next_step_route: 'hephaistos_administration_import_fichier_client', mapping_configuration_type: 'integration_client'}; $.ajax({ url: "{{ path('check_format_mapping_page') }}", type: 'POST', data: data, success: function (data) { $("#mappingDiv").html(data); }, error: function () { Toast.fire({type: 'error', title: 'Error'}); } });