/** * test string captureing */ public function testCapture() { // callback $this->assertEquals(CCStr::capture(function () { echo "Test"; }), 'Test'); // normal $this->assertEquals(CCStr::capture('Test'), 'Test'); // params $this->assertEquals(CCStr::capture(function ($q) { echo $q; }, 'Test2'), 'Test2'); // params array $this->assertEquals(CCStr::capture(function ($q) { echo $q; }, array('Test2')), 'Test2'); }
/** * generates an closure * * @param string $str * @param int $wordwrap * @return string */ public function closure($name, $content = null, $comment) { return $this->add(($comment ? static::make('comment', array($comment)) . "\n" : '') . $name . "\n{\n" . str_replace("\n", "\n\t", "\t" . CCStr::capture($content)) . "\n}"); }
/** * Create a new from instance * * @param callback $callback * @param string $key The form key used for identification. * @param array $attr The form dom attributes. * @return UI\Form */ public static function capture($callback = null, $key = null, $attr = null) { // we got some dynamics in the parameters here so in case // of this shift stuff if (is_callable($attr) && !is_callable($callback)) { $new_attr = $key; $key = $callback; $callback = $attr; $attr = $new_attr; } $form = new static(); if (is_null($callback)) { throw new Exception('Cannot use capture without a callback or string given.'); } // fix no array given if (!is_array($attr)) { $attr = array(); } return static::start($key, $attr) . \CCStr::capture($callback, array($form)) . static::end(); }
/** * just like capture but it appends * * @param string $key * @param callback $callback * @return void */ public function capture_append($key, $callback) { return $this->set($key, $this->get($key, '') . CCStr::capture($callback, $this)); }