PHP code example of gollumsf / url-tokenizer-bundle
1. Go to this page and download the library: Download gollumsf/url-tokenizer-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use GollumSF\UrlTokenizerBundle\Tokenizer\TokenizerInterface;
public function (TokenizerInterface $tokenizer) { // Inject service
$url = 'http://www.mydomain.com?param1=a';
// $url1Tokenised => http://www.mydomain.com?param1=a&t=THE_TOKENd=1580775131 (tokenize only parameter)
$url1Tokenised = $tokenizer->generateUrl($url);
// $url1Tokenised => http://www.mydomain.com?param1=a&t=THE_TOKENd=1580775131 (tokenize full url)
$url1Tokenised = $tokenizer->generateUrl($url, true);
// $url1Tokenised => http://www.mydomain.com?param1=a&t=THE_TOKENd=1580775131 (use custom secret)
$url1Tokenised = $tokenizer->generateUrl($url, false, 'CUSTOM SECRET');
}
use GollumSF\UrlTokenizerBundle\Checker\CheckerInterface;
public function (CheckerInterface $checker) { // Inject service
$urlWithToken = 'http://www.mydomain.com?param1=a&t=THE_TOKEN&d=1580775131';
// $result => true or false
$result = $checker->checkToken($urlWithToken);
// $result => true or false (use full url)
$result = $checker->checkToken($urlWithToken, true);
// $result => true or false (use custom secret)
$result = $checker->checkToken($urlWithToken, null, 'CUSTOM SECRET');
// $result => true or false automatic use url from Master Request
$result = $checker->checkTokenMasterRequest();
$result = $checker->checkTokenMasterRequest(true);
$result = $checker->checkTokenMasterRequest(null, 'CUSTOM SECRET');
// $result => is true if token is generate before 3600 second ago
$result = $checker->checkTokenTime($urlWithToken, 3600);
$result = $checker->checkTokenTimeMasterRequest(3600); // on Master Request
// $result => result on valid Token and Time
$result = $checker->checkTokenAndTokenTime($urlWithToken, 3600);
$result = $checker->checkTokenAndTokenTimeMasterRequest(3600); // on Master Request
}
use GollumSF\UrlTokenizerBundle\Annotation\ValidToken;
use GollumSF\UrlTokenizerBundle\Tokenizer\TokenizerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;
class GenerateController extends AbstractController {
/**
* @Route("/generate")
*/
public function generate(TokenizerInterface $tokenizer) {
return new Response($tokenizer->generateUrl(
$this->generateUrl('validate', [ 'param' => 'value' ], RouterInterface::ABSOLUTE_URL)
));
}
/**
* @Route("/validate", name="validate")
* @ValidToken()
*/
public function validate(TokenizerInterface $tokenizer) {
return new Response('good');
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.