Skip to content

Instantly share code, notes, and snippets.

@imliam
Last active January 15, 2020 14:30
Show Gist options
  • Select an option

  • Save imliam/11940ab73b024140f8e7cd76ef56b0e0 to your computer and use it in GitHub Desktop.

Select an option

Save imliam/11940ab73b024140f8e7cd76ef56b0e0 to your computer and use it in GitHub Desktop.

Revisions

  1. imliam revised this gist Feb 24, 2018. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions take.php
    Original file line number Diff line number Diff line change
    @@ -17,6 +17,11 @@ public function __construct($value)
    $this->id = '__pipe-' . uniqid();
    $GLOBALS[$this->id] = $value;
    }

    public function __destruct()
    {
    unset($GLOBALS[$this->id]);
    }

    public function pipe($value)
    {
  2. imliam created this gist Feb 23, 2018.
    38 changes: 38 additions & 0 deletions take.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    <?php
    if (! function_exists('take')) {
    /**
    * Run functions consecutively by piping through the result of one
    * into the next.
    *
    * @param mixed $value A value
    *
    * @return object
    */
    function take($value)
    {
    return new class($value) {

    public function __construct($value)
    {
    $this->id = '__pipe-' . uniqid();
    $GLOBALS[$this->id] = $value;
    }

    public function pipe($value)
    {
    $GLOBALS[$this->id] = $value;
    return $this;
    }

    public function __get($name)
    {
    if ($name === 'value') {
    return $GLOBALS[$this->id];
    }

    trigger_error("Property '$name' doesn't exist and cannot be gotten", E_USER_ERROR);
    }

    };
    }
    }