PHP code example of alichry / laminas-authorization

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

    

alichry / laminas-authorization example snippets



# module.config.php

use Laminas\Authentication\AuthenticationService;

return [
    // ...
    'alichry' => [
        'authorization' => [
            'chain' => [
                'global' => [
                    'redirect_route' => 'login',
                    'authentication_service' => AuthenticationService::class,
                    'access_control_list' => 'identity'
                ]
            ]
        ]
    ],
    // ...
];


use AliChry\Laminas\Authorization\Annotation\Authorization;

/**
 * Class-level annotations are treated as a fallback. First method annotations
 * are consulted, if no relevant method annotations were found then
 * class-level annotations are utilized.
 *
 * Default class policy is to reject unspecified links:
 * @Authorization(policy="Reject")
 *
 * Require valid authentication status for "global" link:
 * @Authorization(link="global", policy="Authenticate")
 */
class ApplicationController
{
    /**
     * Allow this resource to be publicly accessible:
     * @Authorization(policy="Allow")
     * The above will override class-level annotations, and since the link
     * property was omitted, it will apply to all links.
     */
    public function indexAction()
    {
    }
        
    /**
     * Allow this resource to be accessible by entities granted the "delete"
     * permission under the "global" link:
     * @Authorization(link="global", policy="Authorize", permission="delete")
     */
    public function deleteAction()
    {
    }

    /**
     * No annotations are defined for this method, the class annotations
     * will be used as a fallback. This method