本文整理汇总了PHP中Uri类的典型用法代码示例。如果您正苦于以下问题:PHP Uri类的具体用法?PHP Uri怎么用?PHP Uri使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Uri类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* Parses the string and returns the {@link Uri}.
*
* Parses the string and returns the {@link Uri}. If parsing fails, null is returned.
*
* @param String $string The url.
*
* @return \Bumble\Uri\Uri The Uri object.
*/
public function parse($string)
{
$data = parse_url($string);
//helper function gets $a[$k], checks if exists
function get($a, $k)
{
if (array_key_exists($k, $a)) {
return empty($a[$k]) ? null : $a[$k];
}
return null;
}
if ($data === null) {
return null;
}
$uri = new Uri();
$uri->setProtocol(get($data, 'scheme'));
$uri->setUsername(get($data, 'user'));
$uri->setPassword(get($data, 'pass'));
$uri->setHost(get($data, 'host'));
$uri->setPort(get($data, 'port'));
$uri->setPath(get($data, 'path'));
$uri->setQuery(get($data, 'query'));
$uri->setAnchor(get($data, 'anchor'));
return $uri;
}
示例2: dispatch
/**
* @param \Components\Http_Scriptlet_Context $context_
* @param \Components\Uri $uri_
*/
public static function dispatch(Http_Scriptlet_Context $context_, Uri $uri_)
{
$key = $uri_->getFilename();
if (!($path = Cache::get($key))) {
throw new Http_Exception('ui/scriptlet/image', null, Http_Exception::NOT_FOUND);
}
// TODO Cache headers.
readfile($path);
}
示例3: match
public function match(FilterableUri $uri)
{
/*
* if the URI does not contain the seed, it is not allowed
*/
if (false === stripos($uri->toString(), $this->seed->toString())) {
$uri->setFiltered(true, 'Doesn\'t match base URI');
return true;
}
return false;
}
示例4: dispatch
public static function dispatch(Http_Scriptlet_Context $context_, Uri $uri_)
{
$params = $uri_->getPathParams();
$storeName = array_shift($params);
$categoryName = array_shift($params);
$file = Io::fileUpload();
$store = Media::store($storeName);
$store->add($file, $file->getName(), $categoryName);
// TODO JSON
echo $store->uri($file->getName(), $categoryName);
}
示例5: testGettersAndSetters
public function testGettersAndSetters()
{
$uri1 = new Uri('');
$uri2 = $uri1->withScheme('HTTP')->withUserInfo('foo', 'bar')->withHost('EXAMPLE.com')->withPort(81)->withPath('/FOO/bar')->withQuery('a=2&b=3')->withFragment('foobar');
$this->assertEquals('http', $uri2->getScheme());
$this->assertEquals('foo:bar', $uri2->getUserInfo());
$this->assertEquals('example.com', $uri2->getHost());
$this->assertEquals(81, $uri2->getPort());
$this->assertEquals('/foo/bar', $uri2->getPath());
$this->assertEquals('a=2&b=3', $uri2->getQuery());
$this->assertEquals('foobar', $uri2->getFragment());
}
示例6: dispatch
/**
* @param \Components\Http_Scriptlet_Context $context_
* @param \Components\Uri $uri_
*/
public static function dispatch(Http_Scriptlet_Context $context_, Uri $uri_)
{
$params = $uri_->getPathParams();
$base64 = end($params);
$info = unserialize(\str\decodeBase64Url($base64));
$path = array_shift($info);
$id = array_shift($info);
$category = array_shift($info);
$scheme = array_shift($info);
$store = Media::store($path);
$file = $store->findByScheme($scheme, $id, $category);
header('Content-Length: ' . $file->getSize()->bytes());
readfile((string) $file);
}
示例7: getSegments
private function getSegments()
{
$uri = $this->uri;
foreach ($this->route as $key => $val) {
if (preg_match('#^' . $key . '$#', $uri)) {
if (strpos($val, '$') !== false && strpos($key, '(') !== false) {
$uri = preg_replace('#^' . $key . '$#', $val, $this->uri);
}
}
}
$uri = new Uri($uri);
$segments = $uri->explodeSegments();
return $segments;
}
示例8: Anchor
public static function Anchor($uri, $title = NULL, $attributes = NULL, $protocol = NULL, $escape_title = FALSE)
{
/**
* Create HTML link anchors.
*
* @param string URL or URI string
* @param string link text
* @param array HTML anchor attributes
* @param string non-default protocol, eg: https
* @param boolean option to escape the title that is output
* @return string
*/
if ($protocol === NULL) {
$protocol = getenv('HTTPS') == 'on' ? 'https' : 'http';
}
if (strpos($uri, '#') === 0) {
// This is an id target link, not a URL
$site_url = $uri;
} elseif (strpos($uri, '://') === FALSE) {
$site_url = Uri::baseUrl() . $uri;
} else {
//$attributes['target'] = '_blank';
$site_url = $uri;
}
return '<a href="' . $site_url . '"' . (is_array($attributes) ? htmlAttributes($attributes) : '') . '>' . ($escape_title ? htmlspecialchars($title === NULL ? $site_url : $title, ENT_QUOTES, 'UTF-8', FALSE) : ($title === NULL ? $site_url : $title)) . '</a>';
}
示例9: include_client_scripts
protected function include_client_scripts($scripts = 'default')
{
if (empty($scripts)) {
return;
}
if (!is_array($scripts)) {
$scripts = array($scripts);
}
foreach ($scripts as $script) {
if (empty($this->client_scripts_included[$script])) {
switch ($script) {
case 'default':
$this->template->scripts[] = $this->create_js_link("//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js");
$this->template->scripts[] = $this->create_js_link("//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.min.js");
$this->template->css[] = $this->create_css_link("//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css");
$this->template->css[] = $this->create_css_link(Uri::create('assets/css/style.css'));
break;
case 'jquery_forms':
$this->template->scripts[] = $this->create_js_link("//cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.0/jquery.qtip.min.js");
$this->template->scripts[] = $this->create_js_link("//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.14.0/jquery.validate.min.js");
$this->template->scripts[] = $this->create_js_link("//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.14.0/additional-methods.min.js");
$this->template->scripts[] = $this->create_js_link("//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js");
$this->template->scripts[] = $this->create_js_link(Uri::create('assets/js/jquery-forms-config.js'));
array_unshift($this->template->css, $this->create_css_link('//cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.0/jquery.qtip.min.css'));
array_unshift($this->template->css, $this->create_css_link("//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.css"));
break;
}
$this->client_scripts_included[$script] = true;
//don't include the same script more than once
}
}
}
示例10: notify
/**
* Because Paypal Ipn is redirected to \Payment\PayPal\ipn
* There is no need to notify customer here, we'll do that in Ipn method of Payment module
*/
public function notify()
{
$config = array('mode' => $this->config['mode'], 'acct1.UserName' => $this->config['user_name'], 'acct1.Password' => $this->config['password'], 'acct1.Signature' => $this->config['signature']);
$paypalService = new \PayPal\Service\PayPalAPIInterfaceServiceService($config);
$getExpressCheckoutDetailsRequest = new \PayPal\PayPalAPI\GetExpressCheckoutDetailsRequestType(\Session::get('paypal.token'));
$getExpressCheckoutDetailsRequest->Version = $this->config['version'];
$getExpressCheckoutReq = new \PayPal\PayPalAPI\GetExpressCheckoutDetailsReq();
$getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
$getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
// COMMIT THE PAYMENT
$paypalService = new \PayPal\Service\PayPalAPIInterfaceServiceService($config);
$paymentDetails = new \PayPal\EBLBaseComponents\PaymentDetailsType();
$orderTotal = new \PayPal\CoreComponentTypes\BasicAmountType($this->config['currency'], $this->getOrderTotal());
$paymentDetails->OrderTotal = $orderTotal;
$paymentDetails->PaymentAction = 'Sale';
$paymentDetails->NotifyURL = $this->config['notify_url'];
$DoECRequestDetails = new \PayPal\EBLBaseComponents\DoExpressCheckoutPaymentRequestDetailsType();
$DoECRequestDetails->PayerID = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PayerInfo->PayerID;
$DoECRequestDetails->Token = $getECResponse->GetExpressCheckoutDetailsResponseDetails->Token;
$DoECRequestDetails->PaymentDetails[0] = $paymentDetails;
$DoECRequest = new \PayPal\PayPalAPI\DoExpressCheckoutPaymentRequestType();
$DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
$DoECRequest->Version = $this->config['version'];
$DoECReq = new \PayPal\PayPalAPI\DoExpressCheckoutPaymentReq();
$DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
$DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
if ($DoECResponse->Ack == 'Success') {
$this->savePayment('Completed', 'Completed', $DoECResponse->toXMLString());
\Response::redirect(\Uri::create('order/checkout/finalise_order'));
}
$this->savePayment('Failed', 'Transaction failed', $DoECResponse->Errors[0]->LongMessage);
return true;
// failed
}
示例11: action_index
public function action_index()
{
$this->template = View::forge("teachers/template");
$this->template->auth_status = false;
$this->template->title = "Forgotpassword";
// login
if (Input::post("email", null) !== null and Security::check_token()) {
$email = Input::post('email', null);
$user = Model_User::find("first", ["where" => [["email", $email]]]);
if ($user != null) {
$token = Model_Forgotpasswordtoken::forge();
$token->user_id = $user->id;
$token->token = sha1("asadsada23424{$user->email}" . time());
$token->save();
$url = Uri::base() . "teachers/forgotpassword/form/{$token->token}";
$body = View::forge("email/forgotpassword", ["url" => $url]);
$sendmail = Email::forge("JIS");
$sendmail->from(Config::get("statics.info_email"), Config::get("statics.info_name"));
$sendmail->to($email);
$sendmail->subject("forgot password");
$sendmail->html_body(htmlspecialchars_decode($body));
$sendmail->send();
}
$view = View::forge("teachers/forgotpassword/sent");
$this->template->content = $view;
} else {
$view = View::forge("teachers/forgotpassword/index");
$this->template->content = $view;
}
}
示例12: testDispatch
/**
* @test
* @profile
*/
public function testDispatch()
{
split_time('reset');
Rest_Test_Unit_Case_Resource_Foo::serve('resource/foo');
split_time('Invoke Rest_Test_Unit_Case_Resource_Foo::serve(resource/foo)');
Http_Scriptlet_Context::push(new Http_Scriptlet_Context(Environment::uriComponents()));
split_time('Initialize Components\\Http_Scriptlet_Context');
$uri = Uri::valueOf(Environment::uriComponents('rest', 'resource', 'foo', 'poke', '1234.json'));
split_time("Invoke Uri::valueOf({$uri})");
ob_start();
split_time('reset');
Http_Scriptlet_Context::current()->dispatch($uri, Http_Scriptlet_Request::METHOD_GET);
split_time("Invoke Components\\Http_Scriptlet_Context\$dispatch([{$uri}], GET)");
$result = ob_get_clean();
assertEquals(json_encode(true), $result);
split_time('reset');
$uri = Uri::valueOf(Environment::uriComponents('rest', 'resource', 'foo', 'poke', '1234.json'));
$uri->setQueryParam('log', 'false');
split_time("Invoke Uri::valueOf({$uri})");
ob_start();
split_time('reset');
Http_Scriptlet_Context::current()->dispatch($uri, Http_Scriptlet_Request::METHOD_GET);
split_time("Invoke Components\\Http_Scriptlet_Context\$dispatch([{$uri}], GET)");
$result = ob_get_clean();
assertEquals(json_encode(false), $result);
}
示例13: _send_instructions
/**
* Sends the instructions to a user's email address.
*
* @return bool
*/
private static function _send_instructions($name, Model_User $user)
{
$config_key = null;
switch ($name) {
case 'confirmation':
$config_key = 'confirmable';
break;
case 'reset_password':
$config_key = 'recoverable';
break;
case 'unlock':
$config_key = 'lockable';
break;
default:
throw new \InvalidArgumentException("Invalid instruction: {$name}");
}
$mail = \Email::forge();
$mail->from(\Config::get('email.defaults.from.email'), \Config::get('email.defaults.from.name'));
$mail->to($user->email);
$mail->subject(__("warden.mailer.subject.{$name}"));
$token_name = "{$name}_token";
$mail->html_body(\View::forge("warden/mailer/{$name}_instructions", array('username' => $user->username, 'uri' => \Uri::create(':url/:token', array('url' => rtrim(\Config::get("warden.{$config_key}.url"), '/'), 'token' => $user->{$token_name})))));
$mail->priority(\Email::P_HIGH);
try {
return $mail->send();
} catch (\EmailSendingFailedException $ex) {
logger(\Fuel::L_ERROR, "Warden\\Mailer failed to send {$name} instructions.");
return false;
}
}
示例14: index
public function index()
{
Cache::loadPage('', 30);
$inputData = array();
$postid = 0;
Model::loadWithPath('page', System::getThemePath() . 'model/');
if (!($match = Uri::match('page\\/(.*?)\\.html$'))) {
Redirect::to('404page');
}
$friendly_url = addslashes($match[1]);
$loadData = Pages::get(array('cacheTime' => 30, 'where' => "where friendly_url='{$friendly_url}'"));
if (!isset($loadData[0]['pageid'])) {
Redirect::to('404page');
}
$inputData = $loadData[0];
$postid = $loadData[0]['pageid'];
if (Uri::isNull()) {
System::setTitle(ucfirst($loadData[0]['title']));
}
$keywords = isset($loadData[0]['keywords'][4]) ? $loadData[0]['keywords'] : System::getKeywords();
System::setKeywords($keywords);
if ($loadData[0]['page_type'] == 'fullwidth') {
self::makeContent('pageFullWidth', $inputData);
} else {
self::makeContent('page', $inputData);
}
Cache::savePage();
}
示例15: parseUrl
/**
* Parse url and reroute with routes.xml rules if found
*
* @return Uri Return the instance of Uri (rerouted or not)
*/
public function parseUrl()
{
// Get new instance of Uri
$uriInst = Uri::getInstance();
// Remove first / from uri
$uri = trim($uriInst->getUri(false), '/');
// Init vars
$defaultRedirect = null;
// Parse routes
foreach ($this->_routes as $route) {
// Converts shortcuts to regexp
$rule = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $route->attributes()->rule));
// Rule match to uri
if (preg_match('#^' . $rule . '$#', $uri)) {
// Is there any back reference
if (strpos($route->attributes()->redirect, '$') !== false && strpos($rule, '(') !== false) {
$uri = preg_replace('#^' . $rule . '$#', $route->attributes()->redirect, $uri);
} else {
$uri = $route->attributes()->redirect;
}
// Define rerouted uri to current instance of Uri
return $uriInst->setUri($uri);
}
if ($rule === 'default') {
$defaultRedirect = (string) $route->attributes()->redirect . '/' . $uri;
}
}
if (!$uriInst->isDefined() && $defaultRedirect !== null) {
$uriInst->setUri($defaultRedirect);
}
return $uriInst;
}