public function parse($path) { $path = DIR_ROOT . SEPARADOR_DIRETORIO . $path; // se $path for vazio if (empty($path)) { //throw new Exception\Argument("\$path argument is not valid"); throw new Exception("\$path argument is not valid"); } // verifica se o parse já foi feito if (!isset($this->_parsed[$path])) { $config = array(); // ativa o buffer de saída // enquanto estiver ativo a saída é armazenada em um buffer interno ob_start(); // dá um include no arquivo .ini include "{$path}.ini"; //include("{$path}.ini.php"); // obtém o conteúdo do buffer de saída $string = ob_get_contents(); // descarta o conteúdo e desativa o buffer de saída ob_end_clean(); // transforma o conteúdo do buffer num array associativo chave => valor $pairs = parse_ini_string($string); // se não tiver nada aqui provavelmente foram encontrados erros de sintaxe if ($pairs == false) { //throw new Exception\Syntax("Could not parse configuration file"); throw new Exception("Could not parse configuration file"); } // percorre o array foreach ($pairs as $key => $value) { $config = $this->_pair($config, $key, $value); } // transforma o array num objeto $this->parsed[$path] = ArrayMethods::toObject($config); } return $this->parsed[$path]; }
public static function classify($clicks, $type = 'adid') { $classify = []; foreach ($clicks as $result) { $c = ArrayMethods::toObject($result); $key = Utils::getMongoID($c->{$type} ?? ''); if (strlen($key) == 0) { $key = "Empty"; } $key = str_replace(".", "-", $key); if (!isset($classify[$key]) || !array_key_exists($key, $classify)) { $classify[$key] = []; } $classify[$key][] = $c; } return $classify; }
public function links() { $this->seo(array("title" => "Tracking Links")); $view = $this->getActionView(); $links = Link::all(['user_id' => $this->user->_id], ['ad_id', 'domain', '_id']); $in = ArrayMethods::arrayKeys($links, 'ad_id'); $ads = Ad::all(['_id' => ['$in' => $in]], ['title', '_id']); $result = []; foreach ($links as $l) { $adid = $l->ad_id; $result[] = ArrayMethods::toObject(['title' => $ads[$adid]->title, 'url' => $l->getUrl()]); } $view->set('links', $result); if ($this->defaultExtension === "csv") { $view->erase('start')->erase('end'); $this->_org = $this->_user = null; } }