getConfig() public method

Returns a configuration for a bundle.
public getConfig ( $bundleName ) : Bundle | null
$bundleName
return Jarves\Configuration\Bundle | null
Ejemplo n.º 1
0
 /**
  * Returns the namespace of the bundle of the object key.
  *
  * JarvesBundle/node => JarvesBundle.
  * bundleWithNameSpace/myObject => Bundle\With\Namespace.
  *
  * @param  string $objectKey
  *
  * @return string
  */
 public function getNamespace($objectKey)
 {
     $objectKey = Objects::normalizeObjectKey($objectKey);
     $temp = explode('/', $objectKey);
     $config = $this->jarves->getConfig($temp[0]);
     return $config ? $config->getBundleClass()->getNamespace() : null;
 }
Ejemplo n.º 2
0
 /**
  * Gets the item from the administration entry points defined in the config.json, by the given code.
  *
  * @param string  $code <bundleName>/news/foo/bar/edit
  *
  * @return EntryPoint
  */
 public function getEntryPoint($code)
 {
     if ('/' === $code) {
         return null;
     }
     $path = $code;
     if (substr($code, 0, 1) == '/') {
         $code = substr($code, 1);
     }
     if (false === strpos($code, '/')) {
         $path = '';
     }
     $bundleName = $code;
     if (false !== strpos($code, '/')) {
         $bundleName = substr($code, 0, strpos($code, '/'));
         $path = substr($code, strpos($code, '/') + 1);
     }
     //$bundleName = ucfirst($bundleName) . 'Bundle';
     $config = $this->jarves->getConfig($bundleName);
     if (!$path && $config) {
         //root
         $entryPoint = new EntryPoint();
         $entryPoint->setType(0);
         $entryPoint->setPath($code);
         $entryPoint->setChildren($config->getEntryPoints());
         $entryPoint->setBundle($config);
         return $entryPoint;
     }
     $entryPoint = null;
     if ($config) {
         while (!($entryPoint = $config->getEntryPoint($path))) {
             if (false === strpos($path, '/')) {
                 break;
             }
             $path = substr($path, 0, strrpos($path, '/'));
         }
     }
     return $entryPoint;
 }
Ejemplo n.º 3
0
 public function registerPluginRoutes(Node $page)
 {
     $domain = $this->pageStack->getDomain($page->getDomainId());
     $this->stopwatch->start('Register Plugin Routes');
     //add all router to current router and fire sub-request
     $cacheKey = 'core/node/plugins-' . $page->getId();
     $plugins = $this->cacher->getDistributedCache($cacheKey);
     if (null === $plugins) {
         $plugins = ContentQuery::create()->filterByNodeId($page->getId())->filterByType('plugin')->find();
         $this->cacher->setDistributedCache($cacheKey, serialize($plugins));
     } else {
         $plugins = unserialize($plugins);
     }
     /** @var $plugins Content[] */
     foreach ($plugins as $plugin) {
         if (!$plugin->getContent()) {
             continue;
         }
         $data = json_decode($plugin->getContent(), true);
         if (!$data) {
             $this->logger->alert(sprintf('On page `%s` [%d] is a invalid plugin `%d`.', $page->getTitle(), $page->getId(), $plugin->getId()));
             continue;
         }
         $bundleName = isset($data['module']) ? $data['module'] : @$data['bundle'];
         $config = $this->jarves->getConfig($bundleName);
         if (!$config) {
             $this->logger->alert(sprintf('Bundle `%s` for plugin `%s` on page `%s` [%d] does not not exist.', $bundleName, @$data['plugin'], $page->getTitle(), $page->getId()));
             continue;
         }
         $pluginDefinition = $config->getPlugin(@$data['plugin']);
         if (!$pluginDefinition) {
             $this->logger->alert(sprintf('In bundle `%s` the plugin `%s` on page `%s` [%d] does not not exist.', $bundleName, @$data['plugin'], $page->getTitle(), $page->getId()));
             continue;
         }
         if ($pluginRoutes = $pluginDefinition->getRoutes()) {
             foreach ($pluginRoutes as $idx => $route) {
                 $controller = $pluginDefinition->getController();
                 $defaults = array('_controller' => $route->getController() ?: $controller, '_jarves_is_plugin' => true, '_content' => $plugin, '_title' => sprintf('%s: %s', $bundleName, $pluginDefinition->getLabel()), 'options' => isset($data['options']) && is_array($data['options']) ? $data['options'] : [], 'jarvesFrontend' => true, 'nodeId' => $page->getId());
                 if ($route->getDefaults()) {
                     $defaults = array_merge($defaults, $route->getArrayDefaults());
                 }
                 $url = $this->pageStack->getRouteUrl($page->getId());
                 $this->routes->add('jarves_frontend_plugin_' . ($route->getId() ?: $plugin->getId()) . '_' . $idx, new SyRoute($url . '/' . $route->getPattern(), $defaults, $route->getArrayRequirements() ?: array(), [], '', [], $route->getMethods() ?: []));
             }
         }
     }
     $this->stopwatch->stop('Register Plugin Routes');
 }
Ejemplo n.º 4
0
 public function render()
 {
     if ($response = $this->pageStack->getPageResponse()->getPluginResponse($this->getContent())) {
         return $response->getContent();
     } elseif ($this->plugin) {
         $config = $this->jarves->getConfig($this->bundleName);
         if (!$config) {
             return sprintf('Bundle `%s` does not exist. You probably have to install this bundle.', $this->bundleName);
         }
         if ($this->pluginDef = $config->getPlugin($this->plugin['plugin'])) {
             $controller = $this->pluginDef->getController();
             if ($this->isPreview()) {
                 if (!$this->pluginDef->isPreview()) {
                     //plugin does not allow to have a preview on the actual action method
                     return ($config->getLabel() ?: $config->getBundleName()) . ': ' . $this->pluginDef->getLabel();
                 }
             }
             //create a sub request
             $request = new Request();
             $request->attributes->add(array('_controller' => $controller, '_content' => $this->getContent(), '_jarves_is_plugin' => true, 'options' => isset($this->plugin['options']) ? $this->plugin['options'] : array()));
             $dispatcher = $this->eventDispatcher;
             $callable = array($this, 'exceptionHandler');
             $fixResponse = array($this, 'fixResponse');
             $dispatcher->addListener(KernelEvents::EXCEPTION, $callable, 100);
             $dispatcher->addListener(KernelEvents::VIEW, $fixResponse, 100);
             ob_start();
             $response = $this->kernel->handle($request, HttpKernelInterface::SUB_REQUEST);
             //EventListener\PluginRequestListener converts all PluginResponse objects to PageResponses
             if ($response instanceof PageResponse) {
                 if ($pluginResponse = $response->getPluginResponse($this->getContent()->getId())) {
                     $response = $pluginResponse;
                 }
             }
             //                if ($response instanceof PageResponse) {
             //                    if ($response->getPluginResponse($this->getContent()->getId())) {
             //                        $response = $response->getPluginResponse($this->getContent()->getId());
             //                    }
             //                }
             $ob = ob_get_clean();
             $dispatcher->removeListener(KernelEvents::EXCEPTION, $callable);
             $dispatcher->removeListener(KernelEvents::VIEW, $fixResponse);
             return trim($ob) . $response->getContent();
         } else {
             return sprintf('Plugin `%s` in bundle `%s` does not exist. You probably have to install the bundle first.', $this->plugin['plugin'], $this->bundleName);
         }
     }
 }
Ejemplo n.º 5
0
 public function importObjectRoutes()
 {
     foreach ($this->jarves->getBundles() as $bundleName => $bundle) {
         if ($this->jarves->isJarvesBundle($bundleName)) {
             if (!($config = $this->jarves->getConfig($bundleName))) {
                 continue;
             }
             if ($objects = $config->getObjects()) {
                 foreach ($objects as $object) {
                     if ($object->isExcludeFromREST()) {
                         continue;
                     }
                     $objectName = $config->getName() . '/' . lcfirst($object->getId());
                     $pattern = '%jarves_admin_prefix%/object/' . $objectName;
                     $this->setupRoutes($config, $object->getFinalApiController(), $pattern, $object->getKey(), $object);
                     //maybe in v1.1
                     //$this->setupRelationRoutes($pattern, $object);
                 }
             }
         }
     }
 }