示例#1
0
 /**
  * @param DispatchEvent $event
  */
 public function processEvent(DispatchEvent $event)
 {
     //Generate the URI and return it in the event
     $uri = $this->generateUriPath($event->getMapType(), $event->getLookupParts(), $this->_httpHost, $event->getPath(), $event->getFilename());
     //Invalid resource requested
     if ($uri === null) {
         $event->setResult(null);
         return;
     }
     $cfg = $this->_dispatcher->getConfig();
     switch ($cfg->getItem('run_on', 'path')) {
         case 'path':
             // asset urls are determined by path prefix
             $path = $cfg->getItem('run_match', 'res');
             $uri = Path::buildUnix($this->_httpHost, $path, $uri);
             break;
         case 'subdomain':
             // asset urls are determined by domain prefix
             $sub = $cfg->getItem('run_match', 'static.');
             $domainP = explode('.', $this->_httpHost);
             if (count($domainP) > 2) {
                 $domain = implode('.', array_slice($domainP, 1));
             } else {
                 $domain = implode('.', $domainP);
             }
             $uri = Path::buildUnix($sub . $domain, $uri);
             break;
         case 'domain':
             // asset urls are determined by FQDN
             $domain = $cfg->getItem('run_match', $this->_httpHost);
             $uri = Path::buildUnix($domain, $uri);
             break;
     }
     $event->setResult('//' . $uri);
 }
示例#2
0
 /**
  * @param ApiPayloadInterface $payload
  * @param null                $path
  * @param null                $verb
  *
  * @return ApiRequest
  */
 protected function _createRequest(ApiPayloadInterface $payload = null, $path = null, $verb = null)
 {
     if ($path === null) {
         $path = $this->_path;
     } else {
         if (substr($path, 0, 1) !== '/') {
             $path = Path::buildUnix($this->_path, $path);
         }
     }
     $path = $this->_buildPath($path, $payload);
     if ($payload === null) {
         $request = ApiRequest::create($verb ? $verb : HttpVerb::GET, $path);
     } else {
         if ($verb === HttpVerb::GET) {
             $request = ApiRequest::create(HttpVerb::GET, $path, [], $payload->toArray());
         } else {
             $request = ApiRequest::create($verb ?: HttpVerb::POST, $path, $payload->toArray());
         }
     }
     $request->setApi($this->getApi());
     return $request;
 }
示例#3
0
 public static function fromFid($org, $fid, $size = 30)
 {
     return Path::buildUnix('https://storage.googleapis.com/cdn.fortifi.co', $org, 'avatar', $fid . $size . '.png');
 }
示例#4
0
 /**
  * @param ApiRequestInterface $request
  *
  * @return \GuzzleHttp\Message\RequestInterface
  */
 protected function _createRequest(ApiRequestInterface $request)
 {
     return $this->_getClient()->createRequest($request->getVerb(), Path::buildUnix($this->getUrl(), $request->getPath()) . $request->getQueryString(), $this->_makeOptions($request));
 }
 /**
  * Dispatch a nested URL
  *
  * @param $uri
  *
  * @return string
  */
 protected function _dispatchNestedUrl($uri)
 {
     // if url path is empty, return unchanged
     if (empty($uri[1])) {
         return $uri[0];
     }
     $prefix = '';
     list($path, $append) = Strings::explode('?', $uri[1], [$uri[1], null], 2);
     //Take a root link as it comes
     if (!Strings::startsWith($path, '/')) {
         $relPath = $this->_assetManager->getRelativePath();
         if (Strings::startsWith($path, '../')) {
             $max = count($relPath);
             $depth = substr_count($path, '../');
             $path = substr($path, $depth * 3);
             if ($depth > 0 && $depth < $max) {
                 $rel = array_slice($relPath, 0, $depth);
                 $prefix = implode('/', $rel);
             }
         } else {
             $prefix = implode('/', $relPath);
         }
     }
     $path = ltrim($path, '/');
     $url = $this->_assetManager->getResourceUri(Path::buildUnix($prefix, $path));
     if (empty($url)) {
         return $uri[0];
     }
     if (!empty($append)) {
         return "url('{$url}?{$append}')";
     }
     return "url('{$url}')";
 }
示例#6
0
 /**
  * Execute a route and attempt to generate a response
  *
  * @param IRoute  $route
  * @param Request $request
  * @param int     $type
  * @param bool    $catch
  *
  * @return CubexResponse|null|Response
  * @throws \Exception
  */
 public function executeRoute(IRoute $route, Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     $value = $route->getValue();
     $this->_processParams = $params = $route->getRouteData();
     //If the action has returned a valid response, lets send that back
     if ($value instanceof Response) {
         return $value;
     }
     //Attempt to see if the route is a callable
     if (is_callable($value)) {
         $value = $this->_getCallableResult($value, $params);
     } else {
         if (is_scalar($value)) {
             //If is fully qualified class, create class
             $match = '/^(\\\\?[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)+$/';
             if (stripos($value, '\\') !== false && preg_match($match, $value)) {
                 $class = $value;
                 $nsClass = Path::buildWindows(Objects::getNamespace($this), $value);
                 try {
                     if (class_exists($nsClass)) {
                         $value = $this->getCubex()->make($nsClass);
                     } else {
                         $value = $this->getCubex()->make($class);
                     }
                 } catch (\Exception $e) {
                     if (!$catch) {
                         throw new \RuntimeException("Your route provides an invalid class '{$class}'");
                     } else {
                         return null;
                     }
                 }
             } else {
                 $call = $this->attemptCallable($value);
                 if ($call !== null) {
                     $value = $this->_getCallableResult($call, $params);
                 } else {
                     //Attempt to see if the route is a redirect
                     $url = $this->attemptUrl($value, $request);
                     if ($url !== null) {
                         //Redirect to url
                         return new RedirectResponse($url['url'], $url['code']);
                     } else {
                         //look for method names
                         $method = $this->attemptMethod($value, $request);
                         if ($method !== null) {
                             $value = $this->_getCallableResult([$this, $method], $params);
                         }
                     }
                 }
             }
         }
     }
     if ($value instanceof CubexKernel) {
         $value->_pathProcessed = Path::buildUnix($this->_pathProcessed, $route->getMatchedPath());
         $value->_processParams = $params;
     }
     return $this->_processResponse($value, $request, $type, $catch, $params);
 }
示例#7
0
 public function testBuildUnixPath()
 {
     $this->assertEquals("a/b", Path::buildUnix("a", "b"));
 }
示例#8
0
 protected function _buildUrl($path)
 {
     if ($this->_baseUrl === null) {
         $schemas = $this->_definition->getSchemas();
         rsort($schemas);
         $this->_baseUrl = reset($schemas) . '://';
         $this->_baseUrl .= $this->_definition->getHost();
         $this->_baseUrl .= '/' . ltrim($this->_definition->getBasePath(), '/');
     }
     return Path::buildUnix($this->_baseUrl, $path);
 }
示例#9
0
 /**
  * @param AccessToken $token
  *
  * @return string
  */
 public function urlLogout(AccessToken $token)
 {
     return Path::buildUnix($this->_url, 'auth', 'logout') . '?access_token=' . $token->accessToken;
 }