-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from LaswitchTech/dev
Publishing v0.0.9
- Loading branch information
Showing
12 changed files
with
1,163 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
## Description | ||
**Author(s)**: [Louis Ouellet]([email protected]) | ||
|
||
The `Core` package is a collection of classes that provide the basic functionality for the LaswitchTech Core Framework. The classes are designed to be extended and used in other projects. Additional `Core` packages can be added to extend the functionality of the framework. | ||
|
||
## License | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v0.0.8 | ||
v0.0.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
|
||
/** | ||
* Core Framework - API | ||
* | ||
* @license MIT (https://mit-license.org/) | ||
* @author Louis Ouellet <[email protected]> | ||
*/ | ||
|
||
// Declaring namespace | ||
namespace LaswitchTech\Core; | ||
|
||
// Import additionnal class into the global namespace | ||
use Exception; | ||
|
||
class API { | ||
|
||
// Global Properties | ||
protected $Output; | ||
protected $Request; | ||
protected $Config; | ||
protected $Auth; | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public function __construct() { | ||
|
||
// Import Global Variables | ||
global $OUTPUT, $REQUEST, $CONFIG, $AUTH; | ||
|
||
// Initialize Properties | ||
$this->Output = $OUTPUT; | ||
$this->Request = $REQUEST; | ||
$this->Config = $CONFIG; | ||
$this->Auth = $AUTH; | ||
} | ||
|
||
/** | ||
* Execute the API Request | ||
*/ | ||
public function request(){ | ||
|
||
// Retrieve the namespace | ||
$namespace = $this->Request->getNamespace(); | ||
|
||
// Parse the namespace | ||
$parts = explode("/", trim($namespace, "/")); | ||
|
||
// Check if the namespace is valid | ||
if(count($parts) > 1){ | ||
|
||
// Set the endpoint and method | ||
$endpoint = $parts[0]; | ||
$class = ucfirst($endpoint) . "Endpoint"; | ||
$method = $parts[1] . 'Action'; | ||
|
||
// Set the endpoint path | ||
$path = $this->Config->root() . "/Endpoint/" . ucfirst($endpoint) . "Endpoint.php"; | ||
|
||
// Check if the endpoint exists | ||
if(!is_file($path)){ | ||
|
||
// Set the path to the plugin path | ||
$path = $this->Config->root() . "/lib/plugins/" . $endpoint . "/Endpoint.php"; | ||
} | ||
|
||
// Check if the endpoint exists | ||
if(is_file($path)){ | ||
|
||
// Load the endpoint | ||
require_once $path; | ||
|
||
// Check if the class exists | ||
if(class_exists($class)){ | ||
|
||
// Initialize the endpoint | ||
$object = new $class(); | ||
|
||
// Check if the method exists | ||
if(method_exists($object, $method)){ | ||
|
||
// Retrieve Auth Properties | ||
$public = $object->getPublic(); | ||
$level = $object->getLevel(); | ||
$permission = "Endpoint>" . $namespace; | ||
|
||
// Check if Auth is available and if the endpoint is public | ||
if(get_class($this->Auth) !== "Strap" && !$public){ | ||
|
||
// Check if the user is authenticated | ||
if(!$this->Auth->isAuthenticated()){ | ||
|
||
// Send unauthorized | ||
$this->Output->print('Unauthorized', array('HTTP/1.1 401 Unauthorized')); | ||
} | ||
|
||
// Check if the user has the required permission | ||
if(!$this->Auth->hasPermission($permission, $level)){ | ||
|
||
// Send forbidden | ||
$this->Output->print('Forbidden', array('HTTP/1.1 403 Forbidden')); | ||
} | ||
} | ||
|
||
// Call the method | ||
$object->{$method}(); | ||
} else { | ||
|
||
// Could not find the method, send not implemented | ||
$this->Output->print('Could not find the method', array('HTTP/1.1 501 Not Implemented')); | ||
} | ||
} else { | ||
|
||
// Could not find the class, send not implemented | ||
$this->Output->print('Could not find the endpoint', array('HTTP/1.1 501 Not Implemented')); | ||
} | ||
} else { | ||
|
||
// Could not find the endpoint | ||
$this->Output->print('Could not find the endpoint', array('HTTP/1.1 404 Not Found')); | ||
} | ||
} else { | ||
|
||
// Could not identify the Controller and/or Method, send bad request | ||
$this->Output->print('Could not identify the Controller and/or Action', array('HTTP/1.1 400 Bad Request')); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
|
||
/** | ||
* Core Framework - Connector | ||
* | ||
* @license MIT (https://mit-license.org/) | ||
* @author Louis Ouellet <[email protected]> | ||
*/ | ||
|
||
// Declaring namespace | ||
namespace LaswitchTech\Core; | ||
|
||
// Import additionnal class into the global namespace | ||
use Exception; | ||
|
||
class Connector { | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
protected $Config; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* Here you might load global config or do other setup tasks. | ||
* For this example, we assume there's a $CONFIG global object | ||
* that stores DB credentials, etc. | ||
*/ | ||
public function __construct() | ||
{ | ||
global $CONFIG; | ||
$this->Config = $CONFIG; | ||
|
||
// If you have a method $CONFIG->add('database') to load DB config, do that here. | ||
if (method_exists($this->Config, 'add')) { | ||
$this->Config->add('database'); | ||
} | ||
} | ||
|
||
/** | ||
* Connect method to be overridden by child classes | ||
*/ | ||
public function connect() | ||
{ | ||
// Implementation in child classes | ||
} | ||
|
||
/** | ||
* Close method to be overridden by child classes | ||
*/ | ||
public function close() | ||
{ | ||
// Implementation in child classes | ||
} | ||
|
||
/** | ||
* Check if connected | ||
* | ||
* @return bool | ||
*/ | ||
public function isConnected(): bool | ||
{ | ||
// Implementation in child classes | ||
return false; | ||
} | ||
|
||
/** | ||
* Execute a query | ||
* | ||
* @param string $sql | ||
* @return mixed | ||
*/ | ||
public function query(string $sql) | ||
{ | ||
// Implementation in child classes | ||
} | ||
|
||
/** | ||
* Describe a table | ||
* | ||
* @param string $table | ||
* @return mixed | ||
*/ | ||
public function describe(string $table) | ||
{ | ||
// Implementation in child classes | ||
} | ||
|
||
/** | ||
* Get the ID of the last inserted row | ||
* | ||
* @return int | ||
*/ | ||
public function lastId(): int | ||
{ | ||
// Implementation in child classes | ||
return 0; | ||
} | ||
|
||
/** | ||
* Get the number of affected rows | ||
* | ||
* @return int | ||
*/ | ||
public function affectedRows(): int | ||
{ | ||
// Implementation in child classes | ||
return 0; | ||
} | ||
|
||
/** | ||
* Prepare a query | ||
* | ||
* @param string $sql | ||
*/ | ||
public function prepare(string $sql, array $params = []) | ||
{ | ||
// Implementation in child classes | ||
return false; | ||
} | ||
} |
Oops, something went wrong.