<?php
namespace ProVM\KI\Common\Controller\Web;

use Psr\Container\ContainerInterface as Container;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Slim\Views\Blade as View;

class Nosotros {
  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)));
    $nosotros = $this->str_split_unicode($nosotros, strlen($nosotros) / 2, '-');
    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);
  }
}
