本文整理汇总了PHP中Zend\View\Renderer\PhpRenderer::setCanRenderTrees方法的典型用法代码示例。如果您正苦于以下问题:PHP PhpRenderer::setCanRenderTrees方法的具体用法?PHP PhpRenderer::setCanRenderTrees怎么用?PHP PhpRenderer::setCanRenderTrees使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\Renderer\PhpRenderer
的用法示例。
在下文中一共展示了PhpRenderer::setCanRenderTrees方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* @return $this
* @throws NotifyException
*/
public function send()
{
//VIEW
// create and configure view
$child = new ViewModel(array('user' => $this->params->recipients, 'password' => $this->params->password));
$child->setTemplate('script');
$layout = new ViewModel();
$layout->setTemplate('layout');
$layout->addChild($child, 'content');
$phpRenderer = new PhpRenderer();
$phpRenderer->setCanRenderTrees(true);
$resolver = new Resolver\TemplateMapResolver();
$resolver->setMap(array('layout' => __DIR__ . '/../../../view/layout/email.phtml', 'script' => __DIR__ . '/../../../view/email/lost-password.phtml'));
$phpRenderer->setResolver($resolver);
foreach ($layout as $child) {
$child->setOption('has_parent', true);
$result = $phpRenderer->render($child);
$child->setOption('has_parent', null);
$capture = $child->captureTo();
if (!empty($capture)) {
$layout->setVariable($capture, $result);
}
}
$result = new Mail();
$result->name = $this->params->recipients->name;
$result->email = $this->params->recipients->email;
$result->subject = "Nýtt lykilorð";
$result->body = $phpRenderer->render($layout);
$result->type = 'Password';
$result->test = true;
//MAIL
// now we want to send this to the user/quest via e-mail
// so we try to connect to Queue and send a message
// to mail_queue
try {
$connection = $this->queueFactory->createConnection();
$channel = $connection->channel();
$channel->queue_declare('mail_queue', false, true, false, false);
$msg = new AMQPMessage($result->serialize(), ['delivery_mode' => 2]);
$this->logger->info($this->params->recipients->name . " is requesting new password");
$channel->basic_publish($msg, '', 'mail_queue');
} catch (\Exception $e) {
throw new NotifyException($e->getMessage(), 0, $e);
} finally {
if (isset($channel) && $channel) {
$channel->close();
}
if (isset($connection) && $connection) {
$connection->close();
}
}
return $this;
}
示例2: setUp
public function setUp()
{
$this->resolver = new TemplateMapResolver(array('layout' => __DIR__ . '/../_templates/nested-view-model-layout.phtml', 'child1' => __DIR__ . '/../_templates/nested-view-model-content.phtml', 'child2' => __DIR__ . '/../_templates/nested-view-model-child2.phtml', 'complex' => __DIR__ . '/../_templates/nested-view-model-complexlayout.phtml'));
$this->renderer = $renderer = new PhpRenderer();
$renderer->setCanRenderTrees(true);
$renderer->setResolver($this->resolver);
$this->viewModelHelper = $renderer->plugin('view_model');
$this->helper = $renderer->plugin('render_child_model');
$this->parent = new ViewModel();
$this->parent->setTemplate('layout');
$this->viewModelHelper->setRoot($this->parent);
$this->viewModelHelper->setCurrent($this->parent);
}
示例3: testUsesTreeRendererInterfaceToDetermineWhetherOrNotToPassOnlyRootViewModelToPhpRenderer
public function testUsesTreeRendererInterfaceToDetermineWhetherOrNotToPassOnlyRootViewModelToPhpRenderer()
{
$resolver = new Resolver\TemplateMapResolver(array('layout' => __DIR__ . '/_templates/nested-view-model-layout.phtml', 'content' => __DIR__ . '/_templates/nested-view-model-content.phtml'));
$phpRenderer = new PhpRenderer();
$phpRenderer->setCanRenderTrees(true);
$phpRenderer->setResolver($resolver);
$this->view->addRenderingStrategy(function ($e) use($phpRenderer) {
return $phpRenderer;
});
$result = new stdClass();
$this->view->addResponseStrategy(function ($e) use($result) {
$result->content = $e->getResult();
});
$layout = new ViewModel();
$layout->setTemplate('layout');
$content = new ViewModel();
$content->setTemplate('content');
$content->setCaptureTo('content');
$layout->addChild($content);
$this->view->render($layout);
$this->assertContains('Layout start', $result->content);
$this->assertContains('Content for layout', $result->content, $result->content);
$this->assertContains('Layout end', $result->content);
}
示例4: send
/**
* @return $this
* @throws NotifyException
*/
public function send()
{
//ID
// create an ID for this digest
$emailId = $this->getHash();
//TIME RANGE
// calculate time range and create from and
// to date objects for the range.
$from = new DateTime();
$from->add(new DateInterval('P1D'));
$to = new DateTime();
$to->add(new DateInterval('P8D'));
$this->logger->info("Queue Service says: Fetching upcoming events");
//EVENTS
// fetch all events
$events = $this->getEvents($from, $to);
//NO EVENTS
// if there are no events to publish, then it's no need
// to keep on processing this script
if (count($events) == 0) {
$this->logger->info("Digest, no events registered, stop");
return $this;
} else {
$this->logger->info("Digest, " . count($events) . " events registered.");
}
//USERS
// get all users who want to know
// about the upcoming events.
$users = $this->getUsers();
$this->logger->info("Digest, " . count($users) . " user will get email ");
//VIEW
// create and configure view
$child = new ViewModel(array('events' => $events, 'from' => $from, 'to' => $to));
$child->setTemplate('news-digest');
$layout = new ViewModel();
$layout->setTemplate('layout');
$layout->addChild($child, 'content');
$phpRenderer = new PhpRenderer();
$phpRenderer->setCanRenderTrees(true);
$resolver = new TemplateMapResolver();
$resolver->setMap(array('layout' => __DIR__ . '/../../../view/layout/email.phtml', 'news-digest' => __DIR__ . '/../../../view/email/news-digest.phtml'));
$phpRenderer->setResolver($resolver);
//QUEUE
// try to connect to Queue and send messages to it.
// this will try to send messages to mail_queue, that will
// send them on it's way via a MailTransport
try {
$connection = $this->queueFactory->createConnection();
$channel = $connection->channel();
$channel->queue_declare('mail_queue', false, true, false, false);
foreach ($users as $user) {
$child->setVariable('user', $user);
foreach ($layout as $child) {
$child->setOption('has_parent', true);
$result = $phpRenderer->render($child);
$child->setOption('has_parent', null);
$capture = $child->captureTo();
if (!empty($capture)) {
$layout->setVariable($capture, $result);
}
}
$result = new Mail();
$result->name = $user->name;
$result->email = $user->email;
$result->subject = "Vikan framundan | {$from->format('j. n.')} - {$to->format('j. n. Y')}";
$result->body = $phpRenderer->render($layout);
$result->id = $emailId;
$result->user_id = md5((string) $emailId . $user->email);
$result->type = 'Digest';
$result->parameters = 'allir';
$result->test = false;
$msg = new AMQPMessage($result->serialize(), ['delivery_mode' => 2]);
$channel->basic_publish($msg, '', 'mail_queue');
$this->logger->debug("Queue Service says: Fetching users who want upcoming events, {$user->email} in queue ");
}
} catch (\Exception $e) {
throw new NotifyException($e->getMessage(), 0, $e);
} finally {
if (isset($channel) && $channel) {
$channel->close();
}
if (isset($connection) && $connection) {
$connection->close();
}
$this->closeDataSourceDriver();
}
return $this;
}
示例5: send
/**
* @return $this
* @throws NotifyException
*/
public function send()
{
//DATA-OBJECTS
// get data-objects from persistence layer.
$eventObject = $this->getEvent($this->params->event_id);
$userObject = $this->getUser($this->params->recipients);
//VIEW
// create and configure view
$child = new ViewModel(array('user' => $userObject, 'event' => $eventObject));
$child->setTemplate($this->params->type ? 'attend' : 'unattend');
$layout = new ViewModel();
$layout->setTemplate('layout');
$layout->addChild($child, 'content');
$phpRenderer = new PhpRenderer();
$phpRenderer->setCanRenderTrees(true);
$resolver = new Resolver\TemplateMapResolver();
$resolver->setMap(array('layout' => __DIR__ . '/../../../view/layout/email.phtml', 'attend' => __DIR__ . '/../../../view/email/attending.phtml', 'unattend' => __DIR__ . '/../../../view/email/un-attending.phtml'));
$phpRenderer->setResolver($resolver);
foreach ($layout as $child) {
$child->setOption('has_parent', true);
$result = $phpRenderer->render($child);
$child->setOption('has_parent', null);
$capture = $child->captureTo();
if (!empty($capture)) {
$layout->setVariable($capture, $result);
}
}
//MESSAGE
// create and configure message.
$message = new Mail();
$message->body = $phpRenderer->render($layout);
$message->email = $userObject->email;
$message->name = $userObject->name;
$message->subject = $this->params->type ? "Þú hefur skráð þig á viðburðinn: {$eventObject->subject}" : "Þú hefur afskráð þig af viðburðinum: {$eventObject->subject}";
//MAIL
// now we want to send this to the user/quest via e-mail
// so we try to connect to Queue and send a message
// to mail_queue
try {
$connection = $this->queueFactory->createConnection();
$channel = $connection->channel();
$channel->queue_declare('mail_queue', false, true, false, false);
$msg = new AMQPMessage($message->serialize(), ['delivery_mode' => 2]);
$this->logger->info("{$userObject->email} is " . ($this->params->type ? '' : 'not ') . "attending {$eventObject->subject}");
$channel->basic_publish($msg, '', 'mail_queue');
} catch (\Exception $e) {
throw new NotifyException($e->getMessage(), 0, $e);
} finally {
if (isset($channel) && $channel) {
$channel->close();
}
if (isset($connection) && $connection) {
$connection->close();
}
$eventObject = null;
$userObject = null;
$this->closeDataSourceDriver();
}
return $this;
}
示例6: send
/**
* @return $this
* @throws NotifyException
*/
public function send()
{
//USER
// get the user.
$user = $this->getUser($this->params->user_id);
$this->logger->debug("User validate [{$user->email}]");
//VIEW
// create and configure view
$child = new ViewModel(array('user' => $user, 'link' => $this->params->facebook));
$child->setTemplate('script');
$layout = new ViewModel();
$layout->setTemplate('layout');
$layout->addChild($child, 'content');
$phpRenderer = new PhpRenderer();
$phpRenderer->setCanRenderTrees(true);
$resolver = new Resolver\TemplateMapResolver();
$resolver->setMap(array('layout' => __DIR__ . '/../../../view/layout/email.phtml', 'script' => __DIR__ . '/../../../view/email/user-validate.phtml'));
$phpRenderer->setResolver($resolver);
//MAIL
// now we want to send this to the user/quest via e-mail
// so we try to connect to Queue and send a message
// to mail_queue
try {
$connection = $this->queueFactory->createConnection();
$channel = $connection->channel();
$channel->queue_declare('mail_queue', false, true, false, false);
foreach ($layout as $child) {
$child->setOption('has_parent', true);
$result = $phpRenderer->render($child);
$child->setOption('has_parent', null);
$capture = $child->captureTo();
if (!empty($capture)) {
$layout->setVariable($capture, $result);
}
}
$result = new Mail();
$result->name = $user->name;
$result->email = $user->email;
$result->subject = "Stjórnvísi, staðfesting á aðgangi";
$result->body = $phpRenderer->render($layout);
$result->test = true;
$msg = new AMQPMessage($result->serialize(), ['delivery_mode' => 2]);
$this->logger->info("User validate email to [{$user->email}]");
$channel->basic_publish($msg, '', 'mail_queue');
} catch (\Exception $e) {
throw new NotifyException($e->getMessage(), 0, $e);
} finally {
if (isset($channel) && $channel) {
$channel->close();
}
if (isset($connection) && $connection) {
$connection->close();
}
$user = null;
}
return $this;
}
示例7: send
/**
* @return $this
* @throws NotifyException
*/
public function send()
{
$groupObject = $this->getGroup($this->params->group_id);
$userObject = $this->getUser($this->params->recipient);
//VIEW
// create and configure view
$child = new ViewModel(array('user' => $userObject, 'group' => $groupObject));
$child->setTemplate($this->params->register ? 'group-register' : 'group-unregister');
$layout = new ViewModel();
$layout->setTemplate('layout');
$layout->addChild($child, 'content');
$phpRenderer = new PhpRenderer();
$phpRenderer->setCanRenderTrees(true);
$resolver = new Resolver\TemplateMapResolver();
$resolver->setMap(array('layout' => __DIR__ . '/../../../view/layout/email.phtml', 'group-register' => __DIR__ . '/../../../view/email/group-register.phtml', 'group-unregister' => __DIR__ . '/../../../view/email/group-unregister.phtml'));
$phpRenderer->setResolver($resolver);
foreach ($layout as $child) {
$child->setOption('has_parent', true);
$result = $phpRenderer->render($child);
$child->setOption('has_parent', null);
$capture = $child->captureTo();
if (!empty($capture)) {
$layout->setVariable($capture, $result);
}
}
$result = new Mail();
$result->name = $userObject->name;
$result->email = $userObject->email;
$result->subject = $this->params->register ? "Þú hefur skráð þig í hópinn: {$groupObject->name}" : "Þú hefur afskráð þig úr hópnum: {$groupObject->name}";
$result->body = $phpRenderer->render($layout);
$result->test = true;
//MAIL
// now we want to send this to the user/quest via e-mail
// so we try to connect to Queue and send a message
// to mail_queue
try {
$connection = $this->queueFactory->createConnection();
$channel = $connection->channel();
$channel->queue_declare('mail_queue', false, true, false, false);
$msg = new AMQPMessage($result->serialize(), ['delivery_mode' => 2]);
$this->logger->info(get_class($this) . ":send" . " {$userObject->email} is " . ($this->params->register ? '' : 'not ') . "joining group {$groupObject->name_short}");
$channel->basic_publish($msg, '', 'mail_queue');
} catch (\Exception $e) {
throw new NotifyException($e->getMessage(), 0, $e);
} finally {
if (isset($channel) && $channel) {
$channel->close();
}
if (isset($connection) && $connection) {
$connection->close();
}
$userObject = null;
$groupObject = null;
$this->closeDataSourceDriver();
}
return $this;
}
示例8: pdfAction
public function pdfAction()
{
$sm = $this->getServiceLocator();
$companyService = $sm->get('Stjornvisi\\Service\\Company');
/** @var $companyDAO \Stjornvisi\Service\Company */
$userService = $sm->get('Stjornvisi\\Service\\User');
/** @var $companyDAO \Stjornvisi\Service\User */
$company = $companyService->get(14);
array_walk($company->members, function ($member) use($userService) {
$attendance = $userService->attendance($member->id);
$member->attendance = count($attendance) <= 2 ? $attendance : array_slice($attendance, -2, 2, false);
});
$layout = new ViewModel(array('company' => $company));
$layout->setTemplate('script');
$phpRenderer = new \Zend\View\Renderer\PhpRenderer();
$phpRenderer->setCanRenderTrees(true);
$resolver = new \Zend\View\Resolver\TemplateMapResolver();
$resolver->setMap(array('script' => __DIR__ . '/../../../view/pdf/company-report.phtml'));
$phpRenderer->setResolver($resolver);
$pdf = new \CanGelis\PDF\PDF('/usr/local/bin/wkhtmltopdf');
$pdf->loadHTML($phpRenderer->render($layout))->save("out.pdf", new \League\Flysystem\Adapter\Local('/Users/einar/Desktop/'), true);
}
示例9: send
/**
* Run the handler.
*
* @return $this
* @throws NotifyException
*/
public function send()
{
$emailId = $this->getHash();
$users = $this->getUsers($this->params->recipients, $this->params->test, $this->params->sender_id, $this->params->group_id);
$group = $this->getGroup($this->params->group_id);
$this->logger->info("Group-email in " . ($this->params->test ? '' : 'none') . " test mode");
//MAIL
// now we want to send this to the user/quest via e-mail
// so we try to connect to Queue and send a message
// to mail_queue
try {
//QUEUE
// create and configure queue
$connection = $this->queueFactory->createConnection();
$channel = $connection->channel();
$channel->queue_declare('mail_queue', false, true, false, false);
//VIEW
// create and configure view
$child = new ViewModel(array('user' => null, 'group' => $group, 'body' => call_user_func(new Paragrapher(), $this->params->body)));
$child->setTemplate('script');
$layout = new ViewModel();
$layout->setTemplate('layout');
$layout->addChild($child, 'content');
$phpRenderer = new PhpRenderer();
$phpRenderer->setCanRenderTrees(true);
$resolver = new Resolver\TemplateMapResolver();
$resolver->setMap(array('layout' => __DIR__ . '/../../../view/layout/email.phtml', 'script' => __DIR__ . '/../../../view/email/group-letter.phtml'));
$phpRenderer->setResolver($resolver);
//FOR EVERY USER
// for every user, render mail-template
// and send to mail-queue
foreach ($users as $user) {
$child->setVariable('user', $user);
foreach ($layout as $child) {
$child->setOption('has_parent', true);
$result = $phpRenderer->render($child);
$child->setOption('has_parent', null);
$capture = $child->captureTo();
if (!empty($capture)) {
$layout->setVariable($capture, $result);
}
}
$result = new Mail();
$result->name = $user->name;
$result->email = $user->email;
$result->subject = $this->params->subject;
$result->body = $phpRenderer->render($layout);
$result->user_id = md5((string) $emailId . $user->email);
$result->id = $emailId;
$result->type = 'Event';
$result->entity_id = $group->id;
$result->parameters = $this->params->recipients;
$result->test = $this->params->test;
$msg = new AMQPMessage($result->serialize(), ['delivery_mode' => 2]);
$this->logger->info("Groupmail to user:{$user->email}, group:{$group->name_short}");
$channel->basic_publish($msg, '', 'mail_queue');
}
} catch (\Exception $e) {
throw new NotifyException($e->getMessage(), 0, $e);
} finally {
if (isset($channel) && $channel) {
$channel->close();
}
if (isset($connection) && $connection) {
$connection->close();
}
$users = null;
$group = null;
$this->closeDataSourceDriver();
}
return $this;
}
示例10: send
/**
* @return $this
* @throws NotifyException
*/
public function send()
{
$emailId = $this->getEmailId();
$event = $this->getEvent($this->params->event_id);
$users = $this->getUser($this->getGroupsFromEvent($event), $event->id, $this->params->user_id, $this->params->recipients, $this->params->test);
$this->logger->info(count($users) . " user will get an email" . "in connection with event {$event->subject}:{$event->id}");
//VIEW
// create and configure view
$child = new ViewModel(array('user' => null, 'event' => $event, 'body' => call_user_func(new Paragrapher(), $this->params->body)));
$child->setTemplate('event');
$layout = new ViewModel();
$layout->setTemplate('layout');
$layout->addChild($child, 'content');
$phpRenderer = new PhpRenderer();
$phpRenderer->setCanRenderTrees(true);
$resolver = new Resolver\TemplateMapResolver();
$resolver->setMap(array('layout' => __DIR__ . '/../../../view/layout/email.phtml', 'event' => __DIR__ . '/../../../view/email/event.phtml'));
$phpRenderer->setResolver($resolver);
//CONNECT TO QUEUE
// try to connect to RabbitMQ
try {
$connection = $this->queueFactory->createConnection();
$channel = $connection->channel();
$channel->queue_declare('mail_queue', false, true, false, false);
//FOR EVER USER
// for every user: render email template, create message object and
// send to mail-queue
foreach ($users as $user) {
$child->setVariable('user', $user);
foreach ($layout as $child) {
$child->setOption('has_parent', true);
$result = $phpRenderer->render($child);
$child->setOption('has_parent', null);
$capture = $child->captureTo();
if (!empty($capture)) {
$layout->setVariable($capture, $result);
}
}
$message = new Mail();
$message->name = $user->name;
$message->email = $user->email;
$message->subject = $this->params->subject;
$message->body = $phpRenderer->render($layout);
$message->id = $emailId;
$message->user_id = md5((string) $emailId . $user->email);
$message->type = 'Event';
$message->entity_id = $event->id;
$message->parameters = $this->params->recipients;
$message->test = $this->params->test;
$msg = new AMQPMessage($message->serialize(), ['delivery_mode' => 2]);
$this->logger->info(" {$user->email} will get an email" . "in connection with event {$event->subject}:{$event->id}");
$channel->basic_publish($msg, '', 'mail_queue');
}
} catch (\Exception $e) {
throw new NotifyException($e->getMessage(), 0, $e);
} finally {
if (isset($channel) && $channel) {
$channel->close();
}
if (isset($connection) && $connection) {
$connection->close();
}
$users = null;
$event = null;
$this->closeDataSourceDriver();
}
return $this;
}