pascalkleindienst/form-list-generator

Small library to easily display data as a table-list or a form. Its main application area is in admin/backend applications.

v1.3.0 2017-08-17 09:21 UTC

This package is not auto-updated.

Last update: 2024-11-10 04:32:49 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Code Style Total Downloads

FormListGenerator is a small library to easily display data as a table-list or a form. Its main application area is in admin/backend applications.

Install

Via Composer

$ composer require pascalkleindienst/form-list-generator

Usage

use PascalKleindienst\FormListGenerator\Generators\ListGenerator;
use PascalKleindienst\FormListGenerator\Generators\FormGenerator;
use PascalKleindienst\FormListGenerator\Support\Config;

# set the root path of the application and optionally a baseUrl
Config::set([
    'root'    => dirname(__FILE__),
    'baseUrl' => 'http://example.com'
]);

// Init Generators with yaml config
$list = new ListGenerator('list.yaml'); 
$form = new FormGenerator('form.yaml');

// Alternatively, we can use the load method (useful when you put the generator class in a container)
$list = new ListGenerator(); 
$form = new FormGenerator();
$list = $list->load('list.yaml');
$form = $form->load('form.yaml');

// Render List
# some example date, usually fetched from your DB
$listData = [
    [
        'id'         => 1,
        'full_name'  => 'John Doe',
        'age'        => 42,
        'created_at' => time(),
        'content'    => 'lorem ipsum',
        'recursive'  => [ # accessed via dot notation in yaml => recursive.test or recursive.foo
            'test' => 'Recursive Testing',
            'foo'  => 'Foo'
        ]
    ],
    [
        'id'         => 2,
        'full_name'  => 'John Doe',
        'age'        => 42,
        'created_at' => time(),
        'content'    => 'lorem ipsum',
        'recursive' [ # accessed via dot notation in yaml => recursive.test or recursive.foo
            'test' => 'Recursive Testing',
            'foo'  => 'Foo'
        ]
    ]
];
$list->render($listData);

// Render the form
$formData = [
    'id'         => 1,
    'full_name'  => 'John Doe',
    'age'        => 42,
    'created_at' => time(),
    'content'    => 'lorem ipsum',
    'recursive' [ # accessed via dot notation in yaml => recursive.test or recursive.foo
        'test' => 'Recursive Testing',
        'foo'  => 'Foo'
     ]
];
$form->render($formData);

Configuration

See docs/form.md and docs/list.md

Localization

You're also able to translate your message to another language. The only thing one must do is to set the attribute translator as a callable that will handle the translation:

$form->setTranslator('gettext');
$list->setTranslator('gettext');

The example above uses gettext() but you can use any other callable value, like [$translator, 'trans'] or your_custom_function().

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email mail@pascalkleindienst.de instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.