PHP code example of mimmi20 / mezzio-generic-authorization

1. Go to this page and download the library: Download mimmi20/mezzio-generic-authorization 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/ */

    

mimmi20 / mezzio-generic-authorization example snippets


namespace Mezzio\Authentication;

interface UserInterface
{
    /**
     * Get the unique user identity (id, username, email address or ...)
     */
    public function getIdentity() : string;

    /**
     * Get all user roles
     *
     * @return Iterable
     */
    public function getRoles() : iterable;

    /**
     * Get a detail $name if present, $default otherwise
     */
    public function getDetail(string $name, $default = null);

    /**
     * Get all the details, if any
     */
    public function getDetails() : array;
}

public function isGranted(?string $role = null, ?string $resource = null, ?string $privilege = null, ?\Psr\Http\Message\ServerRequestInterface\ServerRequestInterface $request = null): bool;

  use Mimmi20\Mezzio\GenericAuthorization\AuthorizationInterface;
  use Mimmi20\Mezzio\GenericAuthorization\Acl\LaminasAcl;
  
  return [
      'dependencies' => [
          // Using an alias:
          'aliases' => [
              AuthorizationInterface::class => LaminasAcl::class,
          ],
      ],
  ];
  

  use Mimmi20\Mezzio\GenericAuthorization\AuthorizationInterface;
  use Mimmi20\Mezzio\GenericAuthorization\Acl\LaminasAclFactory;
  
  return [
      'dependencies' => [
          // Using a factory:
          'factories' => [
              AuthorizationInterface::class => LaminasAclFactory::class,
          ],
      ],
  ];