setSingleton(Client::class, function () { return ClientBuilder::create()->build(); });*/ $container->setSingleton(MailerInterface::class, function () use ($app) { return $app->mailer; }); $container->setSingleton(ErrorHandler::class, function () use ($app) { return $app->errorHandler; }); $container->setSingleton(Queue::class, function () use ($app) { return $app->get('queue'); }); $container->setSingleton(Cache::class, function () use ($app) { return $app->cache; }); $container->setSingleton(ManagerInterface::class, function () use ($app) { return $app->authManager; }); $container->setSingleton(ContactService::class, [], [ $app->params['adminEmail'] ]); /*$container->setSingleton(Cart::class, function () use ($app) { return new Cart( new HybridStorage($app->get('user'), 'cart', 3600 * 24, $app->db), new DynamicCost(new SimpleCost()) ); }); $container->setSingleton(YandexMarket::class, [], [ new ShopInfo($app->name, $app->name, $app->params['frontendHostInfo']), ]);*/ $container->setSingleton(Newsletter::class, function () use ($app) { return new MailChimp( new \DrewM\MailChimp\MailChimp($app->params['mailChimpKey']), $app->params['mailChimpListId'] ); }); /*$container->setSingleton(SmsSender::class, function () use ($app) { return new LoggedSender( new SmsRu($app->params['smsRuKey']), \Yii::getLogger() ); });*/ $container->setSingleton(EventDispatcher::class, DeferredEventDispatcher::class); $container->setSingleton(DeferredEventDispatcher::class, function (Container $container) { return new DeferredEventDispatcher(new AsyncEventDispatcher($container->get(Queue::class))); }); $container->setSingleton(SimpleEventDispatcher::class, function (Container $container) { return new SimpleEventDispatcher($container, [ UserSignUpRequested::class => [UserSignupRequestedListener::class], UserSignUpConfirmed::class => [UserSignupConfirmedListener::class], //ProductAppearedInStock::class => [ProductAppearedInStockListener::class], //EntityPersisted::class => [ // ProductSearchPersistListener::class, // CategoryPersistenceListener::class, //], //EntityRemoved::class => [ // ProductSearchRemoveListener::class, // CategoryPersistenceListener::class, //], ]); }); $container->setSingleton(AsyncEventJobHandler::class, [], [ Instance::of(SimpleEventDispatcher::class) ]); /* $container->setSingleton(Filesystem::class, function () use ($app) { return new Filesystem(new Ftp($app->params['ftp'])); }); $container->set(ImageUploadBehavior::class, FlySystemImageUploadBehavior::class); */ // Connect common modules if (Yii::$app->db->schema->getTableSchema('{{%modules}}') !== null) { $modules = ModuleRecord::find()->andWhere(['type' => 'common'])->andWhere(['active' => 1])->all(); foreach ($modules as $module) { Yii::$app->setModule($module->name, [ 'class' => $module->class, ]); Yii::$app->getModule($module->name)->bootstrap(Yii::$app); } } } }