$dispatcher->setEventsManager($eventsManager); // Attach the listener $eventsManager->attach('dispatch', new ControllersListener($di)); return $dispatcher; }); /** * Set the timeService */ $di->setShared('timeService', function () use($config) { return new TimeService($config->timeService->toArray()); }); /** * Set the User Service */ $di->setShared('user', function () use($config, $di) { $user = new UserService($config->user->toArray()); $user->setDi($di); $eventsManager = $di->get('eventManager'); // Set the event manager for user service $user->setEventsManager($eventsManager); // Attach the listener $eventsManager->attach('user', new AuthListener()); return $user; }); /** * Set the Asset manager */ $di->setShared('assetManager', function () use($config) { return new AssetManager($config->assetManager->toArray()); }); // Set the Widget manager
<?php /** * Created by Rem. * Author: Dmitry Kushneriv * Email: remkwadriga@yandex.ua * Date: 10-08-2015 * Time: 12:27 PM */ use components\UserService; $db = (require __DIR__ . '/db.php'); $routes = (require __DIR__ . '/routes.php'); return ['request' => ['cookieValidationKey' => 'hvb6xPBhQBgSjo2TsfOSOoAsKfSguOri'], 'errorHandler' => ['errorAction' => 'landing/error/index'], 'cache' => ['class' => 'yii\\caching\\FileCache'], 'mailer' => ['class' => 'yii\\swiftmailer\\Mailer', 'useFileTransport' => true], 'urlManager' => ['class' => 'yii\\web\\UrlManager', 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => $routes, 'enableStrictParsing' => true], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [['class' => 'yii\\log\\FileTarget', 'levels' => ['error', 'warning']]]], 'db' => $db, 'timeService' => ['class' => 'components\\TimeService'], 'user' => ['class' => UserService::className(), 'identityClass' => 'models\\User', 'enableAutoLogin' => true, 'on ' . UserService::EVENT_AFTER_LOGIN => ['models\\User', 'afterSuccessLogin']], 'view' => ['class' => 'components\\View'], 'authManager' => ['class' => 'components\\AuthManager']];