本文整理汇总了PHP中Nette\Http\Url类的典型用法代码示例。如果您正苦于以下问题:PHP Url类的具体用法?PHP Url怎么用?PHP Url使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Url类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
public function render($rowData)
{
if ($this->_renderer) {
return call_user_func($this->_renderer, $this);
}
// Direct URL
if ($this->_url !== NULL) {
// URL callback
if (is_callable($this->_url)) {
$url = call_user_func($this->_url, $rowData);
} else {
$url = new Nette\Http\Url($this->_url);
foreach ($this->_table->getIdColumns() as $key) {
$url->appendQuery(array('record' . ucfirst($key) => isset($rowData->{$key}) ? $rowData->{$key} : NULL));
}
}
$this->element->href((string) $url);
// Standard action's URL
} else {
$this->element->href($this->_table->createActionLink($this->getName(), $rowData));
}
// Class
if (($class = $this->getClass($rowData)) !== NULL) {
$this->element->class .= " {$class}";
}
return (string) $this->element;
}
示例2: constructUrl
public function constructUrl(Request $appRequest, Url $refUrl)
{
// Module prefix not match.
if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) {
return null;
}
$params = $appRequest->getParameters();
$urlStack = [];
// Module prefix
$moduleFrags = explode(":", Strings::lower($appRequest->getPresenterName()));
$resourceName = array_pop($moduleFrags);
$urlStack += $moduleFrags;
// Resource
$urlStack[] = Strings::lower($resourceName);
// Id
if (isset($params['id']) && is_scalar($params['id'])) {
$urlStack[] = $params['id'];
unset($params['id']);
}
// Set custom action
if (isset($params['action']) && $this->_isApiAction($params['action'])) {
unset($params['action']);
}
$url = $refUrl->getBaseUrl() . implode('/', $urlStack);
// Add query parameters
if (!empty($params)) {
$url .= "?" . http_build_query($params);
}
return $url;
}
示例3: addTrackingParameters
/**
* @param Payment $payment
* @return Payment
*/
public static function addTrackingParameters(Payment $payment)
{
$resURL = $payment->getResURL();
$url = new Url($resURL);
$url->setQueryParameter('utm_nooverride', 1);
$payment->setResURL($url->getAbsoluteUrl());
return $payment;
}
示例4: addTrackingParameters
public static function addTrackingParameters(Payment $payment)
{
$redirectUrls = $payment->getRedirectUrls();
$url = new Url($redirectUrls->getReturnUrl());
$url->setQueryParameter('utm_nooverride', 1);
$redirectUrls->setReturnUrl($url->getAbsoluteUrl());
$payment->setRedirectUrls($redirectUrls);
return $payment;
}
示例5: getVideoByUrl
/**
* Fetches video data by youtube url
* @param string $videoUrl YouTube url
* @return Video
*/
public function getVideoByUrl($videoUrl)
{
$url = new Nette\Http\Url($videoUrl);
if (stripos($url->host, 'youtu.be') !== false) {
return $this->getVideo(trim($url->getPath(), '/'));
}
$videoId = $url->getQueryParameter('v');
if (stripos($url->host, 'youtube.com') === false || $videoId === null) {
throw new Nette\InvalidArgumentException('videoUrl must be valid youtube url.');
}
return $this->getVideo($videoId);
}
示例6: redirectToRequest
/**
* Restores request from session.
* @param string $key
*/
public function redirectToRequest($key)
{
$request = $this->requestStorage->loadRequest($key);
if (!$request) {
return;
}
$parameters = $request->getParameters();
$parameters[Presenter::FLASH_KEY] = $this->getParameter(Presenter::FLASH_KEY);
$parameters[RequestStorage::REQUEST_KEY] = $key;
$request->setParameters($parameters);
$refUrl = new Url($this->httpRequest->getUrl());
$refUrl->setPath($this->httpRequest->getUrl()->getScriptPath());
$url = $this->router->constructUrl($request, $refUrl);
$this->redirectUrl($url);
}
示例7: constructUrl
/**
* Constructs absolute URL from Request object.
*
* @param Nette\Application\Request
* @param Nette\Http\Url
*
* @return string|NULL
*/
public function constructUrl(Application\Request $appRequest, Nette\Http\Url $refUrl)
{
if ($this->flags & self::ONE_WAY) {
return null;
}
$params = $appRequest->getParameters();
// presenter name
$presenter = $appRequest->getPresenterName();
if (strncasecmp($presenter, $this->module, strlen($this->module)) === 0) {
$params[self::PRESENTER_KEY] = substr($presenter, strlen($this->module));
} else {
return null;
}
// remove default values; NULL values are retain
foreach ($this->defaults as $key => $value) {
if (isset($params[$key]) && $params[$key] == $value) {
// intentionally ==
unset($params[$key]);
}
}
$url = ($this->flags & self::SECURED ? 'https://' : 'http://') . $refUrl->getAuthority() . $refUrl->getPath();
$sep = ini_get('arg_separator.input');
$query = http_build_query($params, '', $sep ? $sep[0] : '&');
if ($query != '') {
// intentionally ==
$url .= '?' . $query;
}
return $url;
}
示例8: validateRecaptcha
/**
* @return bool
*/
public function validateRecaptcha()
{
$httpData = $this->getForm()->getHttpData();
if (!isset($httpData['g-recaptcha-response'])) {
$this->addError($this->getFilledMessage());
return TRUE;
}
$this->validateKeys();
$url = new Url();
$url->setHost('www.google.com')->setScheme('https')->setPath('recaptcha/api/siteverify')->setQueryParameter('secret', $this->secretKey)->setQueryParameter('response', $httpData['g-recaptcha-response']);
$data = json_decode(file_get_contents((string) $url));
if (!isset($data->success) || $data->success !== TRUE) {
$this->addError($this->getValidMessage());
}
return TRUE;
}
示例9: exec
/**
* Calls remote API.
*
* @param string
* @return mixed json-decoded result
* @throws \NetteAddons\IOException
*/
protected function exec($path)
{
try {
$url = new Url($this->baseUrl . '/' . ltrim($path, '/'));
if ($this->clientId && $this->clientSecret) {
$url->appendQuery(array('client_id' => $this->clientId, 'client_secret' => $this->clientSecret));
}
$request = $this->requestFactory->create($url);
$request->addHeader('Accept', "application/vnd.github.{$this->apiVersion}+json");
return \Nette\Utils\Json::decode($request->execute());
} catch (\NetteAddons\Utils\StreamException $e) {
throw new \NetteAddons\IOException('Request execution failed.', NULL, $e);
} catch (\Nette\Utils\JsonException $e) {
throw new \NetteAddons\IOException('GitHub API returned invalid JSON.', NULL, $e);
}
}
示例10: process
private function process($url, string $directory, string $parameter, array &$dependencies = []) : string
{
$url = new Nette\Http\Url($url);
$time = NULL;
if ($url->getHost() && (!$this->request || $url->getHost() !== $this->request->getUrl()->getHost())) {
$headers = @get_headers($url, TRUE);
if (is_array($headers) && isset($headers['Last-Modified'])) {
$time = (new DateTime($headers['Last-Modified']))->getTimestamp();
}
} elseif (is_file($filename = implode(DIRECTORY_SEPARATOR, [rtrim($directory, '\\/'), ltrim($url->getPath(), '\\/')]))) {
$time = filemtime($filename);
unset($dependencies[Nette\Caching\Cache::EXPIRE]);
$dependencies[Nette\Caching\Cache::FILES] = $filename;
}
$url->setQueryParameter($parameter, $time ?: ($this->time ?: ($this->time = time())));
return preg_replace($pattern = '#^(\\+|/+)#', preg_match($pattern, $url->getPath()) ? DIRECTORY_SEPARATOR : NULL, $url);
}
示例11: validateRecaptcha
public function validateRecaptcha()
{
$httpData = $this->getForm()->getHttpData();
if (!isset($httpData['g-recaptcha-response'])) {
$this->addError('Please fill antispam.');
return TRUE;
}
$url = new Url();
$url->setHost('www.google.com')->setScheme('https')->setPath('recaptcha/api/siteverify')->setQueryParameter('secret', $this->secretKey)->setQueryParameter('response', $httpData['g-recaptcha-response']);
$data = json_decode(file_get_contents((string) $url));
if (isset($data->success) && $data->success === TRUE) {
return TRUE;
} else {
$this->addError('Antispam detection wasn\'t success.');
return TRUE;
}
}
示例12: sendBackgroundGetRequest
/**
* Funkce pro odeslání GET požadavku bez čekání na získání odpovědi
* @param string $url
* @throws \Exception
*/
public static function sendBackgroundGetRequest($url)
{
$url = new Url($url);
$host = $url->getHost();
if (empty($host)) {
$host = 'localhost';
}
#region parametry připojení
switch ($url->getScheme()) {
case 'https':
$scheme = 'ssl://';
$port = 443;
break;
case 'http':
default:
$scheme = '';
$port = 80;
}
$urlPort = $url->getPort();
if (!empty($urlPort)) {
$port = $urlPort;
}
#endregion
$fp = @fsockopen($scheme . $host, $port, $errno, $errstr, self::REQUEST_TIMEOUT);
if (!$fp) {
Debugger::log($errstr, ILogger::ERROR);
throw new \Exception($errstr, $errno);
}
$path = $url->getPath() . ($url->getQuery() != "" ? '?' . $url->getQuery() : '');
fputs($fp, "GET " . $path . " HTTP/1.0\r\nHost: " . $host . "\r\n\r\n");
fputs($fp, "Connection: close\r\n");
fputs($fp, "\r\n");
}
示例13: createComponentPlayer
public function createComponentPlayer()
{
$host = explode(".", $this->playUrl->getHost());
$provider = Nette\Utils\Strings::lower($host[count($host) - 2]);
$handler = "\\App\\Controls\\" . ucfirst($provider) . "Player";
if (class_exists($handler)) {
$player = new $handler($this->playUrl);
} else {
$player = new \App\Controls\NoPlayer($this->playUrl);
}
return $player;
}
示例14: constructUrl
/**
* Constructs absolute URL from Request object.
* @return string|NULL
*/
public function constructUrl(array $params, Nette\Http\Url $refUrl)
{
if ($this->flags & self::ONE_WAY) {
return NULL;
}
// remove default values; NULL values are retain
foreach ($this->defaults as $key => $value) {
if (isset($params[$key]) && $params[$key] == $value) {
// intentionally ==
unset($params[$key]);
}
}
$url = ($this->flags & self::SECURED ? 'https://' : $refUrl->getScheme() . '://') . $refUrl->getAuthority() . $refUrl->getPath();
$sep = ini_get('arg_separator.input');
$query = http_build_query($params, '', $sep ? $sep[0] : '&');
if ($query != '') {
// intentionally ==
$url .= '?' . $query;
}
return $url;
}
示例15: constructUrl
/**
* Constructs absolute URL from Request object.
*
* @return string|NULL
*/
public function constructUrl(AppRequest $appRequest, Url $refUrl)
{
if ($this->flags & self::ONE_WAY) {
return NULL;
}
$params = $appRequest->getParameters();
if (!isset($params['action']) || !is_string($params['action'])) {
return NULL;
}
$key = $appRequest->getPresenterName() . ':' . $params['action'];
if (!isset($this->tableOut[$key])) {
return NULL;
}
if ($this->lastRefUrl !== $refUrl) {
$this->lastBaseUrl = $refUrl->getBaseUrl();
$this->lastRefUrl = $refUrl;
}
unset($params['action']);
$slug = $this->tableOut[$key];
$query = ($tmp = http_build_query($params)) ? '?' . $tmp : '';
$url = $this->lastBaseUrl . $slug . $query;
return $url;
}