Zend\Expressive\Application::getContainer PHP Method

getContainer() public method

If no IoC container is registered, we raise an exception.
public getContainer ( ) : Interop\Container\ContainerInterface
return Interop\Container\ContainerInterface
    public function getContainer()
    {
        if (null === $this->container) {
            throw new Exception\ContainerNotRegisteredException();
        }
        return $this->container;
    }

Usage Example

 public function up(Application $app, EntityManager $em)
 {
     $accountService = $app->getContainer()->get(AccountService::class);
     /** @var AccountService $accountService */
     $appAccessAccountService = $app->getContainer()->get(AccountAppAccessService::class);
     /** @var AccountAppAccessService $account */
     $all = $accountService->createAccount('*****@*****.**', self::ACCOUNT_PASSWORD);
     $admin = $accountService->createAccount('*****@*****.**', self::ACCOUNT_PASSWORD);
     $reports = $accountService->createAccount('*****@*****.**', self::ACCOUNT_PASSWORD);
     $feedback = $accountService->createAccount('*****@*****.**', self::ACCOUNT_PASSWORD);
     $ac_all = new AccountAppAccess($all);
     $ac_all->allowAdmin();
     $ac_all->allowFeedback();
     $ac_all->allowReports();
     $ac_admin = new AccountAppAccess($admin);
     $ac_admin->allowAdmin();
     $ac_reports = new AccountAppAccess($reports);
     $ac_reports->allowReports();
     $ac_feedback = new AccountAppAccess($feedback);
     $ac_feedback->allowFeedback();
     $appAccessAccountService->applyAppAccess($ac_all);
     $appAccessAccountService->applyAppAccess($ac_admin);
     $appAccessAccountService->applyAppAccess($ac_reports);
     $appAccessAccountService->applyAppAccess($ac_feedback);
     self::$accounts = ['all' => $all, 'admin' => $admin, 'reports' => $reports, 'feedback' => $feedback];
 }
All Usage Examples Of Zend\Expressive\Application::getContainer