Skip to content

Commit

Permalink
Merge 556b0a4 into 2c7f98d
Browse files Browse the repository at this point in the history
  • Loading branch information
kilip committed Jan 24, 2018
2 parents 2c7f98d + 556b0a4 commit 17a1525
Show file tree
Hide file tree
Showing 23 changed files with 5,856 additions and 90 deletions.
5 changes: 4 additions & 1 deletion module/Core/src/Core/Controller/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public function preDispatch(MvcEvent $e)
}
}

/**
* @return null|object
*/
protected function getFile()
{
$fileStoreName = $this->params('filestore');
Expand All @@ -82,7 +85,7 @@ protected function getFile()
} catch (\Exception $e) {
$response->setStatusCode(404);
$this->getEvent()->setParam('exception', $e);
return;
return null;
}
$fileId = $this->params('fileId', 0);
if (preg_match('/^(.*)\..*$/', $fileId, $baseFileName)) {
Expand Down
25 changes: 6 additions & 19 deletions module/Core/src/Core/Controller/Plugin/ConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
namespace Core\Controller\Plugin;

use Interop\Container\ContainerInterface;
use Interop\Container\Exception\ContainerException;
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
use Zend\ServiceManager\Exception\ServiceNotFoundException;
use Zend\ServiceManager\Factory\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Settings\Repository\Settings;
use Zend\Mvc\MvcEvent;
use Zend\EventManager\EventManager;
use Core\Controller\Plugin\Config;

/**
* Create new Config plugin
*
* @package Core\Controller\Plugin
* @author Anthonius Munthi <me@itstoni.com>
*/
class ConfigFactory implements FactoryInterface
{
public function __invoke( ContainerInterface $container, $requestedName, array $options = null )
Expand All @@ -22,15 +20,4 @@ public function __invoke( ContainerInterface $container, $requestedName, array $

return $plugin;
}

/**
* Create the settings service
*
* @param ServiceLocatorInterface $serviceLocator
* @return Config
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator,Config::class);
}
}
52 changes: 42 additions & 10 deletions module/Core/src/Core/Controller/Plugin/ContentCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,68 @@

namespace Core\Controller\Plugin;

use Zend\Mvc\Controller\Plugin\PluginInterface;
use Zend\EventManager\EventInterface;
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
//use Zend\Stdlib\DispatchableInterface as Dispatchable;
//use Zend\EventManager\Event;
//use Zend\Stdlib\Parameters;
use Zend\View\Model\ViewModel;

/**
* Class ContentCollector
*
* @package Core\Controller\Plugin
* @author Anthonius Munthi <me@itstoni.com>
*/
class ContentCollector extends AbstractPlugin
{

/**
* @var string
*/
protected $_captureTo;

/**
* @var string
*/
protected $_template;


/**
* ContentCollector constructor.
*/
public function __construct()
{
$this->_captureTo = 'content_';
}


/**
* Setting the template name to use
*
* @param string $template
* @return $this
*/
public function setTemplate($template)
{
$this->_template = $template;
return $this;
}


/**
* Setting capture to
*
* @param $captureTo
* @return $this
*/
public function captureTo($captureTo)
{
$this->_captureTo = $captureTo;
return $this;
}


/**
* Trigger capture event
*
* @param EventInterface $event
* @param mixed|null $target
*
* @return ViewModel
*/
public function trigger($event, $target = null)
{
if (empty($this->_template) || !is_string($this->_template)) {
Expand All @@ -54,7 +86,7 @@ public function trigger($event, $target = null)
$response = new ViewModel(array('target' => $target));
$response->setTemplate($template);
}
$viewModel->addChild($response, $this->_captureTo . $i);
$viewModel->addChild($response, $this->_captureTo . $i);
}

return $viewModel;
Expand Down
119 changes: 90 additions & 29 deletions module/Core/src/Core/Controller/Plugin/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
namespace Core\Controller\Plugin;

use Interop\Container\ContainerInterface;
use Zend\EventManager\EventManagerInterface;
use Zend\Log\LoggerInterface;
use Zend\Mail\Transport\TransportInterface;
use Zend\ModuleManager\ModuleManagerInterface;
use Zend\Mvc\Controller\Plugin\PluginInterface;
use Zend\Stdlib\DispatchableInterface as Dispatchable;
use Zend\Mail\Message;
Expand All @@ -11,16 +15,10 @@
use Zend\EventManager\Event;
use Zend\Stdlib\Parameters;
use Zend\Stdlib\ArrayUtils;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\View\Resolver\ResolverInterface;

class mail extends Message implements PluginInterface
class Mail extends Message implements PluginInterface
{

/**
* @var ContainerInterface
*/
protected $serviceManager;

/**
* @var Dispatchable
*/
Expand All @@ -29,19 +27,57 @@ class mail extends Message implements PluginInterface
/**
* @var array
*/
protected $param;
protected $param = array();

/**
* @var array
*/
protected $config;
protected $config = array();

/**
* @var LoggerInterface
*/
protected $mailLogger;

/**
* @var ResolverInterface
*/
protected $viewResolver;

/**
* @var EventManagerInterface
*/
protected $eventManager;

/**
* @var ModuleManagerInterface
*/
protected $moduleManager;

/**
* @var TransportInterface
*/
protected $transport;

/**
* @param ContainerInterface $serviceManager
* Mail constructor.
* @param LoggerInterface $mailLogger
* @param ResolverInterface $viewResolver
* @param EventManagerInterface $eventManager
* @param ModuleManagerInterface $moduleManager
*/
public function __construct(ContainerInterface $serviceManager)
public function __construct(
LoggerInterface $mailLogger,
ResolverInterface $viewResolver,
EventManagerInterface $eventManager,
ModuleManagerInterface $moduleManager
)
{
$this->serviceManager = $serviceManager;
$this->mailLogger = $mailLogger;
$this->viewResolver = $viewResolver;
$this->eventManager = $eventManager;
$this->moduleManager = $moduleManager;
$this->transport = new Sendmail();
}

/**
Expand All @@ -64,7 +100,28 @@ public function getController()
{
return $this->controller;
}


/**
* Set mail transport to be use
*
* @param TransportInterface $transport
* @return $this
*/
public function setTransport(TransportInterface $transport)
{
$this->transport = $transport;

return $this;
}

/**
* @return TransportInterface
*/
public function getTransport()
{
return $this->transport;
}

public function __invoke(array $param = array())
{
$this->param = $param;
Expand Down Expand Up @@ -108,21 +165,21 @@ public function __toString()
public function template($template)
{
$controller = get_class($this->controller);
$services = $this->serviceManager;

$event = new Event();
$eventManager = $services->get('EventManager');
$eventManager->setIdentifiers('Mail');
$eventManager = $this->eventManager;
// @TODO: check if change this value into ['Mail'] not causing any errors!
$eventManager->setIdentifiers(['Mail']);
$p = new Parameters(array('mail' => $this, 'template' => $template));
$event->setParams($p);
$eventManager->trigger('template.pre', $event);

// get all loaded modules
$moduleManager = $services->get('ModuleManager');
$moduleManager = $this->moduleManager;
$loadedModules = $moduleManager->getModules();
//get_called_class
$controllerIdentifier = strtolower(substr($controller, 0, strpos($controller, '\\')));
$viewResolver = $this->serviceManager->get('ViewResolver');
$viewResolver = $this->viewResolver;

$templateHalf = 'mail/' . $template;
$resource = $viewResolver->resolve($templateHalf);
Expand Down Expand Up @@ -168,47 +225,46 @@ protected function getTemplate()
} elseif (isset($this->config['templateHalf'])) {
$template = $this->config['templateHalf'];
} else {
throw new \InvalidArgumentException('Not template provided for Mail.');
throw new \InvalidArgumentException('No template provided for Mail.');
}
return $template;
}

public function informationComplete()
{
$log = $this->serviceManager->get('Log/Core/Mail');
$log = $this->mailLogger;
$template = $this->getTemplate();
if (isset($this->config['from'])) {
$from = $this->config['from'];
} else {
$log->err('A from email address must be provided (Variable $from) in Template: ' . $template);
throw new \InvalidArgumentException('A from email address must be provided (Variable $from) in Template: ' . $template);
throw new \InvalidArgumentException('A from email address must be provided (Variable $from) in Template: ' . $template);
}
if (isset($this->config['fromName'])) {
$fromName = $this->config['fromName'];
} else {
$log->err('A from name must be provided (Variable $fromName) in Template: ' . $template);
throw new \InvalidArgumentException('A from name must be provided (Variable $fromName) in Template: ' . $template);
throw new \InvalidArgumentException('A from name must be provided (Variable $fromName) in Template: ' . $template);
}
if (isset($this->config['subject'])) {
$subject = $this->config['subject'];
} else {
$log->err('A subject must be provided (Variable $subject) in Template: ' . $template);
throw new \InvalidArgumentException('A subject must be provided (Variable $subject) in Template: ' . $template);
throw new \InvalidArgumentException('A subject must be provided (Variable $subject) in Template: ' . $template);
}
$this->setFrom($from, $fromName);
$this->setSubject($subject);
return $this;
}



public function send()
{
$log = $this->serviceManager->get('Log/Core/Mail');
$log = $this->mailLogger;
$this->getHeaders()->addHeaderLine('X-Mailer', 'php/YAWIK');

$this->getHeaders()->addHeaderLine('Content-Type', 'text/plain; charset=UTF-8');

$transport = new Sendmail();
$transport = $this->transport;
$erg = false;
try {
$transport->send($this);
Expand All @@ -227,6 +283,11 @@ public function send()
*/
public static function factory(ContainerInterface $container)
{
return new static($container);
//@TODO: need to define transport to be use during ::send()
$mailLog = $container->get('Log/Core/Mail');
$viewResolver = $container->get('ViewResolver');
$eventManager = $container->get('EventManager');
$moduleManager = $container->get('ModuleManager');
return new static($mailLog,$viewResolver,$eventManager,$moduleManager);
}
}
Loading

0 comments on commit 17a1525

Please sign in to comment.