Download the PHP package bdelespierre/underscore without Composer

On this page you can find all versions of the php package bdelespierre/underscore. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package underscore

Build Status

» Table of contents

Underscore.php

PHP lacks consistency, that's a fact. Many functions within a similar field — for instance array functions — may have inconsistent names and prototypes. Underscore.php aims to correct that by providing simple, consistent and data-type tolerant 80-odd functions that support both the usual functional suspects: map, select, invoke — as well as more specialized helpers: function binding, php templating, deep equality testing, and so on.

Underscore.php is strongly inspired by Underscore.js and try to be consistent with it as much as possible (PHP language limitation doesn't allow full coverage — especialy for Functions functions...) Don't hesitate to report any discrepancy with Underscore.js.

Features

Heads up!

This library is in beta phase: you are strongly encouraged to try it and to contribute.Feel free to file an issue if you encounter a bug or an unexpected result.

About data-type tolerance

Juggling with types in PHP can be tedious. Not only types are sometimes ambiguous, they don't fit in every API function/method. For instance, if you want to map every item from an iterator using array_map, you have to translate it into an array first or write the mapping yourself using a loop. Same goes for sort, diff or filter...

PHP is loosely typed, which means that the data you're manipulating are more important than their structure. Underscore.php understands that by providing a comprehensive interface that works with almost every data-type so you don't have to worry about whether you can or cannot use a function/method.

Basically, Underscore.php uses 3 main data-types:

When a fuction requires a Traversable as argument, you can provide either an array, an instance of stdClass — the default (object) casting — an Iterator or anything that implements the Traversable interface, such as a PDOStatement object. With certain functions like #extend, you can even extend an array with an object instance and everything will be fine.

Table of contents

  1. Installation
  2. Usage
  3. Collection Functions
    • size
  4. Uncategorized
    • now
  5. Array Functions
    • range
  6. Function (uh, ahem) Functions
    • apply
  7. Object Functions
    • typeOf
  8. Utility Functions
    • template
  9. Chaining
    • chain
  10. Class Forgery
    • forge

Installation

Composer

Add the following require rule to composer.json and run composer update. See the Packagist repository for more details.

require: { "bdelespierre/underscore": "dev-master" }
With Git
git clone https://github.com/bdelespierre/underscore.php ./underscore.php
Manual
curl -sS https://github.com/bdelespierre/underscore.php/archive/master.zip > underscore.php.zip
unzip underscore.php.zip && rm underscore.zip

Or simply download the zip and extract it where you want.

Usage

Composer
Manual
Functions

Underscore functions can also be used as procedural functions. To do so, include the functions.php library. The only limitation is that you cannot dynamically add new functions with _::mixin.

Collection Functions

each


Description: Iterates over a list of elements, yielding each in turn to an iterator function. The iterator is bound to the context object, if one is passed. Each invocation of iterator is called with three arguments: (element, index, list). If list is an object, iterator's arguments will be (value, key, list).

Parameters
Prototype
_::each(list,iterator,context)
Examples

Collection Functions

eachReference


Alias: walk

Description: Does the very same job as each but provide a reference of every list item to the iterator function.

Parameters
Prototype
_::eachReference(list,iterator,context)
Examples

Collection Functions

map


Alias: collect

Description: Produces a new array of values by mapping each value in list through a transformation function (iterator). The iterator is bound to the context object, if one is passed. Each invocation of iterator is called with three arguments: (element, index, list). If list is an object, iterator's arguments will be (value, key, list).

Parameters
Prototype
_::map(list,iterator,context)
Examples

Collection Functions

reduce


Alias: inject, foldl

Description: Also known as inject and foldl, reduce boils down a list of values into a single value. Memo is the initial state of the reduction, and each successive step of it should be returned by iterator. The iterator is passed four arguments: the memo, then the value and index (or key) of the iteration, and finally a reference to the entire list.

Parameters
Prototype
_::reduce(list,iterator,memo,context)
Examples

Collection Functions

reduceRight


Alias: foldr

Description: The right-associative version of reduce.

Parameters
Prototype
_::reduceRight(list,iterator,memo,context)
Examples

Collection Functions

find


Alias: detect

Description: Looks through each value in the list, returning the first one that passes a truth test (iterator), or null if no value passes the test. The function returns as soon as it finds an acceptable element, and doesn't traverse the entire list.

Parameters
Prototype
_::find(list,iterator,context)
Examples

Collection Functions

filter


Alias: select

Description: Looks through each value in the list, returning an array of all the values that pass a truth test (iterator). If iterator isn't provided, each value will be evaluated as a boolean.

Parameters
Prototype
_::filter(list,iterator,context)
Examples

Collection Functions

where


Description: Looks through each value in the list, returning an array of all the values that contain all of the key-value pairs listed in properties.

Parameters
Prototype
_::where(list,properties)
Examples

Collection Functions

findWhere


Description: Looks through the list and returns the first value that matches all of the key-value pairs listed in properties.

Parameters
Prototype
_::findWhere(list,properties)
Examples

Collection Functions

reject


Description: Returns the values in list without the elements that the truth test (iterator) passes. The opposite of filter.

Parameters
Prototype
_::reject(list,iterator,context)
Examples

Collection Functions

every


Alias: all

Description: Returns true if all of the values in the list pass the iterator truth test. Short-circuits and stops traversing the list if a false element is found.

Parameters
Prototype
_::every(list,iterator,context)
Examples

Collection Functions

some


Alias: any

Description: Returns true if any of the values in the list pass the iterator truth test. Short-circuits and stops traversing the list if a true element is found.

Parameters
Prototype
_::some(list,iterator,context)
Examples

Collection Functions

contains


Alias: includes

Description: Returns true if the value is present in the list.

Parameters
Prototype
_::contains(list,value,strict)
Examples

Collection Functions

invoke


Description: Calls the method named by methodName on each value in the list. Any extra arguments passed to invoke will be forwarded on to the method invocation. If your list items are arrays (instead of objects) methods from ArrayObject can be used (like asort). If the wanted method is not found on the current item during iteration, the item will be left untouched.

Parameters
Prototype
_::invoke(list,methodName,arguments)
Examples

Collection Functions

pluck


Description: A convenient version of what is perhaps the most common use-case for map: extracting a list of property values.

Parameters
Prototype
_::pluck(list,propertyName)
Examples

Collection Functions

max


Description: Returns the maximum value in list. If iterator is passed, it will be used on each value to generate the criterion by which the value is ranked.

Parameters
Prototype
_::max(list,iterator,context)
Examples

Collection Functions

min


Description: Returns the minimum value in list. If iterator is passed, it will be used on each value to generate the criterion by which the value is ranked.

Parameters
Prototype
_::min(list,iterator,context)
Examples

Collection Functions

sortBy


Description: Returns a (stably) sorted copy of list, ranked in ascending order by the results of running each value through iterator. Returns NULL in case of error.

Parameters
Prototype
_::sortBy(list,iterator,context)
Examples

Collection Functions

indexBy


Description: Given a list, and an iterator function that returns a key for each element in the list (or a property name), returns an object with an index of each item. Just like groupBy, but for when you know your keys are unique.

Parameters
Prototype
_::indexBy(list,iterator,context)
Examples

Collection Functions

groupBy


Description: Splits a collection into sets, grouped by the result of running each value through iterator. If iterator is a string instead of a function, groups by the property named by iterator on each of the values.

Parameters
Prototype
_::groupBy(list,iterator,context)
Examples

Collection Functions

countBy


Description: Sorts a list into groups and returns a count for the number of objects in each group. Similar to groupBy, but instead of returning a list of values, returns a count for the number of values in that group.

Parameters
Prototype
_::countBy(list,iterator,context)
Examples

Collection Functions

shuffle


Description: Returns a shuffled copy of the list.

Parameters
Prototype
_::shuffle(list)
Examples

Collection Functions

sample


Description: Produce a random sample from the list. Pass a number to return n random elements from the list. Otherwise a single random item will be returned.

Parameters
Prototype
_::sample(list,n)
Examples

Collection Functions

toArray


Description: Creates a real Array from the list (anything that can be iterated over). This method will also accept scalars such as string, number and even null and will cast them into arrays, for instance Underscore::toArray(null) is [] altough Underscore::toArray('a') is ['a'].

Parameters
Prototype
_::toArray(list)
Examples

Collection Functions

size


Description: Return the number of values in the list. This method will also accept scalars such as string, number and even null or resources but will return 1 in that case.

Parameters
Prototype
_::size(list)
Examples

Collection Functions

Uncategorized

partition


Description: Split a collection into two arrays: one whose elements all satisfy the given predicate, and one whose elements all do not satisfy the predicate.

Parameters
Prototype
_::partition(list,iterator,context)
Examples

Uncategorized

now


Description: Returns an integer timestamp for the current time.

Parameters
Prototype
_::now()

Uncategorized

Array Functions

first


Alias: head, take

Description: Returns the first element of an array. Passing n will return the first n elements of the array. Passing guard will force the returned value to be an array.

Parameters
Prototype
_::first(array,n,guard)

Array Functions

initial


Description: Returns everything but the last entry of the array. Pass n to exclude the last n elements from the result. Passing guard will force the returned value to be an array.

Parameters
Prototype
_::initial(array,n,guard)

Array Functions

last


Description: Returns the last element of an array. Passing n will return the last n elements of the array. Passing guard will force the returned value to be an array.

Parameters
Prototype
_::last(array,n,guard)

Array Functions

rest


Alias: tail, drop

Description: Returns the rest of the elements in an array. Pass an index to return the values of the array from that index onward. Passing guard will force the returned value to be an array.

Parameters
Prototype
_::rest(array,index,guard)

Array Functions

compact


Description: Returns a copy of the array with all falsy values removed. In PHP, false, null, 0, "", array() and "0" are all falsy.

Parameters
Prototype
_::compact(array)

Array Functions

flatten


Description: Flattens a nested array (the nesting can be to any depth). If you pass shallow, the array will only be flattened a single level.

Parameters
Prototype
_::flatten(array,shallow)

Array Functions

without


Description: Returns a copy of the array with all instances of the values removed.

Parameters
Prototype
_::without(array,values)

Array Functions

uniq


Alias: unique

Description: Produces a duplicate-free version of the array, using === to test object equality. If you know in advance that the array is sorted, passing true for isSorted will run a much faster algorithm. If you want to compute unique items based on a transformation, pass an iterator function. WARNING: this function's cyclomatic complexity is (at least) quadratic ! using it with large arrays (> 1000 items) can be very slow and memory consuming.

Parameters
Prototype
_::uniq(array,isSorted,iterator,context)

Array Functions

union


Description: Computes the union of the passed-in arrays: the list of unique items, in order, that are present in one or more of the arrays.

Parameters
Prototype
_::union(array)

Array Functions

intersection


Description: Computes the list of values that are the intersection of all the arrays. Each value in the result is present in each of the arrays.

Parameters
Prototype
_::intersection(array)

Array Functions

difference


Description: Similar to without, but returns the values from array that are not present in the other arrays.

Parameters
Prototype
_::difference(array)

Array Functions

zip


Description: Merges together the values of each of the arrays with the values at the corresponding position. Useful when you have separate data sources that are coordinated through matching array indexes.

Parameters
Prototype
_::zip(array)

Array Functions

obj


Description: 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.

Parameters
Prototype
_::obj(list,values)

Array Functions

indexOf


Description: Returns the index at which value can be found in the array, or -1 if value is not present in the array. This method uses array_search internally and is not optimized for long array binary search.

Parameters
Prototype
_::indexOf(array,item)

Array Functions

lastIndexOf


Description: Returns the index of the last occurrence of value in the array, or -1 if value is not present. This method uses array_keys internally and is not optimized for long array binary search.

Parameters
Prototype
_::lastIndexOf(array,item)

Array Functions

sortedIndex


Description: Uses a binary search to determine the index at which the value should be inserted into the list in order to maintain the list's sorted order. If an iterator is passed, it will be used to compute the sort ranking of each value, including the value you pass. Iterator may also be the string name of the property to sort by (eg. length).

Parameters
Prototype
_::sortedIndex(array,value,iterator,context)

Array Functions

range


Description: A function to create flexibly-numbered lists of integers, handy for each and map loops. start, if omitted, defaults to 0; step defaults to 1. Returns a list of integers from start to stop, incremented (or decremented) by step, exclusive. This method uses range internally.

Parameters
Prototype
_::range(start,stop,step)

Array Functions

Function (uh, ahem) Functions

wrap


Description: Wrap the first function inside of the wrapper function, passing it as the first argument. This allow the wrapper to execute code before and after the function runs, adjust the arguments and execute it conditionnaly. Arguments are passed along to the wrapper function.

Parameters
Prototype
_::wrap(function,wrapper)

Function (uh, ahem) Functions

negate


Description: Returns a new negated version of the predicate function.

Parameters
Prototype
_::negate(function)

Function (uh, ahem) Functions

compose


Description: Returns the composition of a list of functions, where each function consumes the return value of the function that follows. In math terms, composing the functions f(), g(), and h() produces f(g(h())).

Parameters
Prototype
_::compose(functions)

Function (uh, ahem) Functions

after


Description: Creates a version of the function that will only be run after first being called count times. Please note that the function shall not recieve parameters.

Parameters
Prototype
_::after(count,function)

Function (uh, ahem) Functions

before


Description: Creates a version of the function that can be called no more than count times. The result of the last function call is memoized and returned when count has been reached.

Parameters
Prototype
_::before(count,function)

Function (uh, ahem) Functions

once


Description: Creates a version of the function that can only be called one time. Repeated calls to the modified function will have no effect, returning the value from the original call. Useful for initialization functions, instead of having to set a boolean flag and then check it later.

Parameters
Prototype
_::once(function)

Function (uh, ahem) Functions

partial


Description: Partially apply a function by filling in any number of its arguments. Not all the arguments have to be present on the partial construction.

Parameters
Prototype
_::partial(function,arguments)

Function (uh, ahem) Functions

bind


Description: Bind a function to an object, meaning that whenever the function is called, the value of $this will be the object. Optionally, pass arguments to the function to pre-fill them, also known as partial application.

Parameters
Prototype
_::bind(function,object)

Function (uh, ahem) Functions

bindClass


Description: Bind a function to a class, meaning that whenever the function is called, the value of self or static will be the class. Optionally, pass arguments to the function to pre-fill them, also known as partial application.

Parameters
Prototype
_::bindClass(function,class)

Function (uh, ahem) Functions

bindAll


Description: Binds a number of methods on the object, specified by methodNames, to be run in the context of that object whenever they are invoked. Very handy for binding functions that are going to be used as event handlers, which would otherwise be invoked with a fairly useless this. methodNames are required. Keep in mind PHP doesn't allow to call a closure property value like a method, for instance $o->myClosure(), given $o is an instance of stdClass, won't work.

Parameters
Prototype
_::bindAll(object,methodNames)

Function (uh, ahem) Functions

memoize


Description: Memoizes a given function by caching the computed result. Useful for speeding up slow-running computations. If passed an optional hashFunction, it will be used to compute the hash key for storing the result, based on the arguments to the original function. The default hashFunction just uses the first argument to the memoized function as the key.

Parameters
Prototype
_::memoize(function,hashFunction,cache)

Function (uh, ahem) Functions

throttle


Description: Creates and returns a new, throttled version of the passed function, that, when invoked repeatedly, will only actually call the original function at most once per every wait milliseconds. Useful for rate-limiting events that occur faster than you can keep up with.

Parameters
Prototype
_::throttle(function,wait)

Function (uh, ahem) Functions

call


Description: Call (execute) the given function, optionnaly bound to $context, with the given arguments and return its result.

Parameters
Prototype
_::call(function,context)

Function (uh, ahem) Functions

apply


Description: Call (execute) the given function, optionnaly bound to $context, with the given argument list and return its result.

Parameters
Prototype
_::apply(function,context,arguments)

Function (uh, ahem) Functions

Object Functions

keys


Description: Retrieve all the names of the object's properties.

Parameters
Prototype
_::keys(object)

Object Functions

values


Description: Return all of the values of the object's properties.

Parameters
Prototype
_::values(object)

Object Functions

pairs


Description: Convert an object into a list of [key, value] pairs.

Parameters
Prototype
_::pairs(object)

Object Functions

invert


Description: Returns a copy of the object where the keys have become the values and the values the keys. For this to work, all of your object's values should be unique and string serializable.

Parameters
Prototype
_::invert(object)

Object Functions

functions


Alias: methods

Description: Returns a sorted list of the names of every method in an object — that is to say, the name of every function property of the object.

Parameters
Prototype
_::functions(object)

Object Functions

extend


Description: Copy all of the properties in the source objects over to the destination object, and return the destination object. It's in-order, so the last source will override properties of the same name in previous arguments.

Parameters
Prototype
_::extend(destination,sources)

Object Functions

pick


Description: Returns a copy of the object, filtered to only have values for the whitelisted keys (or array of valid keys). If provided object is an object (in the broadest sense), a stdClass instance is returned, otherwise an array is returned.

Parameters
Prototype
_::pick(object,keys)

Object Functions

omit


Description: Return a copy of the object, filtered to omit the blacklisted keys (or array of keys). If provided object is an object (in the broadest sense), a stdClass instance is returned, otherwise an array is returned.

Parameters
Prototype
_::omit(object,keys)

Object Functions

defaults


Description: Fill in null properties in object with values from the defaults objects, and return the object. As soon as the property is filled, further defaults will have no effect.

Parameters
Prototype
_::defaults(object,defaults)

Object Functions

duplicate


Alias: copy

Description: Create a shallow-copied clone of the object. Any nested objects or arrays will be copied by reference, not duplicated. This method is safe to use with arrays.

Parameters
Prototype
_::duplicate(object)

Object Functions

tap


Description: Invokes interceptor with the object, and then returns object. The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.

Parameters
Prototype
_::tap(object,interceptor)

Object Functions

has


Description: Tells whether the object has a non null value for the given key. Gives priority to array's getters ($obj[$key] priorityze on $obj->$key). 'null' is equivalent to 'undefined'.

Parameters
Prototype
_::has(object,key)

Object Functions

property


Description: Returns a function that will itself return the key property of any passed-in object.

Parameters
Prototype
_::property(key)

Object Functions

matches


Description: Returns a predicate function that will tell you if a passed in object contains all of the key/value properties present in properties.

Parameters
Prototype
_::matches(properties)

Object Functions

get


Description: Get the object's key value. If such keys doesn't exists, the default value is returned. If object is neither Array nor an Object, the object itself is returned.

Parameters
Prototype
_::get(object,key,default)

Object Functions

set


Description: Set object's key value. If object is neither Array nor an Object, the object itself is returned.

Parameters
Prototype
_::set(object,key,value)

Object Functions

is


Description: Tells whether the object is of the given type, or class, or pseudo-type. You may pass several types at once (using an array of types or by passing several types as arguments), Underscore::is will return true if object matchs any of these.

Parameters
Prototype
_::is(object,types)

Object Functions

isEqual


Description: Performs an optimized deep comparison between the two objects, to determine if they should be considered equal.

Parameters
Prototype
_::isEqual(object,other)

Object Functions

isEmpty


Description: Returns true if object contains no values (no enumerable own-properties). Works with scalars as well.

Parameters
Prototype
_::isEmpty(object)

Object Functions

isArray


Description: Returns true if object is an array or usable like an array. If the optionnal native parameter is set to true, it will only return true if object is a native array.

Parameters
Prototype
_::isArray(object,native)

Object Functions

isObject


Description: Returns true if value is an Object.

Parameters
Prototype
_::isObject(object)

Object Functions

isFunction


Description: Returns true if object is a Function.

Parameters
Prototype
_::isFunction(object)

Object Functions

isNumber


Alias: isNum, isNumeric

Description: Returns true of object is a Number. If the optionnal native parameter is set to true, it will only return true if object is a native int or float.

Parameters
Prototype
_::isNumber(object,native)

Object Functions

isInteger


Alias: isInt

Description: Returns true if the object is an integer. If the optional native parameter is set to true, it will only return true if object is a native int.

Parameters
Prototype
_::isInteger(object,native)

Object Functions

isFloat


Description: Returns true if the object is a float. If the optional native parameter is set to true, it will only return true if object is a native float.

Parameters
Prototype
_::isFloat(object,native)

Object Functions

isString


Description: Returns true if object is a String. If object is an object with a __toString method, it will be considered as a string as well. If the optionnal native parameter is set to true, it will only return true if object is a native string.

Parameters
Prototype
_::isString(object,native)

Object Functions

isDate


Description: Returns true if object is a DateTime instance. Everything the strtotime function can understand is also considered a date.

Parameters
Prototype
_::isDate(object)

Object Functions

isRegExp


Description: Returns true if object is a valid regular expression (PCRE).

Parameters
Prototype
_::isRegExp(object)

Object Functions

isFinite


Description: Returns true if object is a finite number.

Parameters
Prototype
_::isFinite(object)

Object Functions

isNaN


Description: Returns true if object is NaN (Not a Number).

Parameters
Prototype
_::isNaN(object)

Object Functions

isBoolean


Alias: isBool

Description: Returns true if object is a Boolean. If the optionnal native parameter is set to true, it will only return true if object is a native boolean.

Parameters
Prototype
_::isBoolean(object,native)

Object Functions

isNull


Description: Returns true if object is Null.

Parameters
Prototype
_::isNull(object)

Object Functions

isScalar


Description: Returns true if $object is a scalar. If the optionnal native parameter is set to true, it will only return true if object is a native scalar.

Parameters
Prototype
_::isScalar(object,native)

Object Functions

isTraversable


Description: Returns true if the object can be traversed with a foreach loop.

Parameters
Prototype
_::isTraversable(object)

Object Functions

isResource


Description: Returns true if the object is a resource (like a file handle returned by fopen).

Parameters
Prototype
_::isResource(object)

Object Functions

typeOf


Alias: getType

Description: Gets the class of given object or its native type. This function aggregates most of the is functions and can be seen as a more preceise version of PHP native function gettype. The class parameters lets you know the exact type of the object, if set to false 'object' is returned for objects. Otherwise will return one of the Underscore::TYPE_ constants.

Parameters
Prototype
_::typeOf(object,class)

Object Functions

Utility Functions

identity


Description: Returns the same value that is used as the argument. In math: f(x) = x. This function looks useless, but is used throughout Underscore as a default iterator.

Parameters
Prototype
_::identity(value)

Utility Functions

constant


Description: Creates a function that returns the same value that is used as the argument of _::constant.

Parameters
Prototype
_::constant(value)

Utility Functions

noop


Description: Returns undefined irrespective of the arguments passed to it. Useful as the default for optional callback arguments.

Parameters
Prototype
_::noop()

Utility Functions

times


Description: Invokes the given iterator function n times. Each invocation of iterator is called with an index argument. Produces an array of the returned values.

Parameters
Prototype
_::times(n,iterator,context)

Utility Functions

random


Description: Returns a random integer between min and max, inclusive. If you only pass one argument, it will return a number between 0 and that number.

Parameters
Prototype
_::random(min,max)

Utility Functions

mixin


Description: Allows you to extend Underscore with your own utility functions. Pass a hash of array('name' => function) definitions to have your functions added to the Underscore library, as well as the OOP wrapper.

Parameters
Prototype
_::mixin(functions)

Utility Functions

provide


Description: Returns callable version of any Underscore method (event the user defined ones).

Parameters
Prototype
_::provide(method)

Utility Functions

uniqueId


Description: Generate a pseudo-unique id.

Parameters
Prototype
_::uniqueId(prefix)

Utility Functions

escape


Description: Escapes a string for insertion into HTML, replacing &, <, >, ", ', and / characters.

Parameters
Prototype
_::escape(string)

Utility Functions

unescape


Description: The opposite of escape, replaces &, <, >, ", ', and / with their unescaped counterparts.

Parameters
Prototype
_::unescape(string)

Utility Functions

result


Description: If the value of the named property is a function then invoke it with the object as context; otherwise, return it.

Parameters
Prototype
_::result(object,property)

Utility Functions

lastly


Description: The equivalent of the finally keywork (available since PHP 5.5).

Parameters
Prototype
_::lastly(function,finally,context)

Utility Functions

template


Description: Compiles PHP templates into functions that can be evaluated for rendering. Useful for rendering complicated bits of HTML from JSON data sources. Template functions can both interpolate variables, using <%= ... %>, as well as execute arbitrary PHP code, with <% ... %>. If you wish to interpolate a value, and have it be HTML-escaped, use <%- ... %> When you evaluate a template function, pass in a data object that has properties corresponding to the template's free variables. If you're writing a one-off, you can pass the data object as the second parameter to template in order to render immediately instead of returning a template function. The settings argument should be a hash containing any Underscore::$templateSettings that should be overridden. If ERB-style delimiters aren't your cup of tea, you can change Underscore's template settings to use different symbols to set off interpolated code. Define an interpolate regex to match expressions that should be interpolated verbatim, an escape regex to match expressions that should be inserted after being HTML escaped, and an evaluate regex to match expressions that should be evaluated without insertion into the resulting string. You may define or omit any combination of the three.

Parameters
Prototype
_::template(templateString,data,settings)

Utility Functions

Chaining

chain


Description: Returns a wrapped object. Calling methods on this object will continue to return wrapped objects until value is used. Calling chain will cause all future method calls to return wrapped objects. When you've finished the computation, use value to retrieve the final value.

Parameters
Prototype
_::chain(object)

Chaining

Class Forgery

forge


Alias: strategy

Description: Create new mixins on runtime. The implementation is based on Bob Weinand's idea of Scala traits implementation in PHP (see it here https://gist.github.com/bwoebi/7319798). This method decomposes the $classname to create a new class, using '\with' as a separator for traits.

Parameters
Prototype
_::forge(classname)

Class Forgery


All versions of underscore with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bdelespierre/underscore contains the following files

Loading the files please wait ....