Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Zend Framework 2 GyaruMoji Module for demo
<?php
namespace GyaruMoji;
class Module
{
public function getConfig()
{
return array(
'service_manager' => array(
'factories' => array(
'gyarumoji' => function ($sm) {
$view = $sm->get('view_manager')->getView();
$view->addRenderingStrategy(
function ($e) {
$gals = (array)
json_decode(file_get_contents(__DIR__ . '/gal.json'));
$viewModel = $e->getModel();
foreach ($viewModel->getVariables() as $key => $text) {
$replaced_tags = array();
$i = 1;
$text = preg_replace_callback("/<[^>]+>/",
function ($matches) use(&$i, &$replaced_tags) {
$replaced_tags["[".$i."]"] = $matches[0];
return "[" . $i++ . "]";
}, $text);
foreach ($gals as $search => $replace) {
if (empty($replace) === false
&& strpos($text, $search) !== false) {
$text = str_replace($search,
$replace[array_rand($replace)],
$text);
}
}
$text = str_replace(
array_keys($replaced_tags),
array_values($replaced_tags),
$text);
$viewModel->setVariable($key, $text);
}
}
);
return $view;
}
)
),
'view_manager' => array(
'strategies' => array(
'gyarumoji'
)
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.