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
<?php | |
include ('vendor/autoload.php'); | |
use prodigyview\network\Curl; | |
use prodigyview\network\Socket; | |
use prodigyview\system\Security; | |
echo "\nStarting Route Speed Tests\n\n"; |
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
<?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 |
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
<?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)); |
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
<?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'); |
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
<?php | |
Router::post('/products/purchase', array('callback'=>function(Request $request){ | |
$response = array(); | |
//RETRIEVE Data From The Request | |
$data = $request->getRequestData('array'); | |
if ($data) { |
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
<?php | |
$product_route = '127.0.0.1:8000/products'; | |
$curl = new Curl($product_route.'/purchase'); | |
$curl->send('post', array( | |
'amount' => '20.00', | |
'nounce' => '1c46538c712e9b5bf0fe43d692', | |
)); |
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
<?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'); |
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
<?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; | |
} |
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
<?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 === '*') { |
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
<?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; | |
} |
NewerOlder