public function listAction() { $console = $this->getServiceLocator()->get('console'); $sm = $this->getServiceLocator(); $isLocal = $this->params()->fromRoute('local'); if ($isLocal) { $appdir = getcwd(); echo $appdir; if (file_exists($appdir . '/config/autoload/local.php')) { $config = (include $appdir . '/config/autoload/local.php'); } else { echo 'FILE NO EXIST' . PHP_EOL; $config = array(); } } else { $config = $sm->get('Configuration'); } if (!is_array($config)) { $config = ArrayUtils::iteratorToArray($config, true); } $console->writeLine('Configuration:', Color::GREEN); // print_r($config); $ini = new IniWriter(); echo $ini->toString($config); }
/** * (non-PHPdoc) * * @see \Zend\Stdlib\Hydrator\Strategy\StrategyInterface::extract() */ public function extract($value) { if (true === isset($value['params']) && true === is_array($value['params'])) { $config = new IniWriter(); $config->setRenderWithoutSectionsFlags(true); $value['params'] = $config->toString($value['params']); } else { $value['params'] = ''; } return $value; }
/** * @param int $id * @return int * @throws UthandoException */ public function sendMessage($id) { $message = $this->getById($id); if ($message->isSent()) { throw new UthandoException('Cannot send message out again.'); } // we need to set the server url before add to mail queue $serverUrlHelper = $this->getService('ViewHelperManager')->get('ServerUrl'); $basePathUrlHelper = $this->getService('ViewHelperManager')->get('BasePath'); $serverUrl = $serverUrlHelper() . $basePathUrlHelper(); $iniReader = new IniReader(); $iniWriter = new IniWriter(); $params = $iniReader->fromString($message->getParams()); $params['server_url'] = $serverUrl; $message->setParams($iniWriter->toString($params)); $viewModel = new NewsletterModel(); $viewModel->setTemplate('message/' . $message->getMessageId()); /* @var $subscriptionMapper SubscriptionMapper */ $subscriptionMapper = $this->getService('UthandoNewsletterSubscription')->getMapper(); $subscriptions = $subscriptionMapper->getSubscriptionsByNewsletterId($message->getNewsletterId()); $subscriberIds = []; /* @var $subscription SubscriptionModel */ foreach ($subscriptions as $subscription) { $subscriberIds[] = $subscription->getSubscriberId(); } /* @var $subscriberMapper SubscriberMapper */ $subscriberMapper = $this->getService('UthandoNewsletterSubscriber')->getMapper(); $subscribers = $subscriberMapper->getSubscribersById($subscriberIds); $count = 0; /* @var $subscriber SubscriberModel */ foreach ($subscribers as $subscriber) { $this->getEventManager()->trigger('mail.queue', $this, ['recipient' => ['name' => $subscriber->getName(), 'address' => $subscriber->getEmail()], 'layout' => $viewModel, 'body' => null, 'subject' => $message->getSubject(), 'renderer' => 'ViewNewsletterRenderer', 'transport' => 'default']); $count++; } // set message as sent and save to database. $message->setDateSent(null)->setSent(true); $this->save($message); return $count; }
/** * Get configuration by key */ public function getAction() { // check for help mode if ($this->requestOptions->getFlagHelp()) { return $this->getHelp(); } // output header $this->consoleHeader('Fetching requested configuration'); // get needed options to shorten code $path = realpath($this->requestOptions->getPath()); $configName = $this->requestOptions->getConfigName(); $flagLocal = $this->requestOptions->getFlagLocal(); // check for config name if (!$configName) { return $this->sendError('config get <configName> was not provided'); } // check for local file if ($flagLocal) { $configFile = $path . '/config/autoload/local.php'; // check if local config file exists if (!file_exists($configFile)) { return $this->sendError('Local config file ' . $configFile . ' does not exist.'); } } else { $configFile = $path . '/config/application.config.php'; } // fetch config data $configData = (include $configFile); // check if local config file exists if (empty($configData)) { return $this->sendError('Config file ' . $configFile . ' is empty.'); } // start output $this->console->write(' => Reading configuration file '); $this->console->writeLine($configFile, Color::GREEN); $this->console->writeLine(); // find value in array $configValue = ModuleConfig::findValueInArray($configName, $configData); // start output $this->console->write(' Done ', Color::NORMAL, Color::CYAN); $this->console->write(' '); $this->console->write('Configuration data for key '); $this->console->writeLine($configName, Color::GREEN); $this->console->writeLine(); // check config value if (is_array($configValue)) { $iniWriter = new IniWriter(); $this->console->writeLine(str_pad('', $this->console->getWidth() - 1, '=', STR_PAD_RIGHT)); $this->console->writeLine(trim($iniWriter->toString($configValue))); $this->console->writeLine(str_pad('', $this->console->getWidth() - 1, '=', STR_PAD_RIGHT)); } elseif (is_null($configValue)) { $this->console->writeLine(' => NULL'); } else { $this->console->writeLine(' => ' . $configValue); } // output footer $this->consoleFooter('requested configuration was successfully displayed'); }
/** * @param mixed $data * @param string $format * @param array $context * * @return string */ public function encode($data, $format, array $context = array()) { return $this->encoder->toString($data); }