Sha256: d8db01a2ae0447c72f9b4fec3727112ff66bc0c60e95bdd0c29822d321c2eea5

Contents?: true

Size: 1.9 KB

Versions: 10

Compression:

Stored size: 1.9 KB

Contents

<?php

namespace CoffeeScript;

Init::init();

class Helpers {

  /**
   * In some cases it seems to be unavoidable that method parameters conflict
   * with their parent class's. This workaround is used to silence E_STRICT
   * errors.
   *
   * @param $args      `func_get_args()`
   * @param $required  The number of required arguments.
   * @param $optional  An array of defaults for optional arguments.
   */
  static function args(array $args, $required, array $optional = NULL)
  {
    if (count($args) < $required)
    {
      throw new Error("Function requires at least $required arguments.");
    }

    return array_merge($args, (array) $optional);
  }

  static function compact(array $array)
  {
    $compacted = array();

    foreach ($array as $k => $v)
    {
      if ($v)
      {
        $compacted[] = $v;
      }
    }

    return $compacted;
  }

  static function del( & $obj, $key)
  {
    $val = NULL;

    if (isset($obj[$key]))
    {
      $val = $obj[$key];
      unset($obj[$key]);
    }

    return $val;
  }

  static function extend($obj, $properties)
  {
    foreach ($properties as $k => $v)
    {
      $obj->{$k} = $v;
    }

    return $obj;
  }

  static function flatten(array $array)
  {
    $flattened = array();

    foreach ($array as $k => $v)
    {
      if (is_array($v))
      {
        $flattened = array_merge($flattened, flatten($v));
      }
      else
      {
        $flattened[] = $v;
      }
    }

    return $flattened;
  }

  static function & last( & $array, $back = 0)
  {
    static $NULL;

    $i = count($array) - $back - 1;

    if (isset($array[$i]))
    {
      return $array[$i];
    }
    else
    {
      // Make sure $NULL is really NULL.
      $NULL = NULL;

      return $NULL;
    }
  }


  /**
   * Wrap a primitive with an object, so that properties can be attached to it
   * like in JavaScript.
   */
  static function wrap($v)
  {
    return new Value($v);
  }

}

?>

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
guard-mthaml-0.4.0 vendor/coffeescript/coffeescript/src/CoffeeScript/Helpers.php
guard-mthaml-0.3.1 vendor/coffeescript/coffeescript/src/CoffeeScript/Helpers.php
guard-mthaml-0.3.0 vendor/coffeescript/coffeescript/src/CoffeeScript/Helpers.php
guard-mthaml-0.2.5 vendor/coffeescript/coffeescript/src/CoffeeScript/Helpers.php
guard-mthaml-0.2.4 vendor/coffeescript/coffeescript/src/CoffeeScript/Helpers.php
guard-mthaml-0.2.3 vendor/coffeescript/coffeescript/src/CoffeeScript/Helpers.php
guard-mthaml-0.2.2 vendor/coffeescript/coffeescript/src/CoffeeScript/Helpers.php
guard-mthaml-0.2.1 vendor/coffeescript/coffeescript/src/CoffeeScript/Helpers.php
guard-mthaml-0.2.0 vendor/coffeescript/coffeescript/src/CoffeeScript/Helpers.php
guard-mthaml-0.1.0 vendor/coffeescript/coffeescript/src/CoffeeScript/Helpers.php