Exemplo n.º 1
0
 /**
  * @param string $destination
  *
  * @return object
  */
 public function cast(string $destination)
 {
     if (!is_subclass_of($destination, get_class($this))) {
         throw new \InvalidArgumentException(sprintf('%s is not a descendant of $object class: %s.', $destination, get_class($this)));
     }
     $data = Serializer::serialize($this);
     $data['@type'] = $destination;
     $reflection = new \ReflectionClass($destination);
     $return = $reflection->newInstanceWithoutConstructor();
     Serializer::unserialize($return, $data);
     return $return;
 }
Exemplo n.º 2
0
 /**
  *
  */
 protected function generateData()
 {
     $this->data['id'] = $this->id;
     $start = self::request()->getServer('REQUEST_TIME_FLOAT');
     $end = microtime(true);
     $this->data['time'] = $start;
     $this->data['method'] = self::request()->getMethod();
     $this->data['uri'] = (string) self::request()->getUri()->get(false);
     if (self::router()->current()) {
         $this->data['controller'] = $this->getControllerName(self::router()->current()->getController());
     }
     $this->data['memory'] = memory_get_peak_usage(true);
     // request data
     foreach (self::request()->getCookies() as $cookie) {
         $this->data['request']['cookies'][$cookie->getName()] = $cookie->getValue();
     }
     $this->data['request']['requestHeaders'] = self::request()->getHeaders();
     $this->data['request']['responseHeaders'] = self::response()->getHeaders();
     $this->data['request']['get'] = self::request()->getUri()->getQueries() ?? [];
     $this->data['request']['post'] = self::request()->getPosts() ?? [];
     $this->data['request']['files'] = self::request()->getUploadedFiles() ?? [];
     $this->data['request']['server'] = self::request()->getServers() ?? [];
     // session data
     if (self::session()->isStarted()) {
         $session = self::session()->getData();
         foreach ($session as $key => $value) {
             if (is_object($value)) {
                 $session[$key] = Serializer::serialize($value);
             }
         }
         $this->data['request']['session'] = $session;
         unset($this->data['request']['session']['clockwork']);
     }
     foreach ($this->data['request'] as $type => $data) {
         if (!$data) {
             unset($this->data['request'][$type]);
         }
     }
     // duration
     $this->data['responseTime'] = $end;
     $this->data['responseStatus'] = self::response()->getStatus();
     $this->data['responseDuration'] = ($end - $start) * 1000;
     $this->data['timelineData'] = $this->data['timelineData'] ?? [];
     $this->data['timelineData'] = array_merge(['Total execution time' => [['start' => $start, 'end' => $end, 'duration' => ($end - $start) * 1000]]], $this->data['timelineData']);
 }