/** * cURL POST. * @param string $URL * @param string $format return JSON/XML * @param mixed $data to POST * @return mixed */ private function post($URL, $format, $data) { assert('!empty($format) && is_string($format); // pass format of the data as a string'); // array if (is_array($data)) { curl_setopt($this->cURL, CURLOPT_POST, count($data)); // urlify & encode foreach ($data as $key => &$value) { $key = $key . '=' . urlencode($value); } $data = implode('&', $data); curl_setopt($this->cURL, CURLOPT_POSTFIELDS, $data); // string... hopefully } else { assert('is_string($data); // malformed data, pass string or an array'); curl_setopt($this->cURL, CURLOPT_POST, 1); // replace newlines if present $data = str_replace("\n", "", $data); curl_setopt($this->cURL, CURLOPT_POSTFIELDS, $data); } // setup if (count($formats = splitCamelCase($format)) > 1) { assert('$formats[1] == "Get" && count($formats) == 3; // malformed format query'); $this->setupSession($URL, $formats[2], $formats[0]); } else { $this->setupSession($URL, $format); } // execute $data = curl_exec($this->cURL); curl_close($this->cURL); // decode JSON? return $data; }
/** * Autoload Model classes when needed (before exception is thrown). * @param string $className */ function __autoload($className) { // are we working with a Fari Classes? if (strpos($className, 'Fari_') === FALSE) { // the only exception being a heavily used ORM if ($className == 'Table') { $classFilePath = BASEPATH . '/fari/Db/DbTable' . EXT; } else { // explode the class name by camel case $className = splitCamelCase($className); // the first name in a class could be a folder name, is it? if (is_dir(BASEPATH . '/' . APP_DIR . '/models/' . $className[0])) { // it is, prefix the model with a directory name $classFilePath = BASEPATH . '/' . APP_DIR . '/models/' . $className[0] . '/' . implode('', $className) . EXT; } else { // nah, the 'default' $classFilePath = BASEPATH . '/' . APP_DIR . '/models/' . implode($className) . EXT; } } } else { // remove Fari_ and build path $className = splitCamelCase(substr($className, 5)); $classFilePath = BASEPATH . '/fari/' . $className[0] . '/' . implode('', $className) . EXT; } try { // check that model class exists if (!file_exists($classFilePath)) { throw new Fari_Exception('Missing Class: ' . $classFilePath . '.'); } else { include $classFilePath; // include file } } catch (Fari_Exception $exception) { $exception->fire(); } }