/** * Render the choice from the object. * * @param ModelInterface|ViewableInterface $obj The object or view to render as a label. * @return string */ protected function objPattern($obj) { $pattern = (string) $this->pattern(); if ($obj instanceof ViewableInterface && $obj->view() !== null) { return $obj->renderTemplate($pattern); } else { $cb = function ($matches) use($obj) { $method = trim($matches[1]); if (method_exists($obj, $method)) { return call_user_func([$obj, $method]); } elseif (isset($obj[$method])) { return $obj[$method]; } else { return ''; } }; return preg_replace_callback('~\\{\\{\\s*(.*?)\\s*\\}\\}~i', $cb, $pattern); } }