public function onResponse(SendResponseEvent $event)
 {
     $response = $event->response;
     $disposition = $response->getHeader('Content-Disposition', NULL);
     if ($disposition === NULL) {
         return;
     }
     $m = NULL;
     if (!preg_match("'((?:^|\\W)filename)\\s*=\\s*\"([^\"]+)\"'i", $disposition, $m)) {
         return;
     }
     $filename = $m[2];
     // Bail out when filename is not UTF-8.
     if (UnicodeString::isUtf8($filename)) {
         return;
     }
     $encodedFilename = rawurlencode($filename);
     $userAgent = $event->request->getHeader('User-Agent', '');
     if (false !== stripos($userAgent, 'MSIE') || preg_match("'Trident\\s*/\\s*7.0'i", $userAgent)) {
         $replacement = $m[1] . '="' . $encodedFilename . '"';
     } elseif (false !== stripos($userAgent, 'Firefox')) {
         $replacement = $m[1] . '*="utf8\'\'' . $encodedFilename . '"';
     } else {
         $replacement = $m[1] . '="' . $filename . '"';
     }
     $response->setHeader('Content-Disposition', str_replace($m[0], $replacement, $disposition));
 }
Ejemplo n.º 2
0
 protected function computeUris()
 {
     $base = ($this->isSecure() ? 'https://' : 'http://') . $this->getHost() . '/';
     $uri = $base;
     $raw = '';
     $ru = NULL;
     if (isset($this->server['HTTP_X_REWRITE_URL'])) {
         $raw = (string) $this->server['HTTP_X_REWRITE_URL'];
         $ru = rawurldecode($raw);
     } elseif (isset($this->server['HTTP_X_ORIGINAL_URL'])) {
         $raw = (string) $this->server['HTTP_X_ORIGINAL_URL'];
         $ru = rawurldecode($raw);
     } elseif (isset($this->server['REQUEST_URI'])) {
         $raw = (string) $this->server['REQUEST_URI'];
         $ru = rawurldecode($raw);
     } elseif (isset($this->server['ORIG_PATH_INFO'])) {
         $raw = (string) $this->server['ORIG_PATH_INFO'];
         $ru = rawurldecode($raw);
         if (!empty($this->server['QUERY_STRING'])) {
             $raw .= '?' . $this->server['QUERY_STRING'];
             $ru .= '?' . $this->server['QUERY_STRING'];
         }
     }
     if ($ru === NULL) {
         throw new \RuntimeException('Could not determine the requested HTTP URI on the server');
     }
     if (!UnicodeString::isUtf8($ru)) {
         $ru = utf8_encode($ru);
     }
     $uri .= ltrim(preg_replace("'/{2,}'", '/', $ru), '/');
     $this->rawRequestUri = $raw;
     $this->requestUri = new Uri($uri);
     if (PHP_SAPI == 'cli-server') {
         // PHP builtin web server does not have a base path.
         $baseParts = [];
     } elseif (array_key_exists('DOCUMENT_ROOT', $this->server)) {
         $root = str_replace('\\', '/', $this->server['DOCUMENT_ROOT']);
         $router = str_replace('\\', '/', dirname(get_included_files()[0]));
         $pre = trim(substr($router, strlen($root)), '/');
         $baseParts = preg_split("'/+'", $pre, -1, PREG_SPLIT_NO_EMPTY);
     } else {
         $pathParts = explode('/', preg_replace("'^https?://[^/]+/?([^\\?#]*).*\$'", '$1', $uri));
         $scriptParts = explode('/', trim(str_replace('\\', '/', array_key_exists('ORIG_SCRIPT_NAME', $this->server) ? $this->server['ORIG_SCRIPT_NAME'] : $this->server['SCRIPT_NAME']), '/'));
         $baseParts = [];
         for ($count = min(count($scriptParts), count($pathParts)), $i = 0; $i < $count; $i++) {
             if (strtolower($pathParts[$i]) == strtolower($scriptParts[$i])) {
                 $baseParts[$i] = $scriptParts[$i];
                 unset($pathParts[$i]);
             }
         }
     }
     $this->baseUri = new Uri($base . implode('/', $baseParts));
 }
Ejemplo n.º 3
0
 protected function syncVariables(Execution $execution, array $syncData)
 {
     $delta = $this->computeVarDelta($execution, $syncData);
     if (!empty($delta[Execution::SYNC_STATE_REMOVED])) {
         $this->conn->delete('#__bpmn_execution_variables', ['execution_id' => $execution->getId(), 'name' => (array) $delta[Execution::SYNC_STATE_REMOVED]]);
     }
     if (!empty($delta[Execution::SYNC_STATE_MODIFIED])) {
         foreach ($delta[Execution::SYNC_STATE_MODIFIED] as $k) {
             $value = NULL;
             if (is_scalar($syncData['variables'][$k])) {
                 $val = $syncData['variables'][$k];
                 if (is_bool($val)) {
                     $val = $val ? '1' : '0';
                 }
                 $value = new UnicodeString(trim($val));
                 if ($value->length() > 250) {
                     $value = $value->substring(0, 250);
                 }
                 $value = $value->toLowerCase();
             }
             $this->conn->insert('#__bpmn_execution_variables', ['execution_id' => $execution->getId(), 'name' => $k, 'value' => $value, 'value_blob' => new BinaryData(serialize($syncData['variables'][$k]))]);
         }
     }
 }