<?php
class Button
{
public $data = []; //public только для теста
public function build($method)
{
$method($this); // Передаем в колбэк $this (object Button)
}
$this->data['buttons'] = $method;
}
}
public function addButton
(array $button = []) {
$this->data['buttons'] = $button;
return $this;
}
}
$button = new Button;
$button->build(function ($button) {
/** @var Button $button */
$button->addButton(['a' => 'b']);
});
PD9waHAKCmNsYXNzIEJ1dHRvbgp7CiAgIHB1YmxpYyAkZGF0YSA9IFtdOyAvL3B1YmxpYyDRgtC+0LvRjNC60L4g0LTQu9GPINGC0LXRgdGC0LAKCiAgIHB1YmxpYyBmdW5jdGlvbiBidWlsZCgkbWV0aG9kKQogICB7CiAgICAgICBpZihpc19jYWxsYWJsZSgkbWV0aG9kKSkgewogICAgICAgICAgICRtZXRob2QoJHRoaXMpOyAvLyDQn9C10YDQtdC00LDQtdC8INCyINC60L7Qu9Cx0Y3QuiAkdGhpcyAob2JqZWN0IEJ1dHRvbikKICAgICAgIH0KCiAgICAgICBpZihpc19hcnJheSgkbWV0aG9kKSkgewogICAgICAgICAgICAkdGhpcy0+ZGF0YVsnYnV0dG9ucyddID0gJG1ldGhvZDsKICAgICAgICB9CiAgIH0KCiAgICBwdWJsaWMgZnVuY3Rpb24gYWRkQnV0dG9uKGFycmF5ICRidXR0b24gPSBbXSkKICAgIHsKICAgICAgICAkdGhpcy0+ZGF0YVsnYnV0dG9ucyddID0gJGJ1dHRvbjsKCiAgICAgICAgcmV0dXJuICR0aGlzOwogICAgfQp9CgokYnV0dG9uID0gbmV3IEJ1dHRvbjsKCiRidXR0b24tPmJ1aWxkKGZ1bmN0aW9uICgkYnV0dG9uKSB7CiAgICAvKiogQHZhciBCdXR0b24gJGJ1dHRvbiAqLwogICAgJGJ1dHRvbi0+YWRkQnV0dG9uKFsnYScgPT4gJ2InXSk7Cn0pOwoKcHJpbnRfcigkYnV0dG9uLT5kYXRhWydidXR0b25zJ10pOwo=