8 Commits

Author SHA1 Message Date
d19b99d751 correct version comments 2025-02-02 07:27:56 -05:00
d4b8ccb6ec readme updates 2025-02-02 07:26:15 -05:00
4dbea74e5f Cleanup
Improved readme
removed contributing and code of conduct as they are basically just fluff when no one knows this repo exists
removed composer.lock because this repo doesn't install anything to lock
update copywrite to 2025
composer update to description
comments
2025-02-02 07:14:21 -05:00
247c3ee180 Readme update 2025-01-27 22:54:45 -05:00
4b4e06a98f Improved http vs https detection
To fix issues with cloudflare dns routing.
2025-01-21 20:43:29 -05:00
31c51c1a5b bugfix for camelCase filenames 2024-08-20 06:26:47 -04:00
171183c0ab release prep 2024-08-12 22:56:27 -04:00
9d6a79d80b fixes to support composer / packagist 2024-08-08 23:49:08 -04:00
9 changed files with 169 additions and 18 deletions

21
LICENSE Normal file
View 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.

View File

@ -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`
## 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';
}
}
if ( ! App::$isAdmin ) {
return 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)

View File

@ -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.4
* @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;

View File

@ -4,9 +4,9 @@
*
* This should provide a simple way to add autoloading.
*
* @version 3.0
* @version 1.0.4
* @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 );

40
composer.json Normal file
View File

@ -0,0 +1,40 @@
{
"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":
[
"php",
"tools",
"routing",
"thetempusproject"
],
"homepage": "https://git.thetempusproject.com/the-tempus-project/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"
]
}
}

View File

@ -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.
define( 'HERMES_CONSTANTS_LOADED', true );
if ( ! defined('HERMES_CONSTANTS_LOADED' ) ) {
define( 'HERMES_CONSTANTS_LOADED', true );
}

View File

@ -4,9 +4,9 @@
*
* This class is used for header modification and page redirection.
*
* @version 3.0
* @version 1.0.4
* @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;

View File

@ -4,9 +4,9 @@
*
* This class is used to return file and directory locations.
*
* @version 3.0
* @version 1.0.4
* @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 );
@ -43,16 +44,23 @@ class Route {
* @return string - The string representation of the server's transfer protocol
*/
public static function getProtocol() {
if ( !empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ) {
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
View File

@ -0,0 +1,2 @@
*
!.gitignore