Applies a scope for $resource.

If $action is left undefined, the current controller action will
be used.

@param object $resource The resource to apply a scope to.
@param string|null $action The action to apply a scope for.
@return object
422553
public function applyScope($resource, $action = null)
    {
        $request = $this->getController()->request;
        if ($action === null) {
            $action = $this->getDefaultAction($request);
        }
        $identity = $this->getIdentity($request);

        return $identity->applyScope($action, $resource);
    }
1221633
public function run($action, $request=null) {
		$this->action = $action;
		$this->defaultView = $action;

		if($request === null)
			$request = new Request;
		$this->request = $request;
		$this->response = new Response;
		$this->response->setRequest($this->request);

		#before filters
		$result = null;
		foreach($this->beforeFilters as $filter) {
			if(($result = $filter($this, $request)) !== null)
				break;
		}

		if($result === null) {
			if(($result = $this->before($request)) === null)
				$result = $this->doRun($action, [$request]);
		}

		$this->after($request, $result);

		#after filters
		foreach($this->afterFilters as $filter)
			$filter($this, $request, $result);

		if($result instanceof Response)
			return $result;
		elseif(is_string($result))
			return $this->response->setContent($result);

		return $this->response;
	}
638338
public function getRouteName($resourceName = null, $action)
    {
        $resourceName = $resourceName ?? $this->resourceName;
        return $this->alias.$resourceName.'.'.$action;
    }
232866
public function resolveURL($resource)
    {
        // Skip blank resources
        if (empty($resource)) {
            return null;
        }

        // Resolve resource to reference
        $resource = $this->resolveResource($resource);

        // Resolve resource to url
        /** @var ResourceURLGenerator $generator */
        $generator = Injector::inst()->get(ResourceURLGenerator::class);
        return $generator->urlForResource($resource);
    }
369187
public static function href($controller = null, string $action = null, array $params = null): string
    {
        return Application::route()->href($controller, $action, $params);
    }
943301
protected function authorizationFailedError($resource, $action) {
    // when reading only log the error to avoid errors on the display
    $msg = ObjectFactory::getInstance('message')->
            getText("Authorization failed for action '%0%' on '%1%'.", [$action, $resource]);
    if ($action == PersistenceAction::READ) {
      self::$logger->error($msg."\n".ErrorHandler::getStackTrace());
    }
    else {
      throw new AuthorizationException($msg);
    }
  }
575001
public function performAction($controller, $action) {
		// Replace namespace with directory separator
		$controllerFile = str_replace("\\", DIRECTORY_SEPARATOR, $controller);

		// Check if controller exists
		if ( false == is_file( $controllerLocation = APP . 'Controllers/' . $controllerFile . '.php' ) )
			throw new ControllerNotFoundException();

		// Include and init the controller
		$controllerClass = "\\Application\\Controllers\\{$controller}";
		$controllerObj = new $controllerClass($this);

		// Check if the action exists
		if ( 'Errors' != $controller && false == method_exists($controllerObj, $action.= "Action" ) )
			throw new ActionNotFoundException();
		// Check if the error display action exists
		elseif ( $controller == $this->defaultRoute['_controller'] && false == method_exists($controllerObj, $action = "display" . $action ) )
			throw new ErrorActionNotFoundException();

		// Run the action
		$data = $controllerObj->{$action}();

		// Data fetching
		if ( false === $controllerObj->__returnActionPerformed ):
			// Format returned data
			if ( false == is_array( $data ) )
				$data = (array) $data;

			// Start reflection for data loading
			$ref = new \ReflectionObject($controllerObj);
			$properties = $ref->getProperties(\ReflectionProperty::IS_PUBLIC);
			$controllerData = array();

			// Get public data
			foreach ( $properties as $property ):
				// Don't add internal variabels
				if ( '__returnActionPerformed' == $property->getName() )
					continue;

				// Add property to controller data
				$controllerData[$property->getName()] = $property->getValue($controllerObj);
			endforeach;

			// Merge data from controller and action
			$data = array_merge($controllerData, $data);
		endif;

		// Return the object
		return $data;
	}
511579
public function RelativeLink($action = null)
    {
        return Controller::join_links(
            Director::baseURL(),
            $this->Link($action)
        );
    }
424571
public function setAction($action)
        {
            if (null !== $action && !is_string($action)) {
                throw new Exception(
                    'Invalid argument: $action must be a string or null'
                );
            }

            $this->_action    = $action;
            $this->_hrefCache = null;

            return $this;
        }
1187627
public function check($action = 'resource')
    {
        $this->setCurrentAction($action)->targets->each(function (
            Target $target
        ) {
            $target->check($target);
        });

        $this->notify();

        return $this;
    }
494478
public function can($action, $resource = null, $resourceId = null)
    {
        $this->assertLockInstanceIsSet();

        return $this->lock->can($action, $resource, $resourceId);
    }
940156
public function Link($action = null)
    {
        return Controller::join_links(
            parent::Link(),
            $this->config()->url_segment,
            $action
        );
    }
1179995
public function any($uri, $action = null) {
        return $this->addRoute(Route::HTTP_METHODS, $uri, $action);
    }
1061597
public static function createKey($resource, $context, $action) {
    return $resource.self::$actionDelimiter.$context.self::$actionDelimiter.$action;
  }
337687
public function setAction($action)
    {
        $this->action = is_string($action) ? $action : $this->$action;
        $this->prepareUrl();

        return $this;
    }
421373
public function checkAccess($action, $resource)
    {
        if ((is_null($resource) || is_null($resource->getId())) && (empty($action) || in_array(strtolower($action), array('list', 'create', 'post')))) {
            return true;
        }

        if (!is_null($resource)) {
            $query = $this->createQueryBuilder();
            $query->andWhere($query->getRootAliases()[0] . '.id = ' . $this->addNamedParameter('id', $resource, $query));
            $result = $this->getOneOrNullResultFromQueryBuilder($query);
            if ($result) {
                return true;
            } else {
                $this->throwException('Access for this resource has been denied', 'access-denied');
            }
        }
    }
738516
protected function actionReferencesController($action)
    {
        if ($action instanceof Closure) {
            return false;
        }

        return is_string($action) || is_string(array_get($action, 'uses'));
    }