本文整理汇总了PHP中PhutilURI::setPath方法的典型用法代码示例。如果您正苦于以下问题:PHP PhutilURI::setPath方法的具体用法?PHP PhutilURI::setPath怎么用?PHP PhutilURI::setPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhutilURI
的用法示例。
在下文中一共展示了PhutilURI::setPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProxiedFuture
protected function getProxiedFuture()
{
if (!$this->future) {
$params = $this->params;
if (!$this->action) {
throw new Exception(pht('You must %s!', 'setRawGitHubQuery()'));
}
if (!$this->accessToken) {
throw new Exception(pht('You must %s!', 'setAccessToken()'));
}
$uri = new PhutilURI('https://api.github.com/');
$uri->setPath('/' . ltrim($this->action, '/'));
$future = new HTTPSFuture($uri);
$future->setData($this->params);
$future->addHeader('Authorization', 'token ' . $this->accessToken);
// NOTE: GitHub requires a 'User-Agent' header.
$future->addHeader('User-Agent', __CLASS__);
$future->setMethod($this->method);
foreach ($this->headers as $header) {
list($key, $value) = $header;
$future->addHeader($key, $value);
}
$this->future = $future;
}
return $this->future;
}
示例2: getServerStatus
public static function getServerStatus()
{
$uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
$uri = new PhutilURI($uri);
$uri->setPath('/status/');
list($body) = id(new HTTPSFuture($uri))->setTimeout(3)->resolvex();
$status = json_decode($body, true);
if (!is_array($status)) {
throw new Exception(pht('Expected JSON response from notification server, received: %s', $body));
}
return $status;
}
示例3: run
protected function run()
{
$argv = $this->getArgv();
if (count($argv) !== 1) {
throw new Exception(pht('Usage: %s %s', __CLASS__, '<json_config_file>'));
}
$json_raw = Filesystem::readFile($argv[0]);
try {
$config = phutil_json_decode($json_raw);
} catch (PhutilJSONParserException $ex) {
throw new PhutilProxyException(pht("File '%s' is not valid JSON!", $argv[0]), $ex);
}
$nick = idx($config, 'nick', 'phabot');
$handlers = idx($config, 'handlers', array());
$protocol_adapter_class = idx($config, 'protocol-adapter', 'PhabricatorIRCProtocolAdapter');
$this->pollFrequency = idx($config, 'poll-frequency', 1);
$this->config = $config;
foreach ($handlers as $handler) {
$obj = newv($handler, array($this));
$this->handlers[] = $obj;
}
$ca_bundle = idx($config, 'https.cabundle');
if ($ca_bundle) {
HTTPSFuture::setGlobalCABundleFromPath($ca_bundle);
}
$conduit_uri = idx($config, 'conduit.uri');
if ($conduit_uri) {
$conduit_token = idx($config, 'conduit.token');
// Normalize the path component of the URI so users can enter the
// domain without the "/api/" part.
$conduit_uri = new PhutilURI($conduit_uri);
$conduit_host = (string) $conduit_uri->setPath('/');
$conduit_uri = (string) $conduit_uri->setPath('/api/');
$conduit = new ConduitClient($conduit_uri);
if ($conduit_token) {
$conduit->setConduitToken($conduit_token);
} else {
$conduit_user = idx($config, 'conduit.user');
$conduit_cert = idx($config, 'conduit.cert');
$response = $conduit->callMethodSynchronous('conduit.connect', array('client' => __CLASS__, 'clientVersion' => '1.0', 'clientDescription' => php_uname('n') . ':' . $nick, 'host' => $conduit_host, 'user' => $conduit_user, 'certificate' => $conduit_cert));
}
$this->conduit = $conduit;
}
// Instantiate Protocol Adapter, for now follow same technique as
// handler instantiation
$this->protocolAdapter = newv($protocol_adapter_class, array());
$this->protocolAdapter->setConfig($this->config)->connect();
$this->runLoop();
$this->protocolAdapter->disconnect();
}
示例4: getRedirectURI
public function getRedirectURI()
{
if (strlen($this->getAlias())) {
$path = '/u/' . $this->getAlias();
} else {
$path = '/u/' . $this->getID();
}
$short_domain = PhabricatorEnv::getEnvConfig('phurl.short-uri');
if (!$short_domain) {
return $path;
}
$uri = new PhutilURI($short_domain);
$uri->setPath($path);
return (string) $uri;
}
示例5: validateHost
protected function validateHost($host)
{
if (!$host) {
// If the client doesn't send a host key, don't complain. We should in
// the future, but this change isn't severe enough to bump the protocol
// version.
// TODO: Remove this once the protocol version gets bumped past 2 (i.e.,
// require the host key be present and valid).
return;
}
$host = new PhutilURI($host);
$host->setPath('/');
$host = (string) $host;
$self = PhabricatorEnv::getProductionURI('/');
if ($self !== $host) {
throw new Exception("Your client is connecting to this install as '{$host}', but it is " . "configured as '{$self}'. The client and server must use the exact " . "same URI to identify the install. Edit your .arcconfig or " . "phabricator/conf so they agree on the URI for the install.");
}
}
示例6: getProxiedFuture
protected function getProxiedFuture()
{
if (!$this->future) {
$params = $this->params;
if (!$this->action) {
throw new Exception(pht('You must %s!', 'setRawSlackQuery()'));
}
if (!$this->accessToken) {
throw new Exception(pht('You must %s!', 'setAccessToken()'));
}
$uri = new PhutilURI('https://slack.com/');
$uri->setPath('/api/' . $this->action);
$uri->setQueryParam('token', $this->accessToken);
$future = new HTTPSFuture($uri);
$future->setData($this->params);
$future->setMethod($this->method);
$this->future = $future;
}
return $this->future;
}
示例7: processRequest
public function processRequest()
{
$uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
$uri = new PhutilURI($uri);
$uri->setPath('/status/');
$future = id(new HTTPSFuture($uri))->setTimeout(3);
try {
list($body) = $future->resolvex();
$body = json_decode($body, true);
if (!is_array($body)) {
throw new Exception("Expected JSON response from server!");
}
$status = $this->renderServerStatus($body);
} catch (Exception $ex) {
$status = new AphrontErrorView();
$status->setTitle("Notification Server Issue");
$status->appendChild('Unable to determine server status. This probably means the server ' . 'is not in great shape. The specific issue encountered was:' . '<br />' . '<br />' . '<strong>' . phutil_escape_html(get_class($ex)) . '</strong> ' . nl2br(phutil_escape_html($ex->getMessage())));
}
return $this->buildStandardPageResponse($status, array('title' => 'Aphlict Server Status'));
}
示例8: getProxiedFuture
protected function getProxiedFuture()
{
if (!$this->future) {
$params = $this->params;
if (!$this->action) {
throw new Exception(pht('You must %s!', 'setRawAsanaQuery()'));
}
if (!$this->accessToken) {
throw new Exception(pht('You must %s!', 'setAccessToken()'));
}
$uri = new PhutilURI('https://app.asana.com/');
$uri->setPath('/api/1.0/' . ltrim($this->action, '/'));
$future = new HTTPSFuture($uri);
$future->setData($this->params);
$future->addHeader('Authorization', 'Bearer ' . $this->accessToken);
$future->setMethod($this->method);
$this->future = $future;
}
return $this->future;
}
示例9: getProxiedFuture
protected function getProxiedFuture()
{
if (!$this->future) {
$params = $this->params;
if (!$this->action) {
throw new Exception("You must setRawWordPressQuery()!");
}
if (!$this->accessToken) {
throw new Exception("You must setAccessToken()!");
}
$uri = new PhutilURI('https://public-api.wordpress.com/');
$uri->setPath('/rest/v1/' . ltrim($this->action, '/'));
$future = new HTTPSFuture($uri);
$future->setData($this->params);
$future->setMethod($this->method);
// NOTE: This is how WordPress.com REST API authenticates
$future->addHeader('Authorization', 'Bearer ' . $this->accessToken);
$this->future = $future;
}
return $this->future;
}
示例10: processRequest
public function processRequest()
{
$request = $this->getRequest();
$alt = PhabricatorEnv::getEnvConfig('security.alternate-file-domain');
$uri = new PhutilURI($alt);
$alt_domain = $uri->getDomain();
if ($alt_domain && $alt_domain != $request->getHost()) {
return id(new AphrontRedirectResponse())->setURI($uri->setPath($request->getPath()));
}
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $this->phid);
if (!$file) {
return new Aphront404Response();
}
if (!$file->validateSecretKey($this->key)) {
return new Aphront403Response();
}
$data = $file->loadFileData();
$response = new AphrontFileResponse();
$response->setContent($data);
$response->setCacheDurationInSeconds(60 * 60 * 24 * 30);
$is_view = $file->isViewableInBrowser();
if ($is_view) {
$response->setMimeType($file->getViewableMimeType());
} else {
if (!$request->isHTTPPost()) {
// NOTE: Require POST to download files. We'd rather go full-bore and
// do a real CSRF check, but can't currently authenticate users on the
// file domain. This should blunt any attacks based on iframes, script
// tags, applet tags, etc., at least. Send the user to the "info" page
// if they're using some other method.
return id(new AphrontRedirectResponse())->setURI(PhabricatorEnv::getProductionURI($file->getBestURI()));
}
$response->setMimeType($file->getMimeType());
$response->setDownload($file->getName());
}
return $response;
}
示例11: getProxiedFuture
protected function getProxiedFuture()
{
if (!$this->future) {
$params = $this->params;
if (!$this->action) {
throw new Exception('You must setRawTwitchQuery()!');
}
if (!$this->accessToken) {
throw new Exception('You must setAccessToken()!');
}
$uri = new PhutilURI('https://api.twitch.tv/');
$uri->setPath('/kraken/' . ltrim($this->action, '/'));
$uri->setQueryParam('oauth_token', $this->accessToken);
$future = new HTTPSFuture($uri);
$future->setData($this->params);
$future->setMethod($this->method);
// NOTE: This is how the Twitch API is versioned.
$future->addHeader('Accept', 'application/vnd.twitchtv.2+json');
// NOTE: This is required to avoid rate limiting.
$future->addHeader('Client-ID', $this->clientID);
$this->future = $future;
}
return $this->future;
}
示例12: getViewURI
public function getViewURI()
{
if (!$this->getPHID()) {
throw new Exception("You must save a file before you can generate a view URI.");
}
$alt = PhabricatorEnv::getEnvConfig('security.alternate-file-domain');
if ($alt) {
$path = '/file/alt/' . $this->getSecretKey() . '/' . $this->getPHID() . '/';
$uri = new PhutilURI($alt);
$uri->setPath($path);
return (string) $uri;
} else {
return '/file/view/' . $this->getPHID() . '/';
}
}
示例13: getURIObject
private function getURIObject()
{
// Users can provide Git/SCP-style URIs in the form "user@host:path".
// In the general case, these are not equivalent to any "ssh://..." form
// because the path is relative.
if ($this->isBuiltin()) {
$builtin_protocol = $this->getForcedProtocol();
$builtin_domain = $this->getForcedHost();
$raw_uri = "{$builtin_protocol}://{$builtin_domain}";
} else {
$raw_uri = $this->getURI();
}
$port = $this->getForcedPort();
$default_ports = array('ssh' => 22, 'http' => 80, 'https' => 443);
$uri = new PhutilURI($raw_uri);
// Make sure to remove any password from the URI before we do anything
// with it; this should always be provided by the associated credential.
$uri->setPass(null);
$protocol = $this->getForcedProtocol();
if ($protocol) {
$uri->setProtocol($protocol);
}
if ($port) {
$uri->setPort($port);
}
// Remove any explicitly set default ports.
$uri_port = $uri->getPort();
$uri_protocol = $uri->getProtocol();
$uri_default = idx($default_ports, $uri_protocol);
if ($uri_default && $uri_default == $uri_port) {
$uri->setPort(null);
}
$user = $this->getForcedUser();
if ($user) {
$uri->setUser($user);
}
$host = $this->getForcedHost();
if ($host) {
$uri->setDomain($host);
}
$path = $this->getForcedPath();
if ($path) {
$uri->setPath($path);
}
return $uri;
}
示例14: PhutilURI
if ($force_conduit) {
$conduit_uri = $force_conduit;
} else {
$conduit_uri = $configuration_manager->getConfigFromAnySource('phabricator.uri');
if ($conduit_uri === null) {
$conduit_uri = $configuration_manager->getConfigFromAnySource('default');
}
}
if ($conduit_uri) {
// Set the URI path to '/api/'. TODO: Originally, I contemplated letting
// you deploy Phabricator somewhere other than the domain root, but ended
// up never pursuing that. We should get rid of all "/api/" silliness
// in things users are expected to configure. This is already happening
// to some degree, e.g. "arc install-certificate" does it for you.
$conduit_uri = new PhutilURI($conduit_uri);
$conduit_uri->setPath('/api/');
$conduit_uri = (string) $conduit_uri;
}
$workflow->setConduitURI($conduit_uri);
// Apply global CA bundle from configs.
$ca_bundle = $configuration_manager->getConfigFromAnySource('https.cabundle');
if ($ca_bundle) {
$ca_bundle = Filesystem::resolvePath($ca_bundle, $working_copy->getProjectRoot());
HTTPSFuture::setGlobalCABundleFromPath($ca_bundle);
}
$blind_key = 'https.blindly-trust-domains';
$blind_trust = $configuration_manager->getConfigFromAnySource($blind_key);
if ($blind_trust) {
HTTPSFuture::setBlindlyTrustDomains($blind_trust);
}
if ($need_conduit) {
示例15: makeInternalURI
private function makeInternalURI($uri_string)
{
$uri = new PhutilURI($uri_string);
$proto = $uri->getProtocol();
if ($proto !== 'svn+ssh') {
throw new Exception(pht('Protocol for URI "%s" MUST be "svn+ssh".', $uri_string));
}
$path = $uri->getPath();
// Subversion presumably deals with this, but make sure there's nothing
// skethcy going on with the URI.
if (preg_match('(/\\.\\./)', $path)) {
throw new Exception(pht('String "/../" is invalid in path specification "%s".', $uri_string));
}
$repository = $this->loadRepository($path);
$path = preg_replace('(^/diffusion/[A-Z]+)', rtrim($repository->getLocalPath(), '/'), $path);
if (preg_match('(^/diffusion/[A-Z]+/\\z)', $path)) {
$path = rtrim($path, '/');
}
$uri->setPath($path);
// If this is happening during the handshake, these are the base URIs for
// the request.
if ($this->externalBaseURI === null) {
$pre = (string) id(clone $uri)->setPath('');
$this->externalBaseURI = $pre . '/diffusion/' . $repository->getCallsign();
$this->internalBaseURI = $pre . rtrim($repository->getLocalPath(), '/');
}
return (string) $uri;
}