PHP code example of zepekegno / obfuscate-id-bundle
1. Go to this page and download the library: Download zepekegno/obfuscate-id-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/ */
// src/Controller/PostController.php
namespace App\Controller;
use App\Entity\Post;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Zepekegno\ObfuscateBundle\Attribute\ObfuscateId;
class PostController extends AbstractController
{
#[Route('/{id}', name: 'app_post_show', methods: ['GET'])]
public function show(
#[ObfuscateId] Post $post
): Response {
return $this->render('post/show.html.twig', [
'post' => $post,
]);
}
}
// src/Controller/PostController.php
namespace App\Controller;
use App\Entity\Post;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Zepekegno\ObfuscateBundle\Attribute\ObfuscateId;
class PostController extends AbstractController
{
#[Route('/{post}', name: 'app_post_show', methods: ['GET'])]
public function show(
#[ObfuscateId(routeParam: 'post')] Post $post
): Response {
return $this->render('post/show.html.twig', [
'post' => $post,
]);
}
}
// src/Controller/PostController.php
namespace App\Controller;
use App\Entity\Post;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Zepekegno\ObfuscateBundle\Attribute\ObfuscateId;
class PostController extends AbstractController
{
#[Route('/{id}', name: 'app_post_show', methods: ['GET'])]
public function show(
#[ObfuscateId(identifierField: 'post')] Post $post
): Response {
return $this->render('post/show.html.twig', [
'post' => $post,
]);
}
}
// src/Controller/PostController.php
namespace App\Controller;
use App\Entity\Post;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Zepekegno\ObfuscateBundle\Attribute\ObfuscateId;
class PostController extends AbstractController
{
#[Route('/{post}', name: 'app_post_show', methods: ['GET'])]
public function show(
#[ObfuscateId(routeParam: 'post', entity: Post::class)] $post,
): Response {
return $this->render('post/show.html.twig', [
'post' => $post,
]);
}
}
// src/Controller/PostController.php
namespace App\Controller;
use App\Entity\Post;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Zepekegno\ObfuscateBundle\Attribute\ObfuscateId;
class PostController extends AbstractController
{
#[Route('/{id}', name: 'app_post_show', methods: ['GET'])]
public function show(
#[ObfuscateId(enity:Post::class)] $post
): Response {
return $this->render('post/show.html.twig', [
'post' => $post,
]);
}
}
//src/service/CustomObfuscate.php
class CustomObfuscateService implements ObfuscateInterface{
public function obfuscate(int $value):string{
// Do something here
}
public function deobfuscate(string $value):?int{
// Do something here
}
}
config/bundles.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.