Skip to content

Commit d1c80c4

Browse files
committed
BaseControl: added support for extension methods
1 parent 72127b1 commit d1c80c4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Forms/Controls/BaseControl.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,4 +561,25 @@ public function getOptions()
561561
return $this->options;
562562
}
563563

564+
565+
/********************* extension methods ****************d*g**/
566+
567+
568+
public function __call($name, $args)
569+
{
570+
if ($callback = Nette\Utils\ObjectMixin::getExtensionMethod(get_class($this), $name)) {
571+
return Nette\Utils\Callback::invoke($callback, $this, ...$args);
572+
}
573+
return parent::__call($name, $args);
574+
}
575+
576+
577+
public static function extensionMethod($name, $callback = NULL)
578+
{
579+
if (strpos($name, '::') !== FALSE) { // back compatibility
580+
list(, $name) = explode('::', $name);
581+
}
582+
Nette\Utils\ObjectMixin::setExtensionMethod(get_called_class(), $name, $callback);
583+
}
584+
564585
}

0 commit comments

Comments
 (0)