magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Use Underscore.php

Open colinmollenhour opened this issue 12 years ago • 4 comments

PHP lacks a lot when it comes to syntax sugar, especially when working with arrays. Maybe someday this will be addressed (PHP 6?), but in the meantime there are useful tools to work around these shortcomings. One such tool is Underscore.php which is a PHP port of underscore.js.

One simple example:

$options = array(
  array('label' => 'Foo', 'value' => 'foo'),
  array('label' => 'Foo', 'value' => 'foo'),
);

// PHP standard
$values = array();
foreach ($options as $option) {
  $values = $option['value'];
}

// Underscore.php
$values = __::pluck($options, 'value');

Sure, one can include this in their own code, but by including it in core it prevents conflicts and ensures that using it is "ok". Also it could be used to clean up some existing core code.

http://brianhaveri.github.io/Underscore.php/

Just a thought. ;)

colinmollenhour avatar Apr 23 '14 16:04 colinmollenhour

@colinmollenhour, thank you for a suggestion! I will ask architects to look at the suggested improvement and let you know of the decision taken.

verklov avatar Apr 23 '14 20:04 verklov

@colinmollenhour -- good suggestion but we did not rework any core code to leverage underscore in our platform work for the initial M2 release. As you mentioned community can be innovative now and we'll consider core changes post 2.0.

TexanHogman avatar Jan 10 '15 19:01 TexanHogman

:+1:

Vinai avatar Jan 10 '15 20:01 Vinai

@colinmollenhour, as it was mentioned by @TexanHogman 'underscore' is not in our nearest plans.

vpelipenko avatar Apr 21 '15 13:04 vpelipenko