/** * Calls $method on $object with parameters provided in $params variable and getData method(). * * @param $object * @param string $method * @param array $params * * @return mixed */ public static function method($object, $method = '__construct', $params = []) { if (is_string($object) && $method != '__construct') { $object = static::create($object, $params); } try { $reflectionMethod = new ReflectionMethod($object, $method); } catch (ReflectionException $e) { try { $result = call_user_func_array([$object, $method], $params); return $result; } catch (Throwable $e2) { throw $e2; } throw $e; } $params = static::paramsToArray($reflectionMethod->getParameters(), is_array($params) ? $params : [$params]); return measure('Invoking ' . (is_object($object) ? get_class($object) : $object) . '->' . $method, function () use($reflectionMethod, $object, $params) { if ($reflectionMethod->isStatic()) { $reflectionClass = new ReflectionClass(is_object($object) ? get_class($object) : $object); return $reflectionMethod->invokeArgs($reflectionClass, $params); } else { return $reflectionMethod->invokeArgs($object, $params); } }); }
public function fetchPrepared($prepare) { return measure('Fetching prepared', function () use($prepare) { $records = $this->transformRecordsToObjects($prepare->fetchAll()); return $records ? $records[0] : null; }); }
public function autoparse() { self::addDir(path('root'), Twig::PRIORITY_LAST); $this->initTwig($this->file); if ($this->file) { $this->twig = $this->twig->loadTemplate($this->file . ".twig"); } else { $this->twig = $this->twig->createTemplate($this->template); } try { /** * Trigger rendering event so we can attach some handlers. */ trigger(RenderingView::class, ['view' => $this->file]); /** * Render template. */ $render = measure('Rendering ' . $this->file, function () { return $this->twig->render($this->getFullData()); }); if ($render == $this->file . '.twig') { if (prod()) { return null; } return '<p style="color: black; font-weight: bold; background-color: red;">' . 'Cannot load file ' . $this->file . '</p>'; } return $render; } catch (Twig_Error_Syntax $e) { return "<pre>Twig error:" . exception($e) . "</pre>"; } catch (Throwable $e) { return '<pre>' . exception($e) . '</pre>'; } }
public function fetchAllPrepared($prepare) { return measure('Fetching prepared', function () use($prepare) { return $prepare->fetchAll(); }); }