Inheritance: extends Model
コード例 #1
0
ファイル: TypePlugin.php プロジェクト: jarves/jarves
 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);
         }
     }
 }
コード例 #2
0
ファイル: PluginTest.php プロジェクト: jarves/jarves
 public function testPluginConfigArray()
 {
     $pluginArray = array('id' => 'listing', 'label' => 'News Listing', 'controller' => 'Publication\\Controller\\Plugin\\News:listing', 'routes' => array(array('pattern' => '{page}', 'defaults' => array('page' => 1), 'requirements' => array('page' => '\\d')), array('pattern' => '{slug}', 'requirements' => array('page' => '[^/]+'))), 'options' => array('template' => array('id' => 'template', 'label' => 'Template', 'type' => 'view', 'options' => array('directory' => '@PublicationBundle/news/list/'), 'selection' => array('template')), 'itemsPerPage' => array('id' => 'itemsPerPage', 'label' => 'Items per page', 'type' => 'number', 'default' => 10, 'selection' => array('itemsPerPage')), 'detailPage' => array('id' => 'detailPage', 'label' => 'Detail page', 'type' => 'object', 'object' => 'JarvesBundle:Node', 'selection' => array('detailPage'))));
     $plugin = new Plugin($pluginArray);
     $this->assertEquals($pluginArray, $plugin->toArray());
     $this->valueTest($plugin);
 }