Пример #1
0
 /**
  * Instance of construct
  * 
  * @param string $layout
  * @param array $options
  */
 public function __construct($layout = 'email', array $options = array())
 {
     $this->frontController = \Zend_Controller_Front::getInstance();
     $resources = $this->frontController->getParam('bootstrap')->getOption('resources');
     if (isset($options['layout'])) {
         $this->layout = new \Zend_Layout($options['layout']);
     } elseif (isset($resources['layout'])) {
         $this->layout = new \Zend_Layout($resources['layout']);
     } else {
         $this->layout = new \Zend_Layout();
     }
     if (isset($options['view'])) {
         $this->layout->setView(new \Zend_View($options['view']));
     } elseif (isset($resources['view'])) {
         $this->layout->setView(new \Zend_View($resources['view']));
     } else {
         $this->layout->setView(new \Zend_View());
     }
     $scriptPath = APPLICATION_PATH . self::EMAIL_PATH;
     if (null !== $this->frontController->getModuleDirectory()) {
         $scriptPath = $this->frontController->getModuleDirectory() . self::EMAIL_PATH;
     }
     $this->layout->setLayout($layout);
     $this->setScriptPath($scriptPath);
 }
Пример #2
0
 /**
  * Prepare layout instance to be used
  *
  * @return void
  */
 private function _prepareLayout()
 {
     // set the view object
     $this->_layout->setView($this->view);
     // set the layout path
     $this->_layout->setLayoutPath($this->getApplicationPath() . '/layouts/scripts/');
 }
Пример #3
0
 /**
  *
  * Layout setter. If no layout indicated a new one is created.
  * @param Zend_Layout $layout
  */
 public function setLayout(Zend_Layout $layout = null)
 {
     if (isset($layout)) {
         $this->_layout = $layout;
         $this->_layout->setView($this->getView());
     } else {
         $this->getLayout();
     }
     return $this;
 }
Пример #4
0
 public function postDispatch()
 {
     $layouts = array_reverse($this->_layouts);
     $mvcLayout = Zend_Layout::getMvcInstance();
     $mvcContentKey = $mvcLayout->getContentKey();
     $content = $this->getResponse()->getBody();
     $view = $this->_cloneView();
     $layout = new Zend_Layout(array('layoutPath' => $mvcLayout->getLayoutPath(), 'viewSuffix' => $mvcLayout->getViewSuffix()));
     $layout->setView($view);
     foreach ($layouts as $layoutName) {
         $layout->setLayout($layoutName);
         $layout->{$mvcContentKey} = $this->getResponse()->getBody();
         $this->getResponse()->setBody($layout->render());
     }
 }
Пример #5
0
 /**
  * @return void
  */
 public function testViewAccessorsAllowSettingView()
 {
     $layout = new Zend_Layout();
     $view = new Zend_View();
     $layout->setView($view);
     $received = $layout->getView();
     $this->assertSame($view, $received);
 }
