Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Test {
- public function run() {
- $this->html = new HtmlHelper();
- $this->test = new TestHelper();
- $test = (string)$this->html('main', function() {
- $category = [ 'name' => 'test', 'philosophy' => 'Paragraph about philosophy of working with brands.' ];
- for($i = 0; $i < 50; $i++) {
- yield $this->html('article', function() use($category) {
- yield $this->html('h3', $category['name']);
- yield $this->html('div', $this->html->lower($category['philosophy']));
- yield $this->html('div', $this->test('This is a test'));
- yield $this->test->doThing();
- });
- }
- });
- die($test);
- }
- public function __call($name, $args) {
- $helper = $this->{$name};
- return $helper(...$args);
- }
- }
- class HtmlHelper {
- public function __invoke($name, $content) {
- return '<'.$name.'>'.$this->_renderChild($content).'</'.$name.'>';
- }
- protected function _renderChild($value) {
- if(is_callable($value) && is_object($value)) {
- return $this->_renderChild($value($this));
- }
- if(is_array($value) || $value instanceof \Generator) {
- $output = '';
- foreach($value as $part) {
- $output .= $this->_renderChild($part);
- }
- return $output;
- }
- return (string)$value;
- }
- public function lower($value) {
- return strtolower($value);
- }
- }
- class TestHelper {
- public function __invoke($value) {
- return strtoupper($value);
- }
- public function doThing() {
- return 'other thing';
- }
- }
- (new Test())->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement