承接 stringkey/bit-magic-bundle 相关项目开发

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

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

stringkey/bit-magic-bundle

最新稳定版本:0.0.7

Composer 安装命令:

composer require stringkey/bit-magic-bundle

包简介

Symfony bundle that allows you to do bit manipulations in code and with symfony forms

README 文档

README

Toolkit to manipulate bitfields in code and symfony forms

Using the bundle

Installation

To include the bundle in your Symfony 6.4 LTS or Symfony 7 project, run:

composer require stringkey/bit-magic-bundle

Creating a Symfony 6.4 demo app

Create a new Symfony 6.4 LTS project

symfony new bit-bundle-test --version=lts

Include the minimum required bundles

composer require maker orm form validator twig-bundle security-csrf

Setup the database connection string, since the bundle works with standard integer types there should be no issues with any database create a .env.local file

cp .env .env.local

And create the database

php bin/console doctrine:database:create

Create an entity

php bin/console make:entity BitmaskTest

Add 2 integer properties and name them

  • enableMask
  • valueMask

After creating the entity, generate the migration and execute it

php bin/console doc:mig:diff
php bin/console doc:mig:mig
php bin/console make:crud BitmaskTest

Run the symfony development server

symfony serve

And navigate to http://localhost:8000/bitmask/test

When clicking new a form with 2 fields are shown, modify the code in: src/Form/BitmaskTestType.php

Don't forget to include the usages

use Stringkey\BitMagicBundle\Form\BitMaskType;
use Stringkey\BitMagicBundle\Utilities\BitOperations;

Modify the build form method

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $choices = BitOperations::createOptions(16, 0xffff); // creates the choice fields

        /** @var BitmaskTest $bitmaskTest */
        $bitmaskTest = $builder->getData(); // fetch the entity
        $enableOption = ['enable_mask' => $bitmaskTest->getEnableMask(), 'choices' => $choices];

        $builder->add('enableMask', BitMaskType::class, ['choices' => $choices]);
        $builder->add('valueMask', BitMaskType::class, $enableOption);
    }

Refresh the create page the form should now show 2 rows of checkboxes the top one controls which fields in the bottom row are enabled

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-14