src/endobox/Box.php
public function assign(array $data) : Box
    {
        // Allow passing closures as data.
        // The trick is to wrap the closure in an anonymous class instance that takes the closure and calls it
        // when it is invoked as a string or as a function.
        // We only support real closures (i.e., instance of Closure), not just any callable,
        // because there is no way to know if "time" is supposed to be data or a function name.
        foreach ($data as $k => &$v) {
            if ($v instanceof \Closure) {
                $data[$k] = new class($v) {
                    private $closure;
                    public function __construct($c) { $this->closure = $c; }
                    public function __toString() { return \call_user_func($this->closure); }
                    public function __invoke(...$args) { return \call_user_func_array($this->closure, $args); }
                };
            }
        }

        $this->data = \array_merge($this->data, $data);

        return $this;
    }
public function assign(array $data) : Box
    {
        // Allow passing closures as data.
        // The trick is to wrap the closure in an anonymous class instance that takes the closure and calls it
        // when it is invoked as a string or as a function.
        // We only support real closures (i.e., instance of Closure), not just any callable,
        // because there is no way to know if "time" is supposed to be data or a function name.
        foreach ($data as $k => &$v) {
            if ($v instanceof \Closure) {
                $data[$k] = new class($v) {
                    private $closure;
                    public function __construct($c) { $this->closure = $c; }
                    public function __toString() { return \call_user_func($this->closure); }
                    public function __invoke(...$args) { return \call_user_func_array($this->closure, $args); }
                };
            }
        }

        $this->data = \array_merge($this->data, $data);

        return $this;
    }
public function assign ( array $ data ) : Box { // Allow passing closures as data. // The trick is to wrap the closure in an anonymous class instance that takes the closure and calls it // when it is invoked as a string or as a function. // We only support real closures (i.e., instance of Closure), not just any callable, // because there is no way to know if "time" is supposed to be data or a function name. foreach ( $ data as $ k => & $ v ) { if ( $ v instanceof \ Closure ) { $ data [ $ k ] = new class ( $ v ) { private $ closure ; public function __construct ( $ c ) { $ this -> closure = $ c ; } public function __toString ( ) { return \ call_user_func ( $ this -> closure ) ; } public function __invoke ( ... $ args ) { return \ call_user_func_array ( $ this -> closure , $ args ) ; } } ; } } $ this -> data = \ array_merge ( $ this -> data , $ data ) ; return $ this ; }
Assign some data to this Box.
Assign some data to this Box .