Git Product home page Git Product logo

lodash-php's People

Contributors

elhardoum avatar mathieu-dumoulin-tulip avatar pierredup avatar rkrx avatar wizu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lodash-php's Issues

Lack of set function - porting proposal

I noted the lack of a set function (as here). I built a sort of set function in a project of mine. At the moment it works only on array, what do you think if I make a porting of my function on your project?
What are your general guidelines to make a pull request? Do you have any suggest?
Best Regards
Domenico Rizzo

Missing has() and hasIn()

Was looking for has today and couldn't find it. I can implement has and hasIn (Seems to be the exact same to me) using the Symfony Property Access component (SPAC after) but will have one slight difference from the lodash support because SPAC doesn't support one of the suggested approach in the lodash docs. Also, it will obviously require the addition of a small dependency. Are you ok with it?

References:

The differences would be:

var object = { 'a': { 'b': 2 } };
var other = _.create({ 'a': _.create({ 'b': 2 }) });
 
_.has(object, ['a', 'b']);
// => broken, SPAC cannot resolve paths using arrays of keys

I will wait for your approval to start work on this.

Using with Laravel cause issues

Using the library with Laravel or Lumen cause the folowing issue since __ is already being used by the core framework.

Fatal error: Cannot redeclare __() (previously declared in ..../vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:947) in ..../vendor/lodash-php/lodash-php/src/compiled.php on line 5

Any idea how to fix this issue? Creating a different class name perhaps?

Thank you

Best way to support chaining

As an extension to #8 , I'd like to either document the magic methods with @method or replace them with real method calls. My IDE refuses to do code completion and other features until they're there or in the docblock. So my question is which of the two would @pierredup prefer. I always prefer real methods, even if auto-generated by a script, than more magic.

Is this project abandoned?

Release 0.0.7 was over a year ago and uses now abandoned packages.

(Package symfony/inflector is abandoned, you should avoid using it. Use EnglishInflector from the String component instead.)

`_\flatten` not expand empty array inside passed array

when I pass _\flatten an array which contains empty array, _\flatten does not expand the empty array.

ex.

use function _\flatten;

$arr = [
    [1, 2, 3],
    [],
    [4, 5, 6],
];
$result = flatten($arr);

I expected that $result is [1, 2, 3, 4, 5, 6], but actually [1, 2, 3, [], 4, 5, 6].

this behavior is expected?

Call to undefined function `_\\get()`

I'm struggling to get this library to work.

I've required it via composer. I'm trying to include it with a class (none of the examples in the docs show how to work within classes).

composer.json

{
    "name": "cakephp/app",
    "description": "CakePHP skeleton app",
    "homepage": "https://cakephp.org",
    "type": "project",
    "license": "MIT",
    "require": {
        "php": ">=5.6",
        "lodash-php/lodash-php": "^0.0.6",

php code

<?php
namespace App\Controller\Api;
use function _\get;
class Controller{
    public function __construct()
    {
        get('one.two.three');
    }

error:

 {
            "status": "500",
            "title": "Internal Server Error",
            "detail": "Call to undefined function _\\get()"
 }

I tried this without using classes and I get the same error:

<?php
namespace App\Controller\Api;
use function _\get;
get('obj.one.two.three');
die();

error: Call to undefined function _\\get()

Update: it seems other functions are working, it's only get that doesn't (Murphy's law because that's the only function I'm interested in!).

Looking through the vendor src folder I can see that the get function is not included. The README seems to indicate that it would be expected in the Objects folder but it is not present there.

I also tried composer remove and then require again. Same deal, src/Objects/get.php is missing. I'm on Mac OS X Catalina and Composer version 1.8.6

I also notice that the tests for get are missing from the tests folder.

Chaining operations

You're missing one of the important features of lodash which is the _.chain() method.

e.g:

_::chain(array)->map(function(item) {
    return item['price'];
})->sum();

Nesting these functions instead of chaining would be a real pain in the ass. Consider this example:

_::sum(_::map(array, function(item) {
    return item['price'];
}));

This example only involves two functions, but in real world we use more than that.

Compatibility Issue?

composer require lodash-php/lodash-php

Error: Package lodash-php/lodash-php at version has a PHP requirement incompatible with your PHP version (7.0.33)

implementation suggestions

suggestion 1:
implement all functions as \lodash\_ class static methods
this way _ class will be loaded on-demand only.
so far php missing namespaced functions on-demand autoload mechanics

use lodash\_;

_::$method();

suggestion 2:
split class in two or more parts:

  • first part - standalone methods
  • second part dependent extensions: (defined in separate composer module)

implement

public static function  __callStatic($method, $args) {
    foreach (static::$KNOWN_EXTENSIONS as $ext)
        if (class_exists($ext) && method_exists($ext, $method)) 
           return $ext::$method(...$args);
 }

Warning on hasUnicode.php

I'm getting those warnings when using lodash-php with PHP 7.4:

PHP Warning:  Use of undefined constant rsZWJ - assumed 'rsZWJ' (this will throw an Error in a future version of PHP) in /var/www/symfony/vendor/lodash-php/lodash-php/src/internal/hasUnicode.php on line 15
PHP Stack trace:
PHP   1. {main}() /var/www/symfony/bin/console:0
PHP   2. require() /var/www/symfony/bin/console:16
PHP   3. ComposerAutoloaderInitf1b79703f32f0edf938f45d6c5aba2e0::getLoader() /var/www/symfony/vendor/autoload.php:12
PHP   4. composerRequiref1b79703f32f0edf938f45d6c5aba2e0() /var/www/symfony/vendor/composer/autoload_real.php:59
PHP   5. require() /var/www/symfony/vendor/composer/autoload_real.php:69
PHP   6. require_once() /var/www/symfony/vendor/lodash-php/lodash-php/src/bootstrap.php:19

Warning: Use of undefined constant rsZWJ - assumed 'rsZWJ' (this will throw an Error in a future version of PHP) in /var/www/symfony/vendor/lodash-php/lodash-php/src/internal/hasUnicode.php on line 15

Call Stack:
    0.0060     402680   1. {main}() /var/www/symfony/bin/console:0
    0.0070     404480   2. require('/var/www/symfony/vendor/autoload.php') /var/www/symfony/bin/console:16
    0.0073     418048   3. ComposerAutoloaderInitf1b79703f32f0edf938f45d6c5aba2e0::getLoader() /var/www/symfony/vendor/autoload.php:12
    0.0161    1018976   4. composerRequiref1b79703f32f0edf938f45d6c5aba2e0() /var/www/symfony/vendor/composer/autoload_real.php:59
    0.0162    1021176   5. require('/var/www/symfony/vendor/lodash-php/lodash-php/src/bootstrap.php') /var/www/symfony/vendor/composer/autoload_real.php:69
    0.0274    1419224   6. require_once('/var/www/symfony/vendor/lodash-php/lodash-php/src/internal/hasUnicode.php') /var/www/symfony/vendor/lodash-php/lodash-php/src/bootstrap.php:19

PHP Warning:  Use of undefined constant rsAstralRange - assumed 'rsAstralRange' (this will throw an Error in a future version of PHP) in /var/www/symfony/vendor/lodash-php/lodash-php/src/internal/hasUnicode.php on line 15
PHP Stack trace:
PHP   1. {main}() /var/www/symfony/bin/console:0
PHP   2. require() /var/www/symfony/bin/console:16
PHP   3. ComposerAutoloaderInitf1b79703f32f0edf938f45d6c5aba2e0::getLoader() /var/www/symfony/vendor/autoload.php:12
PHP   4. composerRequiref1b79703f32f0edf938f45d6c5aba2e0() /var/www/symfony/vendor/composer/autoload_real.php:59
PHP   5. require() /var/www/symfony/vendor/composer/autoload_real.php:69
PHP   6. require_once() /var/www/symfony/vendor/lodash-php/lodash-php/src/bootstrap.php:19

Warning: Use of undefined constant rsAstralRange - assumed 'rsAstralRange' (this will throw an Error in a future version of PHP) in /var/www/symfony/vendor/lodash-php/lodash-php/src/internal/hasUnicode.php on line 15

Call Stack:
    0.0060     402680   1. {main}() /var/www/symfony/bin/console:0
    0.0070     404480   2. require('/var/www/symfony/vendor/autoload.php') /var/www/symfony/bin/console:16
    0.0073     418048   3. ComposerAutoloaderInitf1b79703f32f0edf938f45d6c5aba2e0::getLoader() /var/www/symfony/vendor/autoload.php:12
    0.0161    1018976   4. composerRequiref1b79703f32f0edf938f45d6c5aba2e0() /var/www/symfony/vendor/composer/autoload_real.php:59
    0.0162    1021176   5. require('/var/www/symfony/vendor/lodash-php/lodash-php/src/bootstrap.php') /var/www/symfony/vendor/composer/autoload_real.php:69
    0.0274    1419224   6. require_once('/var/www/symfony/vendor/lodash-php/lodash-php/src/internal/hasUnicode.php') /var/www/symfony/vendor/lodash-php/lodash-php/src/bootstrap.php:19

PHP Warning:  Use of undefined constant rsComboRange - assumed 'rsComboRange' (this will throw an Error in a future version of PHP) in /var/www/symfony/vendor/lodash-php/lodash-php/src/internal/hasUnicode.php on line 15
PHP Stack trace:
PHP   1. {main}() /var/www/symfony/bin/console:0
PHP   2. require() /var/www/symfony/bin/console:16
PHP   3. ComposerAutoloaderInitf1b79703f32f0edf938f45d6c5aba2e0::getLoader() /var/www/symfony/vendor/autoload.php:12
PHP   4. composerRequiref1b79703f32f0edf938f45d6c5aba2e0() /var/www/symfony/vendor/composer/autoload_real.php:59
PHP   5. require() /var/www/symfony/vendor/composer/autoload_real.php:69
PHP   6. require_once() /var/www/symfony/vendor/lodash-php/lodash-php/src/bootstrap.php:19

Warning: Use of undefined constant rsComboRange - assumed 'rsComboRange' (this will throw an Error in a future version of PHP) in /var/www/symfony/vendor/lodash-php/lodash-php/src/internal/hasUnicode.php on line 15

Call Stack:
    0.0060     402680   1. {main}() /var/www/symfony/bin/console:0
    0.0070     404480   2. require('/var/www/symfony/vendor/autoload.php') /var/www/symfony/bin/console:16
    0.0073     418048   3. ComposerAutoloaderInitf1b79703f32f0edf938f45d6c5aba2e0::getLoader() /var/www/symfony/vendor/autoload.php:12
    0.0161    1018976   4. composerRequiref1b79703f32f0edf938f45d6c5aba2e0() /var/www/symfony/vendor/composer/autoload_real.php:59
    0.0162    1021176   5. require('/var/www/symfony/vendor/lodash-php/lodash-php/src/bootstrap.php') /var/www/symfony/vendor/composer/autoload_real.php:69
    0.0274    1419224   6. require_once('/var/www/symfony/vendor/lodash-php/lodash-php/src/internal/hasUnicode.php') /var/www/symfony/vendor/lodash-php/lodash-php/src/bootstrap.php:19

PHP Warning:  Use of undefined constant rsVarRange - assumed 'rsVarRange' (this will throw an Error in a future version of PHP) in /var/www/symfony/vendor/lodash-php/lodash-php/src/internal/hasUnicode.php on line 15
PHP Stack trace:
PHP   1. {main}() /var/www/symfony/bin/console:0
PHP   2. require() /var/www/symfony/bin/console:16
PHP   3. ComposerAutoloaderInitf1b79703f32f0edf938f45d6c5aba2e0::getLoader() /var/www/symfony/vendor/autoload.php:12
PHP   4. composerRequiref1b79703f32f0edf938f45d6c5aba2e0() /var/www/symfony/vendor/composer/autoload_real.php:59
PHP   5. require() /var/www/symfony/vendor/composer/autoload_real.php:69
PHP   6. require_once() /var/www/symfony/vendor/lodash-php/lodash-php/src/bootstrap.php:19

Warning: Use of undefined constant rsVarRange - assumed 'rsVarRange' (this will throw an Error in a future version of PHP) in /var/www/symfony/vendor/lodash-php/lodash-php/src/internal/hasUnicode.php on line 15

Call Stack:
    0.0060     402680   1. {main}() /var/www/symfony/bin/console:0
    0.0070     404480   2. require('/var/www/symfony/vendor/autoload.php') /var/www/symfony/bin/console:16
    0.0073     418048   3. ComposerAutoloaderInitf1b79703f32f0edf938f45d6c5aba2e0::getLoader() /var/www/symfony/vendor/autoload.php:12
    0.0161    1018976   4. composerRequiref1b79703f32f0edf938f45d6c5aba2e0() /var/www/symfony/vendor/composer/autoload_real.php:59
    0.0162    1021176   5. require('/var/www/symfony/vendor/lodash-php/lodash-php/src/bootstrap.php') /var/www/symfony/vendor/composer/autoload_real.php:69
    0.0274    1419224   6. require_once('/var/www/symfony/vendor/lodash-php/lodash-php/src/internal/hasUnicode.php') /var/www/symfony/vendor/lodash-php/lodash-php/src/bootstrap.php:19

Cannot redeclare __()

I encountered this error after installing this library within a Bedrock/Sage WordPress application. This issue seems to be similar to #12.

Error

Fatal error: Cannot redeclare __() (previously declared in /app/vendor/lodash-php/lodash-php/src/compiled.php:5) in /app/web/wp/wp-includes/l10n.php on line 249

Conflicting File

I10n.php

/**
 * Retrieve the translation of $text.
 *
 * If there is no translation, or the text domain isn't loaded, the original text is returned.
 *
 * @since 2.1.0
 *
 * @param string $text   Text to translate.
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
 *                       Default 'default'.
 * @return string Translated text.
 */
function __( $text, $domain = 'default' ) {
	return translate( $text, $domain );
}

Improve autoload

Right now your autoload iterate over directory tree and manually includes every file (one function per file)

find . -name "*.php" | wc -l
288 FILES = 288 includes
This approach makes this library unusable for any serious system.

Please create one file with all functions.
You can create build script to generate this file:

suggestion:
vendor/lodash-php/lodash-php/src:
echo "declare(strict_types=1); namespace _;" > loadash-one-file.php
find . -name ".php" | grep -v internal | xargs -n 1 php -w | sed "s/<?php/\r/g" | sed "s/declare(strict_types=1); namespace _;//g" >> loadash-one-file.php
.. same for internal/
.php

^^^ this script + minor code fixes will create you one file with all your functions

Namespace issue with using 'chain' method

Code:

$visibleColumns = \_::chain($columnSettings)
	->filter(function($column) {
		return
			null == $columns['ratioCalculations'] &&
			null == $columns['averageCalculation'] &&
			null == $columns['percentageOf']
		;
	})
	->map(function($column) {
		return [
			$columns['name'],
			$columns['alt_name'],
		];
	})
	->value();

Error:

Attempted to call function "chain" from namespace "_".

Symfony\Component\Debug\Exception
UndefinedFunctionException
in vendor/lodash-php/lodash-php/src/Lodash.php (line 56)

* @return mixed     
* @throws Exception     
*/
public static function __callStatic(string $method, array $args)    
{
	return ("_\\$method")(...$args);    
}

Lack of defaultTo - porting proposal

I couldn't find the defaultTo function present in the lodash JS
I could create a pull request for the same
The defafultTo function signature would be as follows:
_::defaultTo(object|associative array, string|array, defaultValue[, defaultToOnEmpty])

why _\filter also sort passed list not only filter?

lodash-php/src/Collection/filter.php l.65

function filter(iterable $array, $predicate = null): array
{
    $iteratee = baseIteratee($predicate);
    $result = \array_filter(
        \is_array($array) ? $array : \iterator_to_array($array),
        function ($value, $key) use ($array, $iteratee) {
            return $iteratee($value, $key, $array);
        },
        \ARRAY_FILTER_USE_BOTH
    );
    \sort($result); // <- why ?
    return $result;
}

why _\filter also sort list not only filter?

it confuse me because I don't expected "filtered list is sorted".
when i need the sorted, i want to do by myself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.