Initial commit
This commit is contained in:
104
vendor/hermes/functions/route.php
vendored
Normal file
104
vendor/hermes/functions/route.php
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* functions/routes.php
|
||||
*
|
||||
* This class is used to return file and directory locations.
|
||||
*
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com/Core
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
|
||||
namespace TheTempusProject\Hermes\Functions;
|
||||
|
||||
class Route {
|
||||
public static function testRouting() {
|
||||
// $url = Routes::getAddress( true ) . DEFAULT_CONTROLLER_CLASS . '/' . DEFAULT_CONTROLLER_METHOD;
|
||||
// echo '<pre>' . var_export( $url, true ) . '</pre>';
|
||||
// $host = gethostbyname( $url );
|
||||
// echo '<pre>' . var_export( $url, true ) . '</pre>';
|
||||
// $host = dns_get_record( $url );
|
||||
// echo '<pre>' . var_export( $url, true ) . '</pre>';
|
||||
// $headers = @get_headers( $url );
|
||||
// echo '<pre>' . var_export( $headers, true ) . '</pre>';
|
||||
// $file = true;
|
||||
// echo '<pre>' . var_export( $file, true ) . '</pre>';
|
||||
// exit;
|
||||
return true;
|
||||
$headers = get_headers( $url );
|
||||
if ( empty( $headers ) ) {
|
||||
return false;
|
||||
}
|
||||
$response_code = substr( $headers[0], 9, 3 );
|
||||
if ( $response_code != '200' ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the server is using a secure transfer protocol or not.
|
||||
*
|
||||
* @return string - The string representation of the server's transfer protocol
|
||||
*/
|
||||
public static function getProtocol() {
|
||||
if ( !empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ) {
|
||||
return 'https';
|
||||
}
|
||||
if ( $_SERVER['SERVER_PORT'] == 443 ) {
|
||||
return 'https';
|
||||
}
|
||||
return 'http';
|
||||
}
|
||||
|
||||
public static function getHost( $internal = false ) {
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
if ( true === $internal ) {
|
||||
// if ( 'docker' === getenv( 'APP_ENV' ) ) {
|
||||
// if ( Check::isNginx() ) {
|
||||
// $host = 'webone';
|
||||
// } elseif ( Check::isApache() ) {
|
||||
// $host = 'webtwo';
|
||||
// } else {
|
||||
// $host = '127.0.0.1';
|
||||
// }
|
||||
// }
|
||||
}
|
||||
return $host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the root directory of the application.
|
||||
*
|
||||
* @return string - The applications root directory.
|
||||
*/
|
||||
public static function getRoot() {
|
||||
$fullArray = explode( '/', $_SERVER['PHP_SELF'] );
|
||||
array_pop( $fullArray ); // removes the current file name (index.php)
|
||||
$route = implode( '/', $fullArray ) . '/';
|
||||
return $route;
|
||||
}
|
||||
/**
|
||||
* finds the physical location of the application
|
||||
*
|
||||
* @return string - The root file location for the application.
|
||||
*/
|
||||
public static function getAddress( $internal = false ) {
|
||||
return self::getProtocol() . '://' . self::getHost( $internal ) . self::getRoot();
|
||||
}
|
||||
|
||||
public static function getRequestUrl( $includeParams = true ) {
|
||||
return self::getProtocol() . '://' . self::getHost() . self::getUri( $includeParams );
|
||||
}
|
||||
|
||||
public static function getUri( $includeParams = true ) {
|
||||
if ( true === $includeParams ) {
|
||||
$out = $_SERVER['REQUEST_URI'];
|
||||
} else {
|
||||
$explodedSelect = explode( '?', $_SERVER['REQUEST_URI'] );
|
||||
$out = $explodedSelect[0];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user