php DoomHamster Media Group的URI解析器(如果不使用命名空间,则从脚本顶部删除命名空间)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php DoomHamster Media Group的URI解析器(如果不使用命名空间,则从脚本顶部删除命名空间)相关的知识,希望对你有一定的参考价值。
<?php namespace DHMedia\Input;
/**
* DHMedia URI Parser
*
* @author Mark LaDoux <mark.ladoux@gmail.com>
* @copyright Copyright © 2018, DoomHamster Media
* @license MIT <https://opensource.org/licenses/MIT>
*/
class URI
{
/**
* URI Data
*
* @access protected
* @var array
*/
protected $data = [];
/**
* Class Constructior
*
* Parses the current URI and stores it into an array for use.
*
* @access public
* @return void
*/
public function __construct()
{
// Smaller variable that's easier to work with
$sd = $_SERVER;
// Data Stuff
$data['hostname'] = $sd['SERVER_NAME'];
$data['secure'] = (isset($sd['HTTPS']) && $sd['HTTPS'] == 'on') ? true : false;
$data['port'] = (int) $sd['SERVER_PORT'];
$data['document'] = $sd['DOCUMENT_URI'];
// Get raw uri
$raw_uri = ltrim($sd['REQUEST_URI'], $data['document']);
// Ensure that $data['raw_uri'] is set to something.
if (empty($raw_uri)) {
$raw_uri = '/';
}
$data['raw_uri'] = $raw_uri;
// Check for uri query string
$pos = strpos($data['raw_uri'], '?');
if ($pos === false) {
// We don't need to do anything, set the uri and query arrays.
$data['uri'] = $data['raw_uri'];
$data['query'] = [];
} else {
// we need to split the query's from the uri
$limit = 2;
$parts = explode('?', $data['raw_uri'], $limit);
$data['uri'] = $parts[0];
$queries = explode('&', $parts[1]);
foreach ($queries as $query) {
$limit = 2;
$keyval = explode('=', $query, $limit);
$data['query'][$keyval[0]] = $keyval[1];
}
}
// Get URI segments
$data['segment'] = array_merge([], array_filter(explode('/', $data['uri'])));
$this->data = $data;
}
/**
* segment
*
* Returns the requested uri segment
*
* @access public
* @param int $n Segment to retrieve
* @return string Value of segment
*/
public function segment(int $n)
{
// If the script requests segment 0, we will return the document name
// We stripped it out before forming the segments for consistency, so that
// it will even be available here if url rewriting is used to hide it.
if ($n === 0) {
return $this->data['document'];
}
$key = $n - 1;
// if the segment is set, return it, else return false
return ($this->data['segment'][$key]) ? $this->data['segment'][$key] : false;
}
/**
* Retrieve value of query
*
* @access public
* @param string $key Key name
* @return mixed Key value
*/
public function query(string $key)
{
return (isset($this->data['query'][$key])) ? $this->data['query'][$key] : false;
}
/**
* Return whether or not the request is using a secure protocol
*
* @access public
* @return bool true if secure, false if not.
*/
public function secure()
{
return $this->data['secure'];
}
/**
* Return the requested hostname from the URL
*
* @access public
* @return string
*/
public function hostname()
{
return $this->data['hostname'];
}
/**
* Return the port number site was accessed over
*
* @access public
* @return int
*/
public function port()
{
return $this->data['port'];
}
}
以上是关于php DoomHamster Media Group的URI解析器(如果不使用命名空间,则从脚本顶部删除命名空间)的主要内容,如果未能解决你的问题,请参考以下文章
php Drupal Media Bundle Image
PHP PHP Media API类(YouTube,Flickr,Vimeo,Bitly)
php Laravel上传Spatie Media Libary
php 允许SVG通过WordPress Media Uploader
php my_media_handle_upload()
php Filtre Media Library par utilisateurs