Bolt\Configuration\ResourceManager::getApp PHP Method

getApp() public static method

Get the Bolt\Application object.
public static getApp ( ) : Silex\Application
return Silex\Application
    public static function getApp()
    {
        if (!static::$theApp) {
            $trace = debug_backtrace(false);
            $trace = $trace[0]['file'] . '::' . $trace[0]['line'];
            $message = sprintf("The Bolt 'Application' object isn't initialized yet so the container can't be accessed here: <code>%s</code>", $trace);
            throw new \RuntimeException($message);
        }
        return static::$theApp;
    }

Usage Example

Esempio n. 1
0
 /**
  * Returns [route name, route params] for url generation, or null for various reasons.
  *
  * @return array|null
  */
 public function getRouteNameAndParams()
 {
     if (empty($this->app)) {
         $this->app = ResourceManager::getApp();
     }
     if (empty($this->id)) {
         return null;
     }
     // No links for records that are 'viewless'
     if (isset($this->contenttype['viewless']) && $this->contenttype['viewless'] == true) {
         return null;
     }
     list($name, $config) = $this->getRouteConfig();
     if (!$config) {
         return null;
     }
     $slug = $this->getLinkSlug();
     $availableParams = array_filter(array_merge($config['defaults'] ?: [], $this->getRouteRequirementParams($config), ['contenttypeslug' => $this->contenttype['singular_slug'], 'id' => $this->id, 'slug' => $slug]));
     /** @var Route|null $route */
     $route = $this->app['routes']->get($name);
     if (!$route) {
         return null;
     }
     // Needed params as array keys
     $pathVars = $route->compile()->getPathVariables();
     $neededKeys = array_flip($pathVars);
     // Set the values of neededKeys from the availableParams.
     // This removes extra parameters that are not needed for url generation.
     $params = array_replace($neededKeys, array_intersect_key($availableParams, $neededKeys));
     return [$name, $params];
 }
All Usage Examples Of Bolt\Configuration\ResourceManager::getApp