Middleware to be used in before()
@param Application $app
@param string $scopeName
@return JsonResponse
9053
protected function requireScope(Application $app, $scopeName)
    {
        /** @var ResourceServer $server */
        $server = $app[ResourceServer::class];
        if ($response = $this->requireAuthorization($app)) {
            return $response;
        }
        $accessToken = $server->getAccessToken();
        if (!$accessToken->hasScope($scopeName)) {
            return new JsonResponse(
                [
                    'error' => 'UNAUTHORIZED',
                    'message' => 'Token does not contain scope: '.$scopeName
                ],
                Response::HTTP_FORBIDDEN
            );
        }
    }
1069126
private function resolveAbstractToClassName(Application $app, $abstract)
    {
        $result = null;
        try {
            $instance = $app->make($abstract);
            if (is_object($instance)) {
                $className = get_class($instance);
                if (ltrim($abstract, '\\') !== $className) {
                    $result = $className;
                }
            }
        } catch (Exception $e) {
        } catch (Throwable $e) {
        }

        return $result;
    }
140326
private function checkInstall(Application $app, Request $request)
    {
        if (!$app->isInstalled()) {
            if (
                !$request->matches('/install/*')
                && $request->getPath() != '/install'
                && !$request->matches('/ccm/assets/localization/*')
            ) {
                $manager = $app->make('Concrete\Core\Url\Resolver\Manager\ResolverManager');
                $response = new RedirectResponse($manager->resolve(['install']));

                return $response;
            }
        }
    }
990443
protected function callAfterCallbacks(Application $app)
    {
        foreach ($this->_afterCallbacks as $callback) {
            call_user_func($callback, $app);
        }
    }
64959
public function extendCache(Application $app)
    {
        $app->resolving('cache', function(CacheManager $cache) {
            $cache->extend('memcache', function ($app) {
                return $app['memcache.store'];
            });
        });
    }
173749
public function getRecordsToSubstitute(Application $app, $includeReason = false)
    {
        $merged = [];
        /** @var LazaretCheck $check */
        foreach($this->getChecks() as $check) {
            /** @var record_adapter $record */
            $conflicts = $check->listConflicts($app);
            foreach ($conflicts as $record) {
                if($includeReason) {
                    if (!array_key_exists($record->getRecordId(), $merged)) {
                        $merged[$record->getRecordId()] = [
                            'record' => $record,
                            'reasons' => []
                        ];
                    }
                    $merged[$record->getRecordId()]['reasons'][$this->getCheckerName($check)] = $check->getReason($app['translator']);
                }
                else {
                    $merged[$record->getRecordId()] = $record;
                }
            }
        }

        return $merged;
    }
50516
public function deleteApp(Request $request, ApiApplication $application)
    {
        $this->assertJsonRequestFormat($request);

        $this->getApiApplicationManipulator()->delete($application);

        return $this->app->json(['success' => true]);
    }
720723
public function bootstrap(Application $app)
    {
        $uri = $app->make('config')->get('app.url', 'http://localhost');

        $components = parse_url($uri);

        $server = $_SERVER;

        if (isset($components['path'])) {
            $server = array_merge($server, [
                'SCRIPT_FILENAME' => $components['path'],
                'SCRIPT_NAME' => $components['path']
            ]);
        }

        $app->instance('request', Request::create(
            $uri,
            'GET',
            [],
            [],
            [],
            $server
        ));
    }
1337339
public function beforeRun($app)
    {
        foreach ($app->tags as $name => $config) {
            TagParser::inject($name, $config);
        }
        
        foreach ($this->getModules() as $id => $module) {
            foreach ($module->urlRules as $key => $rule) {
                if (is_string($key)) {
                    $this->_urlRules[$key] = $rule;
                } else {
                    $this->_urlRules[] = $rule;
                }
            }
            
            // get all api rules (since 1.0.10)
            foreach ($module->apiRules as $endpoint => $rule) {
                $this->_apiRules[$endpoint] = $rule;
            }
            
            /**
             * 'api-admin-user' => 'admin\apis\UserController',
             * 'api-cms-navcontainer' => 'admin\apis\NavContainerController'
             */
            foreach ($module->apis as $alias => $class) {
                $this->_apis[$alias] = ['class' => $class, 'module' => $module];
            }
            
            foreach ($module->tags as $name => $config) {
                TagParser::inject($name, $config);
            }
        }
    }
1043373
protected function getLazaretSession(Application $app)
    {
        $lazaretSession = new LazaretSession();

        $app['orm.em']->persist($lazaretSession);
        $app['orm.em']->flush();

        return $lazaretSession;
    }
95421
protected function checkRbacModuleInstalled(Application $app)
    {
        if ($app instanceof WebApplication) {
            return $app->hasModule('rbac') && $app->getModule('rbac') instanceof RbacWebModule;
        } else {
            return $app->hasModule('rbac') && $app->getModule('rbac') instanceof RbacConsoleModule;
        }
    }
48851
public function getScope($scope)
    {
        if (!isset($this->allScopes[$scope])) {
            throw new ApplicationException('No definition for scope ' . $scope);
        }

        return $this->allScopes[$scope];
    }
259414
public static ApplicationRequest createApplicationRequest(String applicationName) {
		ApplicationRequest applicationRequest = new ApplicationRequest();
		applicationRequest.setApplicationName(applicationName);

		return applicationRequest;
	}
512220
public function defaultViewAction(Application $app, Request $request, $id)
    {
        return $this->renderView($app, array(
            'entity' => $app->getRepository($this->getModelName())->find($id),
        ));
    }
604404
public function defaultDeleteAction(Application $app, Request $request, $id)
    {
        return $this->delete($app, $request, $id);
    }
1189830
public function beforeRequest(Request $request, Application $app)
    {
        $this->root = $request->attributes->get('_root');
    }
951363
public function getAppControllersMethod($methodName, $scope = '')
    {
        $methods = [];
        
        if ($this->appControllerRefls) {
            foreach ($this->appControllerRefls as $appRefl) {
                if ($appRefl->hasMethod($methodName)) {
                    $method = $appRefl->getMethod($methodName);
                    
                    if ($this->isApplicationController($method->getDeclaringClass()->getName())) {
                        if ($scope) {
                            $isScope = 'is' . ucfirst($scope);
                            if (!$method->$isScope()) {
                                continue;
                            }
                        }
                        $methods[] = $method->getClosure($this);
                    }
                }
            }
        }
        
        return $methods;
    }