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


PHP PhutilURI::getProtocol方法代码示例

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


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

示例1: didValidateOption

 protected function didValidateOption(PhabricatorConfigOption $option, $value)
 {
     $key = $option->getKey();
     if ($key == 'phabricator.base-uri' || $key == 'phabricator.production-uri') {
         $uri = new PhutilURI($value);
         $protocol = $uri->getProtocol();
         if ($protocol !== 'http' && $protocol !== 'https') {
             throw new PhabricatorConfigValidationException(pht("Config option '%s' is invalid. The URI must start with " . "%s' or '%s'.", 'http://', 'https://', $key));
         }
         $domain = $uri->getDomain();
         if (strpos($domain, '.') === false) {
             throw new PhabricatorConfigValidationException(pht("Config option '%s' is invalid. The URI must contain a dot " . "('%s'), like '%s', not just a bare name like '%s'. Some web " . "browsers will not set cookies on domains with no TLD.", '.', 'http://example.com/', 'http://example/', $key));
         }
         $path = $uri->getPath();
         if ($path !== '' && $path !== '/') {
             throw new PhabricatorConfigValidationException(pht("Config option '%s' is invalid. The URI must NOT have a path, " . "e.g. '%s' is OK, but '%s' is not. Phabricator must be installed " . "on an entire domain; it can not be installed on a path.", $key, 'http://phabricator.example.com/', 'http://example.com/phabricator/'));
         }
     }
     if ($key === 'phabricator.timezone') {
         $old = date_default_timezone_get();
         $ok = @date_default_timezone_set($value);
         @date_default_timezone_set($old);
         if (!$ok) {
             throw new PhabricatorConfigValidationException(pht("Config option '%s' is invalid. The timezone identifier must " . "be a valid timezone identifier recognized by PHP, like '%s'. " . "\n            You can find a list of valid identifiers here: %s", $key, 'America/Los_Angeles', 'http://php.net/manual/timezones.php'));
         }
     }
 }
开发者ID:patelhardik,项目名称:phabricator,代码行数:27,代码来源:PhabricatorCoreConfigOptions.php

示例2: validateCustomDomain

 /**
  * Makes sure a given custom blog uri is properly configured in DNS
  * to point at this Phabricator instance. If there is an error in
  * the configuration, return a string describing the error and how
  * to fix it. If there is no error, return an empty string.
  *
  * @return string
  */
 public function validateCustomDomain($custom_domain)
 {
     $example_domain = 'blog.example.com';
     $label = pht('Invalid');
     // note this "uri" should be pretty busted given the desired input
     // so just use it to test if there's a protocol specified
     $uri = new PhutilURI($custom_domain);
     if ($uri->getProtocol()) {
         return array($label, pht('The custom domain should not include a protocol. Just provide ' . 'the bare domain name (for example, "%s").', $example_domain));
     }
     if ($uri->getPort()) {
         return array($label, pht('The custom domain should not include a port number. Just provide ' . 'the bare domain name (for example, "%s").', $example_domain));
     }
     if (strpos($custom_domain, '/') !== false) {
         return array($label, pht('The custom domain should not specify a path (hosting a Phame ' . 'blog at a path is currently not supported). Instead, just provide ' . 'the bare domain name (for example, "%s").', $example_domain));
     }
     if (strpos($custom_domain, '.') === false) {
         return array($label, pht('The custom domain should contain at least one dot (.) because ' . 'some browsers fail to set cookies on domains without a dot. ' . 'Instead, use a normal looking domain name like "%s".', $example_domain));
     }
     if (!PhabricatorEnv::getEnvConfig('policy.allow-public')) {
         $href = PhabricatorEnv::getProductionURI('/config/edit/policy.allow-public/');
         return array(pht('Fix Configuration'), pht('For custom domains to work, this Phabricator instance must be ' . 'configured to allow the public access policy. Configure this ' . 'setting %s, or ask an administrator to configure this setting. ' . 'The domain can be specified later once this setting has been ' . 'changed.', phutil_tag('a', array('href' => $href), pht('here'))));
     }
     return null;
 }
开发者ID:fengshao0907,项目名称:phabricator,代码行数:33,代码来源:PhameBlog.php

示例3: renderInput

 protected function renderInput()
 {
     self::requireLib();
     $uri = new PhutilURI(PhabricatorEnv::getEnvConfig('phabricator.base-uri'));
     $protocol = $uri->getProtocol();
     $use_ssl = $protocol == 'https';
     return phutil_safe_html(recaptcha_get_html(PhabricatorEnv::getEnvConfig('recaptcha.public-key'), $error = null, $use_ssl));
 }
开发者ID:pugong,项目名称:phabricator,代码行数:8,代码来源:AphrontFormRecaptchaControl.php

示例4: getProviderConfigurationHelp

 protected function getProviderConfigurationHelp()
 {
     $login_uri = PhabricatorEnv::getURI($this->getLoginURI());
     $uri = new PhutilURI(PhabricatorEnv::getProductionURI('/'));
     $https_note = null;
     if ($uri->getProtocol() !== 'https') {
         $https_note = pht('NOTE: Amazon **requires** HTTPS, but your Phabricator install does ' . 'not use HTTPS. **You will not be able to add Amazon as an ' . 'authentication provider until you configure HTTPS on this install**.');
     }
     return pht("%s\n\n" . "To configure Amazon OAuth, create a new 'API Project' here:" . "\n\n" . "http://login.amazon.com/manageApps" . "\n\n" . "Use these settings:" . "\n\n" . "  - **Allowed Return URLs:** Add this: `%s`" . "\n\n" . "After completing configuration, copy the **Client ID** and " . "**Client Secret** to the fields above.", $https_note, $login_uri);
 }
开发者ID:pugong,项目名称:phabricator,代码行数:10,代码来源:PhabricatorAmazonAuthProvider.php

示例5: validateURI

 private function validateURI($raw_uri)
 {
     $uri = new PhutilURI($raw_uri);
     $protocol = $uri->getProtocol();
     if (!strlen($protocol)) {
         throw new Exception(pht('Unable to identify the protocol for URI "%s". URIs must be ' . 'fully qualified and have an identifiable protocol.', $raw_uri));
     }
     $protocol_key = 'uri.allowed-protocols';
     $protocols = PhabricatorEnv::getEnvConfig($protocol_key);
     if (empty($protocols[$protocol])) {
         throw new Exception(pht('URI "%s" does not have an allowable protocol. Configure ' . 'protocols in `%s`. Allowed protocols are: %s.', $raw_uri, $protocol_key, implode(', ', array_keys($protocols))));
     }
 }
开发者ID:NeoArmageddon,项目名称:phabricator,代码行数:13,代码来源:HarbormasterURIArtifact.php

示例6: 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

示例7: getPath

 /**
  * @task normal
  */
 public function getPath()
 {
     switch ($this->type) {
         case self::TYPE_GIT:
             $uri = new PhutilURI($this->uri);
             return $uri->getPath();
         case self::TYPE_SVN:
         case self::TYPE_MERCURIAL:
             $uri = new PhutilURI($this->uri);
             if ($uri->getProtocol()) {
                 return $uri->getPath();
             }
             return $this->uri;
     }
 }
开发者ID:rchicoli,项目名称:phabricator,代码行数:18,代码来源:PhabricatorRepositoryURINormalizer.php

示例8: hasAllowedProtocol

 public static function hasAllowedProtocol($uri)
 {
     $uri = new PhutilURI($uri);
     $editor_protocol = $uri->getProtocol();
     if (!$editor_protocol) {
         // The URI must have a protocol.
         return false;
     }
     $allowed_key = 'uri.allowed-editor-protocols';
     $allowed_protocols = PhabricatorEnv::getEnvConfig($allowed_key);
     if (empty($allowed_protocols[$editor_protocol])) {
         // The protocol must be on the allowed protocol whitelist.
         return false;
     }
     return true;
 }
开发者ID:rchicoli,项目名称:phabricator,代码行数:16,代码来源:PhabricatorHelpEditorProtocolController.php

示例9: validateCustomDomain

 /**
  * Makes sure a given custom blog uri is properly configured in DNS
  * to point at this Phabricator instance. If there is an error in
  * the configuration, return a string describing the error and how
  * to fix it. If there is no error, return an empty string.
  *
  * @return string
  */
 public function validateCustomDomain($custom_domain)
 {
     $example_domain = '(e.g. blog.example.com)';
     $valid = '';
     // note this "uri" should be pretty busted given the desired input
     // so just use it to test if there's a protocol specified
     $uri = new PhutilURI($custom_domain);
     if ($uri->getProtocol()) {
         return 'Do not specify a protocol, just the domain. ' . $example_domain;
     }
     if (strpos($custom_domain, '/') !== false) {
         return 'Do not specify a path, just the domain. ' . $example_domain;
     }
     if (strpos($custom_domain, '.') === false) {
         return 'Custom domain must contain at least one dot (.) because ' . 'some browsers fail to set cookies on domains such as ' . 'http://example. ' . $example_domain;
     }
     return $valid;
 }
开发者ID:rudimk,项目名称:phabricator,代码行数:26,代码来源:PhameBlog.php

示例10: didValidateOption

 protected function didValidateOption(PhabricatorConfigOption $option, $value)
 {
     $key = $option->getKey();
     if ($key == 'security.alternate-file-domain') {
         $uri = new PhutilURI($value);
         $protocol = $uri->getProtocol();
         if ($protocol !== 'http' && $protocol !== 'https') {
             throw new PhabricatorConfigValidationException(pht("Config option '%s' is invalid. The URI must start with " . "'%s' or '%s'.", $key, 'http://', 'https://'));
         }
         $domain = $uri->getDomain();
         if (strpos($domain, '.') === false) {
             throw new PhabricatorConfigValidationException(pht("Config option '%s' is invalid. The URI must contain a dot ('.'), " . "like '%s', not just a bare name like '%s'. " . "Some web browsers will not set cookies on domains with no TLD.", $key, 'http://example.com/', 'http://example/'));
         }
         $path = $uri->getPath();
         if ($path !== '' && $path !== '/') {
             throw new PhabricatorConfigValidationException(pht("Config option '%s' is invalid. The URI must NOT have a path, " . "e.g. '%s' is OK, but '%s' is not. Phabricator must be installed " . "on an entire domain; it can not be installed on a path.", $key, 'http://phabricator.example.com/', 'http://example.com/phabricator/'));
         }
     }
 }
开发者ID:rchicoli,项目名称:phabricator,代码行数:19,代码来源:PhabricatorSecurityConfigOptions.php

示例11: processEditForm

 public function processEditForm(AphrontRequest $request, array $values)
 {
     $errors = array();
     $issues = array();
     $is_setup = $this->isSetup();
     $key_name = self::PROPERTY_MEDIAWIKI_NAME;
     $key_uri = self::PROPERTY_MEDIAWIKI_URI;
     $key_secret = self::PROPERTY_CONSUMER_SECRET;
     $key_consumer = self::PROPERTY_CONSUMER_KEY;
     if (!strlen($values[$key_uri])) {
         $errors[] = pht('MediaWiki base URI is required.');
         $issues[$key_uri] = pht('Required');
     } else {
         $uri = new PhutilURI($values[$key_uri]);
         if (!$uri->getProtocol()) {
             $errors[] = pht('MediaWiki base URI should include protocol ' . '(like "https://").');
             $issues[$key_uri] = pht('Invalid');
         }
     }
     if (!$is_setup && !strlen($values[$key_secret])) {
         $errors[] = pht('Consumer Secret is required');
         $issues[$key_secret] = pht('Required');
     }
     if (!$is_setup && !strlen($values[$key_consumer])) {
         $errors[] = pht('Consumer Key is required');
         $issues[$key_consumer] = pht('Required');
     }
     if (!count($errors)) {
         $config = $this->getProviderConfig();
         $config->setProviderDomain($values[$key_name]);
         $config->setProperty($key_name, $values[$key_name]);
         if ($is_setup) {
             $config->setProperty($key_uri, $values[$key_uri]);
         } else {
             $config->setProperty($key_uri, $values[$key_uri]);
             $config->setProperty($key_secret, $values[$key_secret]);
             $config->setProperty($key_consumer, $values[$key_consumer]);
         }
         $config->save();
     }
     return array($errors, $issues, $values);
 }
开发者ID:YJSoft,项目名称:phabricator-extensions,代码行数:42,代码来源:PhabricatorMediaWikiAuthProvider.php

示例12: testURIParsing

 public function testURIParsing()
 {
     $uri = new PhutilURI('http://user:pass@host:99/path/?query=value#fragment');
     $this->assertEqual('http', $uri->getProtocol(), 'protocol');
     $this->assertEqual('user', $uri->getUser(), 'user');
     $this->assertEqual('pass', $uri->getPass(), 'pass');
     $this->assertEqual('host', $uri->getDomain(), 'domain');
     $this->assertEqual('99', $uri->getPort(), 'port');
     $this->assertEqual('/path/', $uri->getPath(), 'path');
     $this->assertEqual(array('query' => 'value'), $uri->getQueryParams(), 'query params');
     $this->assertEqual('fragment', $uri->getFragment(), 'fragment');
     $this->assertEqual('http://user:pass@host:99/path/?query=value#fragment', (string) $uri, 'uri');
     $uri = new PhutilURI('ssh://git@example.com/example/example.git');
     $this->assertEqual('ssh', $uri->getProtocol(), 'protocol');
     $this->assertEqual('git', $uri->getUser(), 'user');
     $this->assertEqual('', $uri->getPass(), 'pass');
     $this->assertEqual('example.com', $uri->getDomain(), 'domain');
     $this->assertEqual('', $uri->getPort(), 'port');
     $this->assertEqual('/example/example.git', $uri->getPath(), 'path');
     $this->assertEqual(array(), $uri->getQueryParams(), 'query params');
     $this->assertEqual('', $uri->getFragment(), 'fragment');
     $this->assertEqual('ssh://git@example.com/example/example.git', (string) $uri, 'uri');
     $uri = new PhutilURI('http://0@domain.com/');
     $this->assertEqual('0', $uri->getUser());
     $this->assertEqual('http://0@domain.com/', (string) $uri);
     $uri = new PhutilURI('http://0:0@domain.com/');
     $this->assertEqual('0', $uri->getUser());
     $this->assertEqual('0', $uri->getPass());
     $this->assertEqual('http://0:0@domain.com/', (string) $uri);
     $uri = new PhutilURI('http://%20:%20@domain.com/');
     $this->assertEqual(' ', $uri->getUser());
     $this->assertEqual(' ', $uri->getPass());
     $this->assertEqual('http://%20:%20@domain.com/', (string) $uri);
     $uri = new PhutilURI('http://%40:%40@domain.com/');
     $this->assertEqual('@', $uri->getUser());
     $this->assertEqual('@', $uri->getPass());
     $this->assertEqual('http://%40:%40@domain.com/', (string) $uri);
 }
开发者ID:lsubra,项目名称:libphutil,代码行数:38,代码来源:PhutilURITestCase.php

示例13: processEditForm

 public function processEditForm(AphrontRequest $request, array $values)
 {
     $errors = array();
     $issues = array();
     $is_setup = $this->isSetup();
     $key_name = self::PROPERTY_JIRA_NAME;
     $key_uri = self::PROPERTY_JIRA_URI;
     if (!strlen($values[$key_name])) {
         $errors[] = pht('JIRA instance name is required.');
         $issues[$key_name] = pht('Required');
     } else {
         if (!preg_match('/^[a-z0-9.]+\\z/', $values[$key_name])) {
             $errors[] = pht('JIRA instance name must contain only lowercase letters, digits, and ' . 'period.');
             $issues[$key_name] = pht('Invalid');
         }
     }
     if (!strlen($values[$key_uri])) {
         $errors[] = pht('JIRA base URI is required.');
         $issues[$key_uri] = pht('Required');
     } else {
         $uri = new PhutilURI($values[$key_uri]);
         if (!$uri->getProtocol()) {
             $errors[] = pht('JIRA base URI should include protocol (like "https://").');
             $issues[$key_uri] = pht('Invalid');
         }
     }
     if (!$errors && $is_setup) {
         $config = $this->getProviderConfig();
         $config->setProviderDomain($values[$key_name]);
         $consumer_key = 'phjira.' . Filesystem::readRandomCharacters(16);
         list($public, $private) = PhutilJIRAAuthAdapter::newJIRAKeypair();
         $config->setProperty(self::PROPERTY_PUBLIC_KEY, $public);
         $config->setProperty(self::PROPERTY_PRIVATE_KEY, $private);
         $config->setProperty(self::PROPERTY_CONSUMER_KEY, $consumer_key);
     }
     return array($errors, $issues, $values);
 }
开发者ID:hamilyjing,项目名称:phabricator,代码行数:37,代码来源:PhabricatorJIRAAuthProvider.php

示例14: getSVNLogXMLObject

 /**
  * This method is kind of awkward here but both the SVN message and
  * change parsers use it.
  */
 protected function getSVNLogXMLObject($uri, $revision, $verbose = false)
 {
     if ($verbose) {
         $verbose = '--verbose';
     }
     try {
         list($xml) = execx("svn log --xml {$verbose} --limit 1 --non-interactive %s@%d", $uri, $revision);
     } catch (CommandException $ex) {
         // HTTPS is generally faster and more reliable than svn+ssh, but some
         // commit messages with non-UTF8 text can't be retrieved over HTTPS, see
         // Facebook rE197184 for one example. Make an attempt to fall back to
         // svn+ssh if we've failed outright to retrieve the message.
         $fallback_uri = new PhutilURI($uri);
         if ($fallback_uri->getProtocol() != 'https') {
             throw $ex;
         }
         $fallback_uri->setProtocol('svn+ssh');
         list($xml) = execx("svn log --xml {$verbose} --limit 1 --non-interactive %s@%d", $fallback_uri, $revision);
     }
     // Subversion may send us back commit messages which won't parse because
     // they have non UTF-8 garbage in them. Slam them into valid UTF-8.
     $xml = phutil_utf8ize($xml);
     return new SimpleXMLElement($xml);
 }
开发者ID:nguyennamtien,项目名称:phabricator,代码行数:28,代码来源:PhabricatorRepositoryCommitParserWorker.php

示例15: processEditForm

 public function processEditForm(AphrontRequest $request, array $values)
 {
     $is_setup = $this->isCreate();
     if (!$is_setup) {
         list($errors, $issues, $values) = parent::processEditForm($request, $values);
     } else {
         $errors = array();
         $issues = array();
     }
     $key_name = self::PROPERTY_PHABRICATOR_NAME;
     $key_uri = self::PROPERTY_PHABRICATOR_URI;
     if (!strlen($values[$key_name])) {
         $errors[] = pht('Phabricator instance name is required.');
         $issues[$key_name] = pht('Required');
     } else {
         if (!preg_match('/^[a-z0-9.]+\\z/', $values[$key_name])) {
             $errors[] = pht('Phabricator instance name must contain only lowercase letters, ' . 'digits, and periods.');
             $issues[$key_name] = pht('Invalid');
         }
     }
     if (!strlen($values[$key_uri])) {
         $errors[] = pht('Phabricator base URI is required.');
         $issues[$key_uri] = pht('Required');
     } else {
         $uri = new PhutilURI($values[$key_uri]);
         if (!$uri->getProtocol()) {
             $errors[] = pht('Phabricator base URI should include protocol (like "%s").', 'https://');
             $issues[$key_uri] = pht('Invalid');
         }
     }
     if (!$errors && $is_setup) {
         $config = $this->getProviderConfig();
         $config->setProviderDomain($values[$key_name]);
     }
     return array($errors, $issues, $values);
 }
开发者ID:rchicoli,项目名称:phabricator,代码行数:36,代码来源:PhabricatorPhabricatorAuthProvider.php


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