From 47cb7d22dabf517309d0f6506a70303a042a92f2 Mon Sep 17 00:00:00 2001 From: Nuno Chaves Date: Sat, 23 Nov 2019 13:09:25 +0000 Subject: [PATCH] isCallable function added to filter random strings acting like callables --- src/Table/TableColumn.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Table/TableColumn.php b/src/Table/TableColumn.php index 8acc36e..39218a8 100644 --- a/src/Table/TableColumn.php +++ b/src/Table/TableColumn.php @@ -125,7 +125,7 @@ public function renderHeader() return ""; } - if (empty($this->title) && !is_callable($this->value)) { + if (empty($this->title) && !$this->isCallable($this->value)) { if ($this->tableInstance->titlesMode == 'underscore') $this->title = $this->underscoreToTitle($this->value); elseif ($this->tableInstance->titlesMode == 'camelcase') $this->title = $this->camelToTitle($this->value); } @@ -178,7 +178,7 @@ public function renderBody( &$row ) $css = $this->css['td']->render('{prop}:{val}; '); $val = ""; - if (is_callable($this->value)) { + if ($this->isCallable($this->value)) { $val = $this->value; $val = $val($row); } @@ -216,6 +216,15 @@ private function underscoreToTitle($str) return $str; } - - + + + /** + * @param string $var + * @return boolean + */ + private function isCallable($var) + { + return (!is_string($var) && is_callable($var)) || (is_object($var) && $var instanceof \Closure); + } + }