Skip to content

Instantly share code, notes, and snippets.

View ProdigyView's full-sized avatar

Devin Dixon ProdigyView

View GitHub Profile
<?php
include ('vendor/autoload.php');
use prodigyview\network\Curl;
use prodigyview\network\Socket;
use prodigyview\system\Security;
echo "\nStarting Route Speed Tests\n\n";
<?php
include_once (dirname(__FILE__) . '/../vendor/autoload.php');
use prodigyview\system\Security;
use prodigyview\network\Socket;
//Create The Server
$server = new Socket('localhost', 8650, array(
'bind' => true,
'listen' => true
<?php
include_once (dirname(__FILE__) . '/../vendor/autoload.php');
use prodigyview\network\Response;
$response = array('status' => 'success', 'message' => 'Responding');
echo Response::createResponse(200, json_encode($response));
<?php
include_once (dirname(__FILE__) . '/../vendor/autoload.php');
use prodigyview\network\Router;
use prodigyview\network\Request;
use prodigyview\network\Response;
Router::post('/callme', array('callback'=>function(Request $request){
$response = array('status' => 'success', 'message' => 'Responding');
<?php
Router::post('/products/purchase', array('callback'=>function(Request $request){
$response = array();
//RETRIEVE Data From The Request
$data = $request->getRequestData('array');
if ($data) {
<?php
$product_route = '127.0.0.1:8000/products';
$curl = new Curl($product_route.'/purchase');
$curl->send('post', array(
'amount' => '20.00',
'nounce' => '1c46538c712e9b5bf0fe43d692',
));
<?php
if (isset($data['token']) && AuthBearer::hasAccess($data['token'], $type)) {
if($type == 'charge' && checkNounce($data['nounce'], $nounces)) {
$id = charge($data['amount'], $data['nounce'], array('product' => 'Shoes'), $charges);
$response = array('status' => 'success', 'message' => $id);
}else if($type == 'charge') {
$response = array('status' => 'error', 'message' => 'Invalid Nounce');
} else if($type == 'refund' && refund($data['id'], $charges)) {
$response = array('status' => 'success', 'message' => 'Refund Successful');
<?php
function hasExpired(string $token, array $tokens, int $current_time) : bool {
if(!isset($tokens[$token])) {
return true;
}
if($tokens[$token]['expiration'] < $current_time) {
return true;
}
<?php
function checkPrivileges(string $token, string $requested_privilege, array $tokens) : bool {
if(!isset($tokens[$token])) {
return false;
}
foreach($tokens[$token]['privileges'] as $privilege) {
if($privilege === '*') {
<?php
function validateToken(string $token, string $privileges = '', array $tokens, int $current_time) : bool {
if(!isset($tokens[$token])) {
return false;
}
if(hasExpired($token, $tokens, $current_time)) {
return false;
}