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/

Issues
  • Add composer.json.

    Add composer.json.

    Add composer.json file so it's easy to use the library with composer tool.

    opened by sobstel 7
  • 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
  • Improved default hash function for memoize()

    Improved default hash function for memoize()

    I've improved the implementation of default hash function in memoize(). It should be able to recognize callbacks from different objects.

    opened by radmen 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
  • '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
  • Fix max empty array

    Fix max empty array

    opened by lorenyu 0
  • Function create_function() is deprecated

    Function create_function() is deprecated

    Function create_function() is deprecated on line 939. Please help me! Thanks!

    opened by nopita37 0
  • Implementation PSR2 and syntax php array

    Implementation PSR2 and syntax php array

    opened by AlefeVariani 0
  • String helpers support

    String helpers support

    Are you plan to add string helpers like https://github.com/epeli/underscore.string ?

    opened by undercloud 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
  • Reject can use associative array

    Reject can use associative array

    You can use this syntax to reject a key/value from an associative array.

    __::reject($params, function($k,$v) { return in_array($k,array("test")); });

    opened by kpitn 0
  • I write a function

    I write a function "object" Converts arrays into objects

    I write this and share with you. Thanks a lot for your work Converts arrays into objects /**

    • Converts arrays into objects. Pass either a single list of [key, value] pairs,

    • or a list of keys, and a list of values. If duplicate keys exist, the last value wins. */ public function object($list=null, $values=null) { if(is_null($list)) return self::_wrap(array()); $return = array(); foreach($list as $k=>$v) { if($values){
      $return[$v] = $values[$k] ; } else{ $return[[$k][0]] = $values[$k][1]; } }

      return self::_wrap($return); }

    opened by thinkink 0
  • undercake.php

    undercake.php

    This is a small adaptation of Underscore.php v1.3.1 for CakePHP.

    As __() is already used by CakePHP for internationalization, the class, function and internal variables were changed to _uc, _uc(), $_uc.

    This is my only contribution so far, but it gets the job done!

    I will try to make a component out of this at a later time.

    USAGE EX: _uc( $myVar )->map(function($n) { return $n * 2; });

    Note: The __::map($myVar, function($n) { return $n * 2; }); method does not work.

    For extended documentation, see the Underscore.php page at http://brianhaveri.github.io/Underscore.php

    To use in CakePHP

    1. Copy undercake.php to your app/vendors folder
    2. Include App::import('Vendor', 'undercake'); right before class AppController extends Controller { in your app_controller.php file
    3. Use the marvels of Underscore.php like this: _uc( $myVar )->map(function($n) { return $n * 2; });
    opened by balaianu 0
Owner
Brian Haveri
Director of Engineering @ TrainHeroic. We build software that helps coaches and athletes be their best. We're hiring.
Brian Haveri
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 53 Dec 27, 2021
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 66 Jan 19, 2022
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 74 Mar 3, 2021
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 4 Dec 29, 2021
PHP phonebook with map (Active Directory, LDAP -> MySQL, PHP)

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

null 43 Dec 27, 2021
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 608 Jan 9, 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 404 Jan 4, 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 10 Jan 2, 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 3 Apr 23, 2021
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 5 Oct 21, 2021
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 229 Jan 13, 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 6 Jun 11, 2021
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 16 Dec 29, 2021
Winbox.js wrapper in PHP.

Winbox PHP A wrapper for using Winbox.js just coding in PHP. Based on: JS Repo - https://github.com/nextapps-de/winbox Installation Clone the repo or

null 9 Sep 7, 2021
Control frontend access to properties/methods in Livewire using PHP 8 attributes.

This package adds PHP 8.0 attribute support to Livewire. In specific, the attributes are used for flagging component properties and methods as frontend-accessible.

ARCHTECH 55 Nov 23, 2021
Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Jameson Lopp 12 Nov 16, 2021
Evo is a Laravel package that leverages PHP 8 features.

Evo is a Laravel package that leverages PHP 8 features. It change the way you write Laravel app into something like this: #[RoutePrefix('users')] clas

Muhammad Syifa 13 Nov 30, 2021