Ejemplo n.º 1
0
 public function getControllerPluginConfig()
 {
     return array('factories' => array('mailerZF2' => function ($sm) {
         $serviceLocator = $sm->getServiceLocator();
         $config = $serviceLocator->get('Configuration');
         if (!isset($config['email'])) {
             throw new \Exception('Configurazione delle mails non impostata.');
         }
         $renderer = new \Zend\View\Renderer\PhpRenderer();
         $resolver = new \Zend\View\Resolver\TemplatePathStack();
         $resolver->setPaths(array(__DIR__ . '/../../../module/'));
         $renderer->setResolver($resolver);
         $controllerPlugin = new Controller\Plugin\Mailer($renderer);
         $mail = $config['email']['credentials']['from_mail'];
         $name = $config['email']['credentials']['from_name'];
         $controllerPlugin->setFrom($mail, $name);
         switch ($config['email']['transport']) {
             case 'smtp':
                 $transport = new \Zend\Mail\Transport\Smtp();
                 $options = new \Zend\Mail\Transport\SmtpOptions(array('host' => $config['email']['smtp']['host'], 'port' => $config['email']['smtp']['port'], 'connection_class' => $config['email']['smtp']['connection_class'], 'connection_config' => $config['email']['smtp']['connection_config']));
                 $transport->setOptions($options);
                 $controllerPlugin->setMailTransport($transport);
                 break;
             case 'sendmail':
             default:
                 $transport = new \Zend\Mail\Transport\Sendmail();
                 $controllerPlugin->setMailTransport($transport);
                 break;
         }
         return $controllerPlugin;
     }));
 }
Ejemplo n.º 2
0
 /**
  * Get a working renderer.
  *
  * @param array  $plugins Custom VuFind plug-ins to register
  * @param string $theme   Theme directory to load from
  *
  * @return \Zend\View\Renderer\PhpRenderer
  */
 protected function getPhpRenderer($plugins = [], $theme = 'blueprint')
 {
     $resolver = new \Zend\View\Resolver\TemplatePathStack();
     // This assumes that all themes will be testing inherit directly
     // from root with no intermediate themes.  Probably safe for most
     // test situations, though other scenarios are possible.
     $resolver->setPaths([$this->getPathForTheme('root'), $this->getPathForTheme($theme)]);
     $renderer = new \Zend\View\Renderer\PhpRenderer();
     $renderer->setResolver($resolver);
     if (!empty($plugins)) {
         $pluginManager = $renderer->getHelperPluginManager();
         foreach ($plugins as $key => $value) {
             $pluginManager->setService($key, $value);
         }
     }
     return $renderer;
 }
Ejemplo n.º 3
0
<?php

require_once './autoloader.php';
use Zend\Mail\Message;
use Zend\Mail\Transport;
use Zend\Di\Di;
use Zend\Di\Config as DiConfig;
$diConfig = array('instance' => array('Zend\\Mail\\Transport\\FileOptions' => array('parameters' => array('path' => __DIR__)), 'Zend\\Mail\\Transport\\File' => array('injections' => array('Zend\\Mail\\Transport\\FileOptions')), 'Zend\\Mail\\Transport\\SmtpOptions' => array('parameters' => array('name' => 'sendgrid', 'host' => 'smtp.sendgrid.net', 'port' => 25, 'connectionClass' => 'login', 'connectionConfig' => array('username' => '*****@*****.**', 'password' => 'password'))), 'Zend\\Mail\\Message' => array('parameters' => array('headers' => 'Zend\\Mail\\Headers', 'Zend\\Mail\\Message::setTo:emailOrAddressList' => '*****@*****.**', 'Zend\\Mail\\Message::setTo:name' => 'EvaEngine', 'Zend\\Mail\\Message::setFrom:emailOrAddressList' => '*****@*****.**', 'Zend\\Mail\\Message::setFrom:name' => 'EvaEngine', 'setBody' => 'Zend\\View\\Renderer\\PhpRenderer::render')), 'Zend\\Mail\\Transport\\Smtp' => array('injections' => array('Zend\\Mail\\Transport\\SmtpOptions'))));
$di = new Di();
$di->configure(new DiConfig($diConfig));
$transport = $di->get('Zend\\Mail\\Transport\\Smtp');
$transport = $di->get('Zend\\Mail\\Transport\\Sendmail');
$transport = $di->get('Zend\\Mail\\Transport\\File');
$message = $di->get('Zend\\Mail\\Message');
$view = new Zend\View\Renderer\PhpRenderer();
$resolver = new Zend\View\Resolver\TemplatePathStack();
$resolver->setPaths(array('mailTemplate' => __DIR__));
$view->setResolver($resolver);
$viewModel = new Zend\View\Model\ViewModel();
$viewModel->setTemplate('mail/template')->setVariables(array('user' => 'AlloVince'));
$message->setSubject("Zend Mail with Template")->setBody($view->render($viewModel));
$transport->send($message);
Ejemplo n.º 4
0
 public function getResolverPaths()
 {
     $pathResolver = new \Zend\View\Resolver\TemplatePathStack();
     $arrayPathResolver = array($this->moduleName . '_layout' => $this->getPathLayout(), $this->moduleName . '_template' => $this->getPathViews() . DS . 'templates', $this->moduleName . '_helpers' => $this->getPathViews() . DS . 'helpers');
     return $pathResolver->setPaths($arrayPathResolver);
 }
Ejemplo n.º 5
0
 /**
  * Set module view root path to module/{module name}/view
  * Reset layout by config->module_namespace_layout_map
  * 
  * @return ViewHelperLoader
  */
 public function onDispatch(MvcEvent $e)
 {
     $routeParams = $e->getRouteMatch()->getParams();
     if (false === isset($routeParams['module']) || !$routeParams['module']) {
         return false;
     }
     $controller = $e->getTarget();
     if (!$controller instanceof \Zend\Mvc\Controller\AbstractActionController && !$controller instanceof \Zend\Mvc\Controller\AbstractRestfulController) {
         //Event should trigger after route matched and found controller
         throw new \Zend\Mvc\Exception\RuntimeException(printf('%s should be only trigger on mvc dispatch event', __METHOD__));
     }
     $object = new \ReflectionObject($controller);
     $controllerFullPath = $object->getFileName();
     $controllerClassname = $object->getName();
     $classRootPath = substr($controllerFullPath, 0, 0 - strlen($controllerClassname . '.php'));
     $moduleRootPath = $classRootPath . '..';
     $this->viewRootPath = $moduleRootPath . DIRECTORY_SEPARATOR . 'view';
     $moduleNamespace = isset($routeParams['moduleNamespace']) ? $routeParams['moduleNamespace'] : '';
     if ($moduleNamespace && $routeParams['moduleNamespace'] && $routeParams['moduleNamespace'] != $routeParams['module']) {
         $this->viewRootPath .= DIRECTORY_SEPARATOR . '_' . strtolower($routeParams['moduleNamespace']);
     }
     if ($moduleNamespace && isset($this->config['module_namespace_layout_map']) && !isset($this->config['layout']) && isset($this->config['module_namespace_layout_map'][ucfirst($moduleNamespace)])) {
         $viewModel = $this->getViewModel();
         $template = $viewModel->getTemplate();
         if ($template == 'layout/layout') {
             $controller->layout('layout/' . $moduleNamespace);
         }
     }
     $templatePathStack = new \Zend\View\Resolver\TemplatePathStack();
     //All path defined in config will be clear here
     $templatePathStack->setPaths(array($this->viewRootPath));
     $this->resolver->attach($templatePathStack);
 }