当前位置: 首页>>代码示例>>PHP>>正文


PHP PhabricatorEnv::requireValidRemoteURIForLink方法代码示例

本文整理汇总了PHP中PhabricatorEnv::requireValidRemoteURIForLink方法的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorEnv::requireValidRemoteURIForLink方法的具体用法?PHP PhabricatorEnv::requireValidRemoteURIForLink怎么用?PHP PhabricatorEnv::requireValidRemoteURIForLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PhabricatorEnv的用法示例。


在下文中一共展示了PhabricatorEnv::requireValidRemoteURIForLink方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handleRequest

 public function handleRequest(AphrontRequest $request)
 {
     $show_prototypes = PhabricatorEnv::getEnvConfig('phabricator.show-prototypes');
     if (!$show_prototypes) {
         throw new Exception(pht('Show prototypes is disabled.
       Set `phabricator.show-prototypes` to `true` to use the image proxy'));
     }
     $viewer = $request->getViewer();
     $img_uri = $request->getStr('uri');
     // Validate the URI before doing anything
     PhabricatorEnv::requireValidRemoteURIForLink($img_uri);
     $uri = new PhutilURI($img_uri);
     $proto = $uri->getProtocol();
     if (!in_array($proto, array('http', 'https'))) {
         throw new Exception(pht('The provided image URI must be either http or https'));
     }
     // Check if we already have the specified image URI downloaded
     $cached_request = id(new PhabricatorFileExternalRequest())->loadOneWhere('uriIndex = %s', PhabricatorHash::digestForIndex($img_uri));
     if ($cached_request) {
         return $this->getExternalResponse($cached_request);
     }
     $ttl = PhabricatorTime::getNow() + phutil_units('7 days in seconds');
     $external_request = id(new PhabricatorFileExternalRequest())->setURI($img_uri)->setTTL($ttl);
     $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
     // Cache missed so we'll need to validate and download the image
     try {
         // Rate limit outbound fetches to make this mechanism less useful for
         // scanning networks and ports.
         PhabricatorSystemActionEngine::willTakeAction(array($viewer->getPHID()), new PhabricatorFilesOutboundRequestAction(), 1);
         $file = PhabricatorFile::newFromFileDownload($uri, array('viewPolicy' => PhabricatorPolicies::POLICY_NOONE, 'canCDN' => true));
         if (!$file->isViewableImage()) {
             $mime_type = $file->getMimeType();
             $engine = new PhabricatorDestructionEngine();
             $engine->destroyObject($file);
             $file = null;
             throw new Exception(pht('The URI "%s" does not correspond to a valid image file, got ' . 'a file with MIME type "%s". You must specify the URI of a ' . 'valid image file.', $uri, $mime_type));
         } else {
             $file->save();
         }
         $external_request->setIsSuccessful(true)->setFilePHID($file->getPHID())->save();
         unset($unguarded);
         return $this->getExternalResponse($external_request);
     } catch (HTTPFutureHTTPResponseStatus $status) {
         $external_request->setIsSuccessful(false)->setResponseMessage($status->getMessage())->save();
         return $this->getExternalResponse($external_request);
     } catch (Exception $ex) {
         // Not actually saving the request in this case
         $external_request->setResponseMessage($ex->getMessage());
         return $this->getExternalResponse($external_request);
     }
 }
开发者ID:endlessm,项目名称:phabricator,代码行数:51,代码来源:PhabricatorFileImageProxyController.php

示例2: getExternalParentURI

 public function getExternalParentURI()
 {
     $uri = $this->getParentDomain();
     PhabricatorEnv::requireValidRemoteURIForLink($uri);
     return (string) $uri;
 }
开发者ID:endlessm,项目名称:phabricator,代码行数:6,代码来源:PhameBlog.php

示例3: validateTransaction

 protected function validateTransaction(PhabricatorLiskDAO $object, $type, array $xactions)
 {
     $errors = parent::validateTransaction($object, $type, $xactions);
     switch ($type) {
         case PhameBlogTransaction::TYPE_NAME:
             $missing = $this->validateIsEmptyTextField($object->getName(), $xactions);
             if ($missing) {
                 $error = new PhabricatorApplicationTransactionValidationError($type, pht('Required'), pht('Name is required.'), nonempty(last($xactions), null));
                 $error->setIsMissingFieldError(true);
                 $errors[] = $error;
             }
             break;
         case PhameBlogTransaction::TYPE_PARENTDOMAIN:
             if (!$xactions) {
                 continue;
             }
             $parent_domain = last($xactions)->getNewValue();
             if (empty($parent_domain)) {
                 continue;
             }
             try {
                 PhabricatorEnv::requireValidRemoteURIForLink($parent_domain);
             } catch (Exception $ex) {
                 $error = new PhabricatorApplicationTransactionValidationError($type, pht('Invalid URI'), pht('Parent Domain must be set to a valid Remote URI.'), nonempty(last($xactions), null));
                 $errors[] = $error;
             }
             break;
         case PhameBlogTransaction::TYPE_FULLDOMAIN:
             if (!$xactions) {
                 continue;
             }
             $custom_domain = last($xactions)->getNewValue();
             if (empty($custom_domain)) {
                 continue;
             }
             list($error_label, $error_text) = $object->validateCustomDomain($custom_domain);
             if ($error_label) {
                 $error = new PhabricatorApplicationTransactionValidationError($type, $error_label, $error_text, nonempty(last($xactions), null));
                 $errors[] = $error;
             }
             if ($object->getViewPolicy() != PhabricatorPolicies::POLICY_PUBLIC) {
                 $error_text = pht('For custom domains to work, the blog must have a view policy of ' . 'public.');
                 $error = new PhabricatorApplicationTransactionValidationError(PhabricatorTransactions::TYPE_VIEW_POLICY, pht('Invalid Policy'), $error_text, nonempty(last($xactions), null));
                 $errors[] = $error;
             }
             $domain = new PhutilURI($custom_domain);
             $domain = $domain->getDomain();
             $duplicate_blog = id(new PhameBlogQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withDomain($domain)->executeOne();
             if ($duplicate_blog && $duplicate_blog->getID() != $object->getID()) {
                 $error = new PhabricatorApplicationTransactionValidationError($type, pht('Not Unique'), pht('Domain must be unique; another blog already has this domain.'), nonempty(last($xactions), null));
                 $errors[] = $error;
             }
             break;
     }
     return $errors;
 }
开发者ID:rchicoli,项目名称:phabricator,代码行数:56,代码来源:PhameBlogEditor.php

示例4: assertValidRedirectURI

 /**
  * See http://tools.ietf.org/html/draft-ietf-oauth-v2-23#section-3.1.2
  * for details on what makes a given redirect URI "valid".
  */
 public function assertValidRedirectURI($raw_uri)
 {
     // This covers basics like reasonable formatting and the existence of a
     // protocol.
     PhabricatorEnv::requireValidRemoteURIForLink($raw_uri);
     $uri = new PhutilURI($raw_uri);
     $fragment = $uri->getFragment();
     if (strlen($fragment)) {
         throw new Exception(pht('OAuth application redirect URIs must not contain URI ' . 'fragments, but the URI "%s" has a fragment ("%s").', $raw_uri, $fragment));
     }
     $protocol = $uri->getProtocol();
     switch ($protocol) {
         case 'http':
         case 'https':
             break;
         default:
             throw new Exception(pht('OAuth application redirect URIs must only use the "http" or ' . '"https" protocols, but the URI "%s" uses the "%s" protocol.', $raw_uri, $protocol));
     }
 }
开发者ID:rchicoli,项目名称:phabricator,代码行数:23,代码来源:PhabricatorOAuthServer.php


注:本文中的PhabricatorEnv::requireValidRemoteURIForLink方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。