Пример #6
0
 /**
  * Render mail content using a view and template 
  * 
  * @param string $template
  * @param array $substitutions
  * @param array $placeholders
  * @param string $mode
  * @param string $layout
  * @param string $layoutPath
  */
 public function getMailContent($template, $substitutions, $placeholders = array(), $mode = 'html', $layout = null, $layoutPath = null)
 {
     // Create the return variable
     $return = '';
     // Create a view renderer
     $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
     $view = clone $viewRenderer->view;
     // Create a layout object and set it to app_path/emails/layouts
     if ($layoutPath === null || $layoutPath == '') {
         $layoutPath = PUBLIC_PATH . $view->templateUrl('') . 'email' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR;
     }
     // Create the layout object
     $layoutObject = new Zend_Layout($layoutPath);
     // Add the script path to the view that overrules the default path
     $application = $this->getFrontController()->getParam('application');
     $module = $this->getRequest()->getModuleName();
     $scriptPath = $view->layout()->getViewScriptPath() . '/views/' . $application . '/modules/' . $module . '/';
     if (!in_array($scriptPath, $view->getScriptPaths())) {
         $view->addScriptPath($scriptPath);
     }
     // Add the default email folder for the layout/template
     $view->addScriptPath(PUBLIC_PATH . $view->templateUrl('') . 'email' . DIRECTORY_SEPARATOR . 'views');
     // Assign all substitutions (e.g. view variables) to the view view
     foreach ($substitutions as $key => $sub) {
         $view->{$key} = $sub;
     }
     // Replace all placeholders
     if (is_array($placeholders)) {
         foreach ($placeholders as $key => $sub) {
         }
     }
     // Set the view object to the layout object
     $layoutObject->setView($view);
     // Initialize a default layout
     if ($layout === null || $layout == '') {
         $layout = 'default';
     }
     switch ($mode) {
         case 'html':
             // Render html version of template & assign to $return
             $layoutObject->content = $view->render($template . '.html.phtml');
             // Set the layout
             $layoutObject->setLayout('' . $layout . '.html');
             // Render the layout output
             $return = $layoutObject->render();
             // Assimilate the stylesheet in the html
             $stylesheet = $layoutPath . $layout . '.css';
             if (file_exists($stylesheet)) {
                 $stylesheetContent = file_get_contents($stylesheet);
                 $test = new CSSToInlineStyles($return, $stylesheetContent);
                 $return = $test->convert(true);
             }
             break;
         case 'text':
             // Render text version of template & assign to $return
             $layoutObject->content = $view->render($template . '.text.phtml');
             // Set the layout
             $layoutObject->setLayout('' . $layout . '.text');
             // Render the layout output
             $return = $layoutObject->render();
             break;
     }
     // Replace the placeholders in the content
     $return = $this->_replacePlaceholders($return, $placeholders);
     // all done, return output
     return $return;
 }
Пример #7
0
 /**
  * Set Options from an Array
  *
  * @param array $options
  * @return Bgy\Mail\Template Provides fluent interface
  */
 public function setOptions(array $options = array())
 {
     if (isset($options['view'])) {
         $view = $options['view'];
         if (is_string($view)) {
             $view = new $view();
         }
     } else {
         // Set default view to Zend_View
         $view = new \Zend_View();
     }
     unset($options['view']);
     if (isset($options['layout'])) {
         $layout = $options['layout'];
         if (is_string($layout)) {
             $layout = new $layout();
         }
     } else {
         // Default layout to Zend_Layout
         $layout = new \Zend_Layout();
     }
     if (isset($options['htmlRenderer'])) {
         $htmlRenderer = $options['htmlRenderer'];
         if (is_string($htmlRenderer)) {
             $htmlRenderer = new $htmlRenderer();
         }
     } else {
         // Default provided Html Renderer to convert Html to Text
         $htmlRenderer = new Template\Html\Renderer\SimpleText();
     }
     $this->setHtmlRenderer($htmlRenderer);
     unset($options['htmlRenderer']);
     $layout->setView($view);
     $this->setLayout($layout);
     $this->setView($view);
     unset($options['layout']);
     if (!isset($options['layoutScript'])) {
         // Default layout script name 'layout'
         $options['layoutScript'] = 'layout';
     }
     foreach ($options as $key => $value) {
         $method = 'set' . ucfirst($key);
         if (method_exists($this, $method)) {
             $this->{$method}($value);
         }
         unset($options[$key]);
     }
     return $this;
 }
 /**
  * Creates simulated resources and injects them into the given bootstrapper.
  *
  * @param Mol_Test_Bootstrap $bootstrapper
  */
 protected function injectResources(Mol_Test_Bootstrap $bootstrapper)
 {
     $bootstrapper->simulateResource('log', new Zend_Log($this->logWriter));
     $view = $this->createView();
     $bootstrapper->simulateResource('view', $view);
     $layout = new Zend_Layout();
     $layout->setView($view);
     $view->getHelper('layout')->setLAyout($layout);
     $bootstrapper->simulateResource('layout', $layout);
 }