init
This commit is contained in:
93
README.md
93
README.md
@ -1,93 +1,2 @@
|
||||
# Hermes
|
||||
|
||||
|
||||
|
||||
## Getting started
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
|
||||
## Add your files
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://170-187-142-254.ip.linodeusercontent.com/the-tempus-project/hermes.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
|
||||
- [ ] [Set up project integrations](https://170-187-142-254.ip.linodeusercontent.com/the-tempus-project/hermes/-/settings/integrations)
|
||||
|
||||
## Collaborate with your team
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||
|
||||
## Test and Deploy
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
|
||||
***
|
||||
|
||||
# Editing this README
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
|
||||
## Suggestions for a good README
|
||||
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
Hermes is a small package to handle routing and autoloading designed in conjunction with [The Tempus Project](https://thetempusproject.com).
|
||||
|
44
bin/autoload.php
Normal file
44
bin/autoload.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* autoload.php
|
||||
*
|
||||
* Uses the Hermes autoloader if it has been defined.
|
||||
*
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com/TempusDebugger
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Canary;
|
||||
|
||||
use TheTempusProject\Hermes\Classes\Autoloader;
|
||||
|
||||
if ( !defined( 'HERMES_ROOT_DIRECTORY' ) ) {
|
||||
define( 'HERMES_ROOT_DIRECTORY', dirname( __DIR__ ) . DIRECTORY_SEPARATOR );
|
||||
}
|
||||
|
||||
if ( ! defined('HERMES_CONFIG_DIRECTORY' ) ) {
|
||||
define('HERMES_CONFIG_DIRECTORY', HERMES_ROOT_DIRECTORY . 'config' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
if ( ! defined('HERMES_CONSTANTS_LOADED' ) ) {
|
||||
require_once HERMES_CONFIG_DIRECTORY . 'constants.php';
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TheTempusProject\Hermes\Classes\Autoloader' ) ) {
|
||||
require_once HERMES_CLASSES_DIRECTORY . 'autoloader.php';
|
||||
}
|
||||
|
||||
$autoloader = new Autoloader;
|
||||
$autoloader->setRootFolder( HERMES_ROOT_DIRECTORY );
|
||||
$autoloader->addNamespace(
|
||||
'TheTempusProject\Hermes\Classes',
|
||||
'classes'
|
||||
);
|
||||
$autoloader->addNamespace(
|
||||
'TheTempusProject\Hermes\Functions',
|
||||
'functions'
|
||||
);
|
||||
$autoloader->register();
|
||||
|
||||
define( 'HERMES_AUTOLOADED', true );
|
168
classes/autoloader.php
Normal file
168
classes/autoloader.php
Normal file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/**
|
||||
* classes/autoloader.php
|
||||
*
|
||||
* This should provide a simple way to add autoloading.
|
||||
*
|
||||
* @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\Classes;
|
||||
|
||||
class Autoloader {
|
||||
protected static $namespaces = [];
|
||||
protected $rootFolder = '';
|
||||
|
||||
/**
|
||||
* Automatically requires all the files within a given directory.
|
||||
*
|
||||
* @param {string} [$directory]
|
||||
* @param {bool} [$includeRoot]
|
||||
*/
|
||||
public function includeFolder( $directory = '', $includeRoot = true ) {
|
||||
$base_dir = str_replace( '\\', DIRECTORY_SEPARATOR, $directory );
|
||||
$base_dir = str_replace( '/', DIRECTORY_SEPARATOR, $base_dir );
|
||||
$base_dir = rtrim( $base_dir, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR;
|
||||
// should require all the files in the specific folder
|
||||
if ( $includeRoot ) {
|
||||
$base_dir = $this->rootFolder . $base_dir;
|
||||
}
|
||||
if ( !is_dir( $base_dir ) ) {
|
||||
return false;
|
||||
}
|
||||
$files = scandir( $base_dir );
|
||||
array_shift( $files );
|
||||
array_shift( $files );
|
||||
foreach ( $files as $key => $value ) {
|
||||
if ( stripos( $value, '.php' ) ) {
|
||||
include_once $base_dir . $value;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a namespace and corresponding directory to the autoload list.
|
||||
*
|
||||
* @param {string} [$namespace]
|
||||
* @param {string} [$directory]
|
||||
* @param {bool} [$includeRoot]
|
||||
*/
|
||||
public function addNamespace( $namespace, $directory = '', $includeRoot = true ) {
|
||||
// normalize namespace prefix
|
||||
$prefix = trim( $namespace, '\\' ) . '\\';
|
||||
|
||||
// normalize directory
|
||||
$base_dir = str_replace( '\\', DIRECTORY_SEPARATOR, $directory );
|
||||
$base_dir = str_replace( '/', DIRECTORY_SEPARATOR, $base_dir );
|
||||
$base_dir = rtrim( $base_dir, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR;
|
||||
|
||||
if ( $base_dir === DIRECTORY_SEPARATOR ) {
|
||||
$base_dir = '';
|
||||
}
|
||||
|
||||
if ( empty( self::$namespaces[ $prefix ] ) ) {
|
||||
self::$namespaces[ $prefix ] = [];
|
||||
}
|
||||
|
||||
// retain the base directory for the namespace prefix
|
||||
if ( $includeRoot ) {
|
||||
$base_dir = $this->rootFolder . $base_dir;
|
||||
}
|
||||
array_push( self::$namespaces[ $prefix ], $base_dir );
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the main method for the autoloader. It will cycle through
|
||||
* possible locations and load the first available file.
|
||||
*
|
||||
* @param {string} [$class]
|
||||
*/
|
||||
public function loadClass( $class ) {
|
||||
$class = trim( $class, '\\' );
|
||||
$namespace_array = explode( '\\', $class );
|
||||
$class_name = array_pop( $namespace_array );
|
||||
$namespace = implode( '\\', $namespace_array ) . '\\';
|
||||
|
||||
if ( empty( self::$namespaces[ $namespace ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = convertClassNameToFileName( $class_name );
|
||||
|
||||
$possible_locations = [];
|
||||
foreach ( self::$namespaces[ $namespace ] as $key => $folder ) {
|
||||
if ( file_exists( $folder . $file ) ) {
|
||||
$possible_locations[] = $folder . $file;
|
||||
}
|
||||
}
|
||||
|
||||
// foreach ( $possible_locations as $location ) {
|
||||
// // report the locations
|
||||
// }
|
||||
if ( !empty( $possible_locations ) ) {
|
||||
require_once $possible_locations[0];
|
||||
}
|
||||
}
|
||||
|
||||
public static function testLoad( $class ) {
|
||||
$class = trim( $class, '\\' );
|
||||
$namespace_array = explode( '\\', $class );
|
||||
$class_name = array_pop( $namespace_array );
|
||||
$namespace = implode( '\\', $namespace_array ) . '\\';
|
||||
|
||||
if ( class_exists( $class ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( empty( self::$namespaces[ $namespace ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = convertClassNameToFileName( $class_name );
|
||||
|
||||
$possible_locations = [];
|
||||
foreach ( self::$namespaces[ $namespace ] as $key => $folder ) {
|
||||
if ( file_exists( $folder . $file ) ) {
|
||||
$possible_locations[] = $folder . $file;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !empty( $possible_locations ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the root folder for file paths.
|
||||
*
|
||||
* @param {string} [$folder]
|
||||
*/
|
||||
public function setRootFolder( $folder ) {
|
||||
$this->rootFolder = rtrim( $folder, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new autoloader that should serve the currently defined namespaces.
|
||||
*/
|
||||
public function register() {
|
||||
spl_autoload_register( [ $this, 'loadClass' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the currently defined namespaces.
|
||||
*/
|
||||
public function getNamespaces() {
|
||||
return self::$namespaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the currently defined root folder.
|
||||
*/
|
||||
public function getRootFolder() {
|
||||
return $this->rootFolder;
|
||||
}
|
||||
}
|
17
config/constants.php
Normal file
17
config/constants.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
// Directories
|
||||
if ( !defined( 'HERMES_ROOT_DIRECTORY' ) ) {
|
||||
define( 'HERMES_ROOT_DIRECTORY', dirname( __DIR__ ) . DIRECTORY_SEPARATOR );
|
||||
}
|
||||
if ( ! defined('HERMES_CONFIG_DIRECTORY' ) ) {
|
||||
define('HERMES_CONFIG_DIRECTORY', HERMES_ROOT_DIRECTORY . 'config' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('HERMES_CLASSES_DIRECTORY')) {
|
||||
define('HERMES_CLASSES_DIRECTORY', HERMES_ROOT_DIRECTORY . 'classes' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('HERMES_REDIRECTS_ENABLED')) {
|
||||
define('HERMES_REDIRECTS_ENABLED', true);
|
||||
}
|
||||
# Tell the app all constants have been loaded.
|
||||
define( 'HERMES_CONSTANTS_LOADED', true );
|
64
functions/redirect.php
Normal file
64
functions/redirect.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* functions/redirect.php
|
||||
*
|
||||
* This class is used for header modification and page redirection.
|
||||
*
|
||||
* @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 Redirect {
|
||||
/**
|
||||
* The main redirect function. This will automatically call the
|
||||
* error controller if the value passed to it is numerical. It will
|
||||
* automatically populate the url based on the config and add the
|
||||
* $data string at the end
|
||||
*
|
||||
* @param string|int $data - The desired redirect location (string for location and integer for error page).
|
||||
*/
|
||||
public static function to( $data ) {
|
||||
if ( ! HERMES_REDIRECTS_ENABLED ) {
|
||||
return;
|
||||
}
|
||||
if ( is_numeric( $data ) ) {
|
||||
header( 'Location: ' . Route::getAddress() . 'Errors/' . $data );
|
||||
}
|
||||
$url = Route::getAddress() . $data;
|
||||
if ( filter_var( $url, FILTER_VALIDATE_URL ) != false ) {
|
||||
header( 'Location: ' . $url );
|
||||
}
|
||||
}
|
||||
|
||||
public static function home() {
|
||||
if ( ! HERMES_REDIRECTS_ENABLED ) {
|
||||
return;
|
||||
}
|
||||
header( 'Location: ' . Route::getAddress() );
|
||||
}
|
||||
|
||||
public static function external( $data ) {
|
||||
if ( ! HERMES_REDIRECTS_ENABLED ) {
|
||||
return;
|
||||
}
|
||||
$url = filter_var( $data, FILTER_SANITIZE_URL );
|
||||
if ( filter_var( $url, FILTER_VALIDATE_URL ) != false ) {
|
||||
header( 'Location: ' . $data );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the current page.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public static function reload() {
|
||||
if ( ! HERMES_REDIRECTS_ENABLED ) {
|
||||
exit();
|
||||
}
|
||||
header( 'Refresh:0' );
|
||||
}
|
||||
}
|
104
functions/route.php
Normal file
104
functions/route.php
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