Commit 332177b0 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Corrections pour passer à ZF3.

parent 56508404
Loading
Loading
Loading
Loading
+29 −6
Changes for src/BjyAuthorize/Guard/AbstractGuard.php: 29 added lines, 6 removed lines.
Original line number Diff line number Diff line
<?php
/**
 * BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize)
 *
 * @link https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository
 * @license http://framework.zend.com/license/new-bsd New BSD License
 */

namespace BjyAuthorize\Guard;

@@ -37,6 +31,35 @@ abstract class AbstractGuard extends AbstractListenerAggregate implements
    {
        $this->serviceLocator = $serviceLocator;

        $this->setConfig($rules);
    }

    /**
     * @var array
     */
    protected $config = [];

    /**
     * @param array $config
     */
    public function setConfig(array $config)
    {
        $this->config = $config;
    }

    /**
     * @return mixed
     */
    public function processConfig()
    {
        $this->makeRules($this->config);
    }

    /**
     * @param array $rules
     */
    protected function makeRules(array $rules)
    {
        foreach ($rules as $rule) {
            $rule['roles']  = (array) $rule['roles'];
            $rule['action'] = isset($rule['action']) ? (array) $rule['action'] : array(null);
+7 −10
Changes for src/BjyAuthorize/Module.php: 7 added lines, 10 removed lines.
Original line number Diff line number Diff line
<?php
/**
 * BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize)
 *
 * @link https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository
 * @license http://framework.zend.com/license/new-bsd New BSD License
 */

namespace BjyAuthorize;

use Zend\EventManager\AbstractListenerAggregate;
use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
@@ -42,10 +37,12 @@ class Module implements
        $guards         = $serviceManager->get('BjyAuthorize\Guards');

        foreach ($guards as $guard) {
            $app->getEventManager()->attach($guard);
            /** @var AbstractListenerAggregate $guard */
            $guard->attach($app->getEventManager());
        }

        $app->getEventManager()->attach($strategy);
        /** @var AbstractListenerAggregate $strategy */
        $strategy->attach($app->getEventManager());
    }

    /**
@@ -56,7 +53,7 @@ class Module implements
        return array(
            'factories' => array(
                'isAllowed' => function (AbstractPluginManager $pluginManager) {
                    $serviceLocator = $pluginManager->getServiceLocator();
                    $serviceLocator = $pluginManager;
                    /* @var $authorize \BjyAuthorize\Service\Authorize */
                    $authorize = $serviceLocator->get('BjyAuthorize\Service\Authorize');

@@ -74,7 +71,7 @@ class Module implements
        return array(
            'factories' => array(
                'isAllowed' => function (AbstractPluginManager $pluginManager) {
                    $serviceLocator = $pluginManager->getServiceLocator();
                    $serviceLocator = $pluginManager;
                    /* @var $authorize \BjyAuthorize\Service\Authorize */
                    $authorize = $serviceLocator->get('BjyAuthorize\Service\Authorize');

+16 −6
Changes for src/BjyAuthorize/Provider/Rule/Config.php: 16 added lines, 6 removed lines.
Original line number Diff line number Diff line
<?php
/**
 * BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize)
 *
 * @link https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository
 * @license http://framework.zend.com/license/new-bsd New BSD License
 */

namespace BjyAuthorize\Provider\Rule;

@@ -35,4 +29,20 @@ class Config implements ProviderInterface
    {
        return $this->rules;
    }

    /**
     * @param array $config
     */
    public function setConfig(array $config)
    {
        $this->rules = $config;
    }

    /**
     * @return mixed
     */
    public function processConfig()
    {
        // nop
    }
}
+10 −6
Changes for src/BjyAuthorize/Provider/Rule/ProviderInterface.php: 10 added lines, 6 removed lines.
Original line number Diff line number Diff line
<?php
/**
 * BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize)
 *
 * @link https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository
 * @license http://framework.zend.com/license/new-bsd New BSD License
 */

namespace BjyAuthorize\Provider\Rule;

@@ -20,4 +14,14 @@ interface ProviderInterface
     * @return array
     */
    public function getRules();

    /**
     * @param array $config
     */
    public function setConfig(array $config);

    /**
     * @return mixed
     */
    public function processConfig();
}
+7 −7
Changes for src/BjyAuthorize/Service/BaseProvidersServiceFactory.php: 7 added lines, 7 removed lines.
Original line number Diff line number Diff line
<?php
/**
 * BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize)
 *
 * @link https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository
 * @license http://framework.zend.com/license/new-bsd New BSD License
 */

namespace BjyAuthorize\Service;

use BjyAuthorize\Provider\Rule\ProviderInterface;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
@@ -36,7 +31,12 @@ abstract class BaseProvidersServiceFactory implements FactoryInterface

        foreach ($config[static::PROVIDER_SETTING] as $providerName => $providerConfig) {
            if ($container->has($providerName)) {
                $providers[] = $container->get($providerName);
                $provider = $container->get($providerName);
                if ($provider instanceof ProviderInterface) {
                    $provider->setConfig($providerConfig);
                    $provider->processConfig();
                }
                $providers[] = $provider;
            } else {
                $providers[] = new $providerName($providerConfig, $container);
            }