<?php

use \Slim\Http\Request as Request;
use \Slim\Http\Response as Response;
use App\Model\Config;

$app->get('/configcanal', function (Request $request, Response $response, $args) {
    $result = Config::first();
    $config = array();
    $keys = ($result==null) ? []:array_keys((array) $result->attributes());
    for ($i=0; $i < sizeof($keys); $i++) { 
        if(strpos($keys[$i],"canal") !== false && $result->{$keys[$i]} != null 
            && trim($result->{$keys[$i]} != "")){
            $config[] = $result->{$keys[$i]};
        } 
    }
    
    $response->getBody()->write(json_encode($config));
    return $response;
});

