Download the PHP package micayael/form-generator-bundle without Composer

On this page you can find all versions of the php package micayael/form-generator-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package form-generator-bundle

micayael/form-generator-bundle

Symfony 5 Symfony 6 Scrutinizer Quality Score Packagist License Latest Stable Version Total Downloads PHP from Packagist

Introduction

Allows you to generate Symfony forms using YAML, JSON or associative array configurations based on the standard configurations of the framework's forms component.

See: https://symfony.com/doc/current/reference/forms/types.html

It is based on the use of the add function of the form builder used to create forms with Symfony

  1. el name para el input de formulario
  2. el tipo de campo de formulario
  3. un array de options para configurar este tipo de campo
// FormInterface::add($child, string $type = null, array $options = [])
$builder->add($inputName, $inputTypeClass, $inputOptions);

With this it is possible to create a YAML configuration, JSON or an associative array in which:

This allows you to configure forms dynamically by using yaml, json or an associative array like the examples below:

YAML

name:
birthday:
  type: date
  options:
    label: 'Your Birthday'
status:
  type: choice
  options:
    choices:
      Active: A
      Inactive: I
custom_type:
  type: App\Form\Type\CustomType
  options:
    custom_option: value

JSON

{
  "name": null,
  "birthday": {
    "type": "date",
    "options": {
      "label": "Your Birthday"
    }
  },
  "status": {
    "type": "choice",
    "options": {
      "choices": {
        "Active": "A",
        "Inactive": "I"
      }
    }
  },
  "custom_type": {
    "type": "App\\Form\\Type\\CustomType",
    "options": {
      "custom_option": "value"
    }
  }
}

PHP

$formConfig = [
  'name' => NULL,
  'birthday' => [
    'type' => 'date',
    'options' => [
      'label' => 'Your Birthday',
    ],
  ],
  'status' => [
    'type' => 'choice',
    'options' => [
      'choices' => [
        'Active' => 'A',
        'Inactive' => 'I',
      ],
    ],
  ],
  'custom_type' => [
    'type' => 'App\\Form\\Type\\CustomType',
    'options' => [
      'custom_option' => 'value',
    ],
  ],
]

Installation

composer require micayael/form-generator-bundle

Usage

Where it is necessary to create a form, for example a controller or a service, you must inject the FormGenerator object provided by the bundle.

class HomeController extends AbstractController
{
    /** @required */
    public FormGenerator $formGenerator;

    public function __invoke(Request $request): Response
    {
        $formConfigArray = []; // configuration as associative array

        // Gets a FormInterface object with the configured form
        $form = $this->formGenerator->createForm($formConfigArray);

        $form->handleRequest($request);

        if($form->isSubmitted() && $form->isValid()){
            $formData = $form->getData();

            // process your form
        }
    }

The FormGenerator service provides the following methods:

  1. FormGenerator::createForm(array $formConfig, array $formOptions = [], $data = null, string $baseFormTypeClass = null, string $groupName = null): Creates a form from an associative array
  2. FormGenerator::createFormFromJson(string $formConfigJson, array $formOptions = [], $data = null, string $baseFormTypeClass = null, string $groupName = null): Creates a form from a json string
  3. FormGenerator::createFormFromYaml(string $formConfigYaml, array $formOptions = [], $data = null, string $baseFormTypeClass = null, string $groupName = null): Creates a form from a yaml string

Method arguments

  1. array $formConfig: form configuration
  2. array $formOptions = []: custom form options
  3. $data = null: form data
  4. string $baseFormTypeClass = null: Form class (FQN) that will be used as the base to add the other fields. If not passed, they are added to an empty form.
  5. string $groupName = null: name that will be used to group the fields created by the $formConfig argument as an embeded form

Development

Install dependencies

composer install

Testing

vendor/bin/phpunit

Code Review

vendor/bin/phpstan analyse src tests --level 5
vendor/bin/phpmd ./ text .phpmd-ruleset.xml --exclude var,vendor

All versions of form-generator-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
ext-json Version *
symfony/config Version ^5.1|^6.0|^7.0
symfony/dependency-injection Version ^5.1|^6.0|^7.0
symfony/form Version ^5.1|^6.0|^7.0
symfony/http-kernel Version ^5.1|^6.0|^7.0
symfony/validator Version ^5.1|^6.0|^7.0
symfony/yaml Version ^5.1|^6.0|^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package micayael/form-generator-bundle contains the following files

Loading the files please wait ...