Compare commits
10 Commits
fd8b979c9c
...
main
Author | SHA1 | Date | |
---|---|---|---|
802581b1d2 | |||
1093d127bf | |||
d19b99d751 | |||
d4b8ccb6ec | |||
4dbea74e5f | |||
247c3ee180 | |||
4b4e06a98f | |||
31c51c1a5b | |||
171183c0ab | |||
9d6a79d80b |
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Joey Kimsey
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
60
README.md
60
README.md
@ -1,2 +1,60 @@
|
||||
|
||||
# Hermes
|
||||
Hermes is a small package to handle routing and autoloading designed in conjunction with [The Tempus Project](https://thetempusproject.com).
|
||||
|
||||
Hermes is a small package to handle redirects, routing, and autoloading. This library id developed in conjunction with [The Tempus Project](https://thetempusproject.com).
|
||||
|
||||
## Installation
|
||||
|
||||
To install, simply use the composer command:
|
||||
|
||||
`php composer.phar require thetempusproject/hermes`
|
||||
|
||||
`composer require thetempusproject/hermes`
|
||||
|
||||
## Usage
|
||||
|
||||
Typical usage would be through including the package via composer.
|
||||
|
||||
```php
|
||||
|
||||
require_once VENDOR_DIRECTORY . 'autoload.php';
|
||||
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
|
||||
if ( ! App::$isAdmin ) {
|
||||
return Redirect::home();
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
If you would like to use hermes own autoloading, simply inclode the constants file and the autoload file inside `/bin/`.
|
||||
|
||||
```php
|
||||
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
|
||||
// Hermes Constants
|
||||
if ( ! defined( 'HERMES_CONSTANTS_LOADED' ) ) {
|
||||
if ( defined( 'HERMES_CONFIG_DIRECTORY' ) ) {
|
||||
require_once HERMES_CONFIG_DIRECTORY . 'constants.php';
|
||||
}
|
||||
}
|
||||
|
||||
// Hermes Autoloader (Autoloader)
|
||||
if ( ! defined( 'HERMES_AUTOLOADED' ) ) {
|
||||
if ( defined( 'HERMES_ROOT_DIRECTORY' ) ) {
|
||||
require_once HERMES_ROOT_DIRECTORY . 'bin' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
}
|
||||
}
|
||||
|
||||
Redirect::home();
|
||||
|
||||
```
|
||||
|
||||
## Issues / Bugs / Contact
|
||||
|
||||
If anyone actually uses this library and runs into any issues, feel free to contact me and I'll look into it.
|
||||
|
||||
[Joey Kimsey](mailto:Joey@thetempusproject.com) - _Lead Developer_
|
||||
|
||||
[JoeyKimsey.com](https://JoeyKimsey.com)
|
||||
|
@ -1,15 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* autoload.php
|
||||
* bin/autoload.php
|
||||
*
|
||||
* Uses the Hermes autoloader if it has been defined.
|
||||
*
|
||||
* @version 3.0
|
||||
* @version 1.0.5
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com/TempusDebugger
|
||||
* @link https://TheTempusProject.com/libraries/Hermes
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Canary;
|
||||
namespace TheTempusProject\Hermes;
|
||||
|
||||
use TheTempusProject\Hermes\Classes\Autoloader;
|
||||
|
||||
|
@ -4,9 +4,9 @@
|
||||
*
|
||||
* This should provide a simple way to add autoloading.
|
||||
*
|
||||
* @version 3.0
|
||||
* @version 1.0.5
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com/Core
|
||||
* @link https://TheTempusProject.com/libraries/Hermes
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Hermes\Classes;
|
||||
@ -96,17 +96,35 @@ class Autoloader {
|
||||
foreach ( self::$namespaces[ $namespace ] as $key => $folder ) {
|
||||
if ( file_exists( $folder . $file ) ) {
|
||||
$possible_locations[] = $folder . $file;
|
||||
break;
|
||||
} elseif ( file_exists( $folder . ucfirst( $file ) ) ) {
|
||||
$possible_locations[] = $folder . ucfirst( $file );
|
||||
break;
|
||||
}
|
||||
$newFile = '';
|
||||
$exploded = explode( '_', $file );
|
||||
foreach ( $exploded as &$value ) {
|
||||
$newFile .= ucfirst( $value );
|
||||
}
|
||||
if ( file_exists( $folder . $newFile ) ) {
|
||||
$possible_locations[] = $folder . $newFile;
|
||||
break;
|
||||
} elseif ( file_exists( $folder . ucfirst( $newFile ) ) ) {
|
||||
$possible_locations[] = $folder . ucfirst( $newFile );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// foreach ( $possible_locations as $location ) {
|
||||
// // report the locations
|
||||
// }
|
||||
if ( !empty( $possible_locations ) ) {
|
||||
require_once $possible_locations[0];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the class to see if it can be loaded.
|
||||
*
|
||||
* @param {string} [$class]
|
||||
*/
|
||||
public static function testLoad( $class ) {
|
||||
$class = trim( $class, '\\' );
|
||||
$namespace_array = explode( '\\', $class );
|
||||
|
41
composer.json
Normal file
41
composer.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "thetempusproject/hermes",
|
||||
"type": "library",
|
||||
"description": "This library handles redirects, provides a common backbone for routing, and can handle autoloading in cases where composer is unavailable.",
|
||||
"license": "MIT",
|
||||
"minimum-stability": "dev",
|
||||
"keywords":
|
||||
[
|
||||
"thetempusproject",
|
||||
"php",
|
||||
"tools",
|
||||
"autoloader",
|
||||
"routing"
|
||||
],
|
||||
"homepage": "https://thetempusproject.com/libraries/hermes",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Joey Kimsey",
|
||||
"email": "Joey@thetempusproject.com",
|
||||
"homepage": "https://JoeyKimsey.com",
|
||||
"role": "Lead Developer"
|
||||
}
|
||||
],
|
||||
"require":
|
||||
{
|
||||
"php": ">=8.1.0"
|
||||
},
|
||||
"autoload":
|
||||
{
|
||||
"classmap":
|
||||
[
|
||||
"classes",
|
||||
"functions"
|
||||
],
|
||||
"files":
|
||||
[
|
||||
"config/constants.php"
|
||||
]
|
||||
}
|
||||
}
|
@ -13,5 +13,8 @@ if (!defined('HERMES_CLASSES_DIRECTORY')) {
|
||||
if (!defined('HERMES_REDIRECTS_ENABLED')) {
|
||||
define('HERMES_REDIRECTS_ENABLED', true);
|
||||
}
|
||||
|
||||
# Tell the app all constants have been loaded.
|
||||
if ( ! defined('HERMES_CONSTANTS_LOADED' ) ) {
|
||||
define( 'HERMES_CONSTANTS_LOADED', true );
|
||||
}
|
@ -4,9 +4,9 @@
|
||||
*
|
||||
* This class is used for header modification and page redirection.
|
||||
*
|
||||
* @version 3.0
|
||||
* @version 1.0.5
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com/Core
|
||||
* @link https://TheTempusProject.com/libraries/Hermes
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Hermes\Functions;
|
||||
|
@ -4,9 +4,9 @@
|
||||
*
|
||||
* This class is used to return file and directory locations.
|
||||
*
|
||||
* @version 3.0
|
||||
* @version 1.0.5
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com/Core
|
||||
* @link https://TheTempusProject.com/libraries/Hermes
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
|
||||
@ -14,6 +14,7 @@ namespace TheTempusProject\Hermes\Functions;
|
||||
|
||||
class Route {
|
||||
public static function testRouting() {
|
||||
// @todo - wtf
|
||||
// $url = Routes::getAddress( true ) . DEFAULT_CONTROLLER_CLASS . '/' . DEFAULT_CONTROLLER_METHOD;
|
||||
// echo '<pre>' . var_export( $url, true ) . '</pre>';
|
||||
// $host = gethostbyname( $url );
|
||||
@ -46,13 +47,20 @@ class Route {
|
||||
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
|
||||
return 'https';
|
||||
}
|
||||
if ( $_SERVER['SERVER_PORT'] == 443 ) {
|
||||
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
|
||||
return 'https';
|
||||
}
|
||||
if (!empty($_SERVER['HTTP_X_FORWARDED_PORT']) && $_SERVER['HTTP_X_FORWARDED_PORT'] == 443) {
|
||||
return 'https';
|
||||
}
|
||||
if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) {
|
||||
return 'https';
|
||||
}
|
||||
return 'http';
|
||||
}
|
||||
|
||||
public static function getHost( $internal = false ) {
|
||||
// @todo - wtf
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
if ( true === $internal ) {
|
||||
// if ( 'docker' === getenv( 'APP_ENV' ) ) {
|
||||
@ -79,6 +87,7 @@ class Route {
|
||||
$route = implode( '/', $fullArray ) . '/';
|
||||
return $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* finds the physical location of the application
|
||||
*
|
||||
|
2
vendor/.gitignore
vendored
Normal file
2
vendor/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
Reference in New Issue
Block a user