PHP code example of longitude-one / banned-bundle

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

    

longitude-one / banned-bundle example snippets


// config/bundles.php

return [
    // ...
    LongitudeOne\BannedBundle\LongitudeOneBannedBundle::class => ['all' => true],
];

// src/Entity/User.php

namespace App\Entity;

// declare the interface
use LongitudeOne\BannedBundle\Entity\BannedInterface;
use Symfony\Component\Security\Core\User\UserInterface;

// add the interface
class User implements BannedInterface, UserInterface
{
    //Add a private property
    private bool $banned = false;

    //Your getter can be improved to avoid that an admin bans another one.        
    public function isBanned(): bool
    {
        //In this example admins cannot be banned
        return $this->isBanned() and !in_array('ROLE_ADMIN', $this->getRoles());
    }
    
    //Add a setter if needed
    public function setBanned(bool $banned): self
    {
        $this->banned = $banned;
        
        return $this;
    }
    
    //...    
}