PHP port of Underscore.js

Overview

Underscore.php

Underscore.php is a PHP port of Underscore.js.

In addition to porting Underscore's functionality, Underscore.php includes matching unit tests. Thanks to Jeremy Ashkenas and all contributors to Underscore.js.

For docs, license, tests, change log, and downloads, see: https://brianhaveri.github.io/Underscore.php/

Comments
  • Work with object methods too.

    Work with object methods too.

    Hey !

    We need some code to work with collections of objects. Sometimes we have gets and sets methods to work like ->name(), or get_name(), set_name(), getName()., getAge() , ..........

    The underscore php need to be prepered to work with this methods. like: _::pluck($collection, $nameOfMethod, $arrayParams.)

    opened by sadjow 9
  • list() function causing problems

    list() function causing problems

    It seems the list() function is being used incorrectly:

    list($one, $two) = array('one')

    While this produces what is usually the desired result in the code ($one is set to 'one' and $two is set to NULL), this isn't technically a correct use of list() and produces an undefined offset notice.

    opened by mattm458 5
  • "__" is considered reserved in PHP

    From http://php.net/manual/en/language.oop5.magic.php (and later http://us3.php.net/manual/en/userlandnaming.rules.php)

    "PHP reserves all function names starting with __ as magical. It is recommended that you do not use function names with __ in PHP unless you want some documented magic functionality."

    This does make me a bit reluctant about using the library. As far as I know there are no existing conflicts, but I worry about the potential down the road.

    opened by funkatron 4
  • Allows the first argument of

    Allows the first argument of "extend" and "defaults" to be passed by reference

    Provides the option of passing the first argument by reference, directly modifying the object.

    Current syntax: $object = array('k1' => 'a2'); $object = __::extend($object, array('k1' => 'v1', 'k2' => 'v2')); // $object === array('k1'=>'v1', 'k2' => 'v2');

    With changes: $object = array('k1' => 'a2'); __::extend(&$object, array('k1' => 'v1', 'k2' => 'v2')); OR $object = __::extend($object, array('k1' => 'v1', 'k2' => 'v2')); // $object === array('k1'=>'v1', 'k2' => 'v2');

    opened by tgriesser 3
  • isRegExp to use php last error?

    isRegExp to use php last error?

    I saw that isRegExp is not implemented yet. I have once before needed to know during run time whether or not a string is a regular expression string or not, and after a lot of research, I failed quite epicly. So I turned to stackoverflow where user ThiefMaster gave me some code that works:

    ini_set('track_errors', 'on');
    $php_errormsg = '';
    @preg_match('/[blah/', '');
    if($php_errormsg) echo 'regex is invalid';
    

    Which works. Maybe this can be implemented as isRegExp? I'm not sure if it's a good idea though, hence why I'm asking.

    Alternatively, maybe interoperability with a library like Flux?

    opened by hoshsadiq 0
  • 'bind' and 'bindAll'

    'bind' and 'bindAll'

    Adds in support for 'bind' and 'bindAll', although 'bindAll' is not as fancy as it is in underscore.js. It needs to be used with the list construct.

    Ex:

    <?php
    require('underscore.php');
    
    $f = function($passed=null) {
        echo $passed . "\n";
    };
    
    $f2 = function($passed=null) {
        var_dump($this);
    };
    
    $f =  __::bind($f, json_decode('{"property":"value"}'), 'passed by __', $f);
    $f2 = __::bind($f2, json_decode('{"property":"value"}'), 'passed', $f);
    
    $f('i passed this directly');
    $f();
    $f2();
    $a = json_decode('{"property":"value"}');
    
    $f = function() {
        $this->property = 'nope';
    };
    
    $f2 = function($passed=null) {
        var_dump($this);
    };
    
    list($f, $f2) = __::bindAll($a, $f, $f2);
    
    $f();
    $f2();
    var_dump($a);
    
    opened by chrsm 0
  • Updates

    Updates

    This seems to have fixed the issues with this ticket. I also added the isNull function which the docs claim this has, but it's actually missing.

    Like the ticket says, I basically made a proxy class that handles the static and non static methods yet keeps the chaining functionality.

    opened by bayleedev 0
  • Transfer ownership?

    Transfer ownership?

    @brianhaveri since it seems you have abandoned this package, would you consider transferring the ownership to someone else to maintain? I think that @thephpleague would consider taking it over.

    opened by shadowhand 14
  • issue-38: Support ArrayAccess objects in pluck

    issue-38: Support ArrayAccess objects in pluck

    Although I understand that objects of type ArrayAccess don't and shouldn't behave the same way as arrays, it would be great if pluck would support objects of type ArrayAccess just like any other arrays or objects.

    This commit supports that behavior and contains the additional unit tests for that.

    opened by Tohnmeister 0
  • pluck does not pluck values if elements are of type ArrayAccess

    pluck does not pluck values if elements are of type ArrayAccess

    In PHP it's possible to implement a custom array class, by implementing the ArrayAccess interface. That way you can use any instance of your class as be it an array. We had our own implementation of pluck which could handle elements that did this. But underscore's pluck doesn't seem to be able to handle these custom array types.

    The line from our own implementation that checked for keys existence in elements, was:

    if (isset($element[$key])) { // Must use isset instead of array_key_exists, because the latter does not work correctly on self implementing ArrayAccess classes.
    

    Note the comment.

    It would be great if underscore would support this too. We'd rather use your pluck version than our own.

    opened by Tohnmeister 0
  • Context of anonymous function is lost

    Context of anonymous function is lost

    The context of where the function is being called is lost. This is very unfortunate when I want to do some nested 'each' functions. Is there a way to overcome this?

    opened by alber70g 0
Owner
Brian Haveri
Director of Engineering @ TrainHeroic. We build software that helps coaches and athletes be their best. We're hiring.
Brian Haveri
Adds phone number functionality to TYPO3 based on the PHP port of Google's libphonenumber API by giggsey

TYPO3 Phone Adds phone number functionality to TYPO3 based on the PHP port of Google's libphonenumber API by giggsey. Installation composer require si

Simon Schaufelberger 3 Oct 25, 2022
This is a Laravel port of the local_time gem from Basecamp.

This is a Laravel port of the local_time gem from Basecamp. It makes it easy to display date and time to users in their local time. Its Blade componen

Tony Messias 56 Oct 7, 2022
Asset Component is a port of Laravel 3 Asset for Orchestra Platform.

Asset Component is a port of Laravel 3 Asset for Orchestra Platform. The component main functionality is to allow asset declaration to be handle dynamically and asset dependencies can be resolve directly from the container. It however is not intended to becoma an asset pipeline package for Laravel, for such purpose we would recommend to use Grunt or Gulp.

Orchestra Platform 54 Mar 31, 2022
Magewire is a Laravel Livewire port for Magento 2.

Magewire is a Laravel Livewire port for Magento 2. The goal is to make it fun and easy to build modern, reactive and dynamic interfaces, without leaving the comfort of Magento's core layout and template systems. Magewire can be the missing piece when you intend to build dynamic and reactive features, but don't require or feel comfortable working with a full JavaScript framework like Vue or React.

Magewirephp 120 Jan 2, 2023
Laravel 4.* and 5.* service providers to handle PHP errors, dump variables, execute PHP code remotely in Google Chrome

Laravel 4.* service provider for PHP Console See https://github.com/barbushin/php-console-laravel/releases/tag/1.2.1 Use "php-console/laravel-service-

Sergey 73 Jun 1, 2022
Public API for the project coding.events. Made in PHP 8.0 with Lumen 8, PHP-FPM, NGINX and MySQL 8.

coding.events API Uma API feita apenas para passar o tempo, montando uma API para o site <coding.events>. Sinta-se livre para usar esse código como es

Kaique Garcia 3 Oct 9, 2022
PHP phonebook with map (Active Directory, LDAP -> MySQL, PHP)

LDAP phonebook ???? ???? Development ветка Вопросы предпочтительнее задавать в Issues, а не по почте Корпоративный телефонный справочник с отображение

null 47 Nov 30, 2022
States allows you to create PHP classes following the State Pattern in PHP.

States allows you to create PHP classes following the State Pattern in PHP. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements and this improve maintainability and workflows writing.

Teknoo Software 10 Nov 20, 2022
PHP components - collection of cross-project PHP classes

PHP components Collection of cross-project PHP classes. Install: $ composer require ansas/php-component Ansas\Component\Convert\ConvertPrice Convert "

null 1 Jan 5, 2022
Lavacharts is a graphing / charting library for PHP 5.4+ that wraps Google's Javascript Chart API.

Lavacharts 3.1.12 Lavacharts is a graphing / chart library for PHP5.4+ that wraps the Google Chart API. Stable: Dev: Developer Note Please don't be di

Kevin Hill 616 Dec 17, 2022
PHP Secure Headers

Secure Headers Add security related headers to HTTP response. The package includes Service Providers for easy Laravel integration. Version Installatio

null 431 Dec 26, 2022
A Simple GUID creator Laravel Package for PHP

A Simple GUID creator package for PHP. This package is useful for creating globally unique identifiers (GUID). It's under MIT license so it's free for

Sujip Thapa 15 Jun 26, 2021
laravel package for the Ar-PHP Project

laravel package for the Ar-PHP Project this is just a wrapper to use with laravel for the Ar-PHP Library, for more details checkout khaled-alshamaa

ATM-code 20 Dec 21, 2022
A laravel service provider for the netsuite-php library service

netsuite-laravel A PHP supplemental package to the ryanwinchester/netsuite-php package to add the NetSuite service client to the service container of

NetsuitePHP 6 Nov 9, 2022
Simplest Slugify for PHP to convert string into a slug.

Simplest Slugify for PHP to convert string into a slug. Documentation You can find the detailed documentation here in Slugify Documentation. Contribut

Pharaonic 6 Mar 12, 2022
PHP package to help the development of Laravel-based Telegram bots

Laravel-telegram-bot Project description goes here. This description is usually two to three lines long. It should give an overview of what the projec

CC - UFFS 6 May 10, 2021
Deploy and execute non-PHP AWS Lambda functions from your Laravel application.

Sidecar for Laravel Deploy and execute non-PHP AWS Lambda functions from your Laravel application. Read the full docs at hammerstone.dev/sidecar/docs.

Hammerstone 624 Dec 30, 2022
Laravel blade directives and php helpers for serverside rendered content, based on browser window size WITHOUT css

Laravel Window Size and Breakpoints Laravel blade directives and php helpers for server side rendered content, based on browser window size WITHOUT cs

Tina Hammar 7 Nov 23, 2022
Send PHP errors to Flare

Send PHP errors to Flare This repository contains a PHP client to send PHP errors to Flare. Documentation You can find the documentation of this packa

Spatie 64 Dec 26, 2022