PHP code example of kikwik / debounce-bundle

1. Go to this page and download the library: Download kikwik/debounce-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/ */

    

kikwik / debounce-bundle example snippets


namespace App\Controller;

use Kikwik\DebounceBundle\Service\DebounceInterface;

class HomeController extends AbstractController
{
    /**
     * @Route("/debounce/{email}", name="app_debounce")
     */
    public function debounce($email, DebounceInterface $debounce)
    {
        $message = '';
        $result = $debounce->check($email);
        if($result['success']==1)
        {
            switch($result['debounce']['code'])
            {
                case '1':
                    $message = 'Syntax, Not an email, Not safe';
                    break;
                case '2':
                    $message = 'Spam Trap, Spam-trap by ESPs, Not safe';
                    break;
                case '3':
                    $message = 'Disposable, A temporary, disposable address, Not safe';
                    break;
                case '4':
                    $message = 'Accept-All, A domain-wide setting, Maybe safe';
                    break;
                case '5':
                    $message = 'Deliverable, Verified as real address, Safe';
                    break;
                case '6':
                    $message = 'Invalid, Verified as invalid (Bounce), Not safe';
                    break;
                case '7':
                    $message = 'Unknown, The server cannot be reached, Not safe';
                    break;
                case '8':
                    $message = 'Role, Role accounts such as info, support, etc, Maybe safe';
                    break;
            }
        }
        else
        {
            $message = $result['debounce']['error'];
        }
        return new Response($message);
    }
}

namespace App\Entity;

use Kikwik\DebounceBundle\Model\DebounceTrait;

/**
 * @ORM\Entity(repositoryClass=UserRepository::class)
 * @ORM\Table(name="`user`")
 */
class User implements UserInterface
{
    use DebounceTrait;
}

namespace App\Controller;

use Kikwik\DebounceBundle\Service\DebounceInterface;

class HomeController extends AbstractController
{
    /**
     * @Route("/debounce/{email}", name="app_debounce")
     */
    public function debounce($email, DebounceInterface $debounce, UserRepository $userRepository, EntityManagerInterface $entityManager)
    {
        $user = $userRepository->findOneByEmail($email);
        if(!$user)
        {
            return $this->createNotFoundException();
        }

        $user->setDebounceResponse($debounce->check($email));
        $entityManager->flush();
        
        if($user->getIsDebounceSafe())
        {
            // safe email!!!
            $debounceCode = $user->getDebounceResponseCode();
            // ...  
        }

        return $this->redirectToRoute('app_home');
    }
}