ThaDafinser / ZfcDatagrid

New package available here (see website)
https://github.com/zfc-datagrid/zfc-datagrid/
MIT License
87 stars 57 forks source link

Implement object dereferencing for setters #221

Closed popovserhii closed 7 years ago

popovserhii commented 8 years ago

Since PHP 5.4 appears awesomeness "class member access on instantiation"

(new CoolObject())->setSomething($option)->addOther($item)->etc()

It would be very useful add something like this to your library:

$actions = new Column\Action('edit');
$actions->setLabel(' ');
$actions->setTranslationEnabled();
$actions->setFormatters([
    (new \ZfcDatagrid\Column\Formatter\Link())
        ->setAttribute('class', 'pencil-edit')
        ->setLink('/spares-ras/products/' . $fmtr->getColumnValuePlaceholder($colId))
]);
$grid->addColumn($actions);
ThaDafinser commented 8 years ago

@popovsergiy you mean the fluent interface ? https://github.com/domnikl/DesignPatternsPHP/tree/master/Structural/FluentInterface

popovserhii commented 8 years ago

@ThaDafinser, yes but you are called this differently :-)

popovserhii commented 8 years ago

I meant call chain of methods

(new \ZfcDatagrid\Column\Formatter\Link())
        ->setAttribute('class', 'pencil-edit')
        ->setAttribute('data-href', '/some/link')
        ->setLink('/other/link')
jonathangreco commented 7 years ago

I see your point.

In ZfcDatagrid, indeed, most of setters are not fluent (means that they don't return $this) you can't chain them.

Why not adding return $this.

ThaDafinser commented 7 years ago

This issue was moved to zfc-datagrid/zfc-datagrid#28