PHP code example of mohamedallou / mezzio-security

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

    

mohamedallou / mezzio-security example snippets


\Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory::class,



declare(strict_types=1);

namespace App\Factory;

use Laminas\EventManager\EventManager;
use Laminas\EventManager\EventManagerAwareInterface;
use Laminas\EventManager\LazyListener;
use Psr\Container\ContainerInterface;

class EventManagerFactory
{
    public function __invoke(ContainerInterface $container): EventManager
    {
        $events = $container->get('config')['events'] ?? [];

        $eventManager = new EventManager();

        foreach ($events as $eventName => $listenerClasses) {
            if (!is_string($eventName)) {
                continue;
            }

            $listenerClasses = is_array($listenerClasses) ? $listenerClasses : [$listenerClasses];
            foreach ($listenerClasses as $listenerClass) {
                //TODO: use LazyEvent Listener

                if (is_a($listenerClass, EventManagerAwareInterface::class, true)) {
                    /** @var callable&EventManagerAwareInterface $listener */
                    $listener = $container->get($listenerClass);
                    $listener->setEventManager($eventManager);
                } else {
                    $listener = new LazyListener(
                        [
                            'listener' => $listenerClass,
                            'method' => '__invoke'
                        ],
                        $container
                    );
                }

                if (!is_callable($listener)) {
                    continue;
                }

                $eventManager->attach($eventName, $listener);
            }
        }
        return $eventManager;
    }
}


$app->pipe(\Mezzio\Session\SessionMiddleware::class);
$app->pipe(\Mezzio\Router\Middleware\RouteMiddleware::class);