2020-05-19 15:20:42 -04:00
|
|
|
<?php
|
|
|
|
namespace ProVM\KI\Common\Controller\Web;
|
|
|
|
|
2020-05-26 23:04:37 -04:00
|
|
|
use Psr\Container\ContainerInterface as Container;
|
2020-05-19 15:20:42 -04:00
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
|
|
use Slim\Views\Blade as View;
|
|
|
|
|
|
|
|
class Nosotros {
|
2020-05-26 23:04:37 -04:00
|
|
|
public function __invoke(Request $request, Response $response, View $view, Container $container) {
|
|
|
|
$filename = implode(DIRECTORY_SEPARATOR, [
|
|
|
|
$container->get('folders.data'),
|
|
|
|
'nosotros.json'
|
|
|
|
]);
|
|
|
|
$nosotros = json_decode(trim(file_get_contents($filename)));
|
2020-06-04 12:33:07 -04:00
|
|
|
$min = 200;
|
|
|
|
$max_phrase = 50;
|
|
|
|
if (strlen($nosotros) > $min) {
|
|
|
|
$half = strlen($nosotros) / 2;
|
|
|
|
$pos = strpos($nosotros, '.', $half);
|
|
|
|
if ($pos > $half + $max_phrase) {
|
|
|
|
$pos = strrpos($nosotros, '.', -$half);
|
|
|
|
}
|
|
|
|
$nosotros = $this->str_split_unicode($nosotros, $pos, '-');
|
|
|
|
if (count($nosotros) > 2) {
|
|
|
|
$s1 = array_shift($nosotros);
|
|
|
|
$nosotros = [$s1, implode('', $nosotros)];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$nosotros = [$nosotros];
|
|
|
|
}
|
2020-05-26 23:04:37 -04:00
|
|
|
return $view->render($response, 'nosotros', compact('nosotros'));
|
|
|
|
}
|
|
|
|
protected function str_split_unicode($str, $l = 0) {
|
|
|
|
if ($l > 0) {
|
|
|
|
$ret = array();
|
|
|
|
$len = mb_strlen($str, "UTF-8");
|
|
|
|
for ($i = 0; $i < $len; $i += $l) {
|
|
|
|
$ret[] = mb_substr($str, $i, $l, "UTF-8");
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
return preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY);
|
2020-05-19 15:20:42 -04:00
|
|
|
}
|
|
|
|
}
|