Example #1
0
 public function getArray()
 {
     $data = json_decode(file_get_contents($this->filename_cache), true);
     if (json_last_error() !== JSON_ERROR_NONE) {
         ErrorHandler::error(500, null, "Error in {$filename} : " . self::jsonLastErrorMsg());
     }
     return $data;
 }
Example #2
0
 public function __construct($dsn, $login, $password)
 {
     try {
         Logger::Debug("connect to ({$dsn})");
         $this->mongo = new MongoClient($dsn);
         $dbname = basename($dsn);
         $this->db = $this->mongo->selectDB($dbname);
     } catch (Exception $e) {
         ErrorHandler::error(500, null, "Unable to connect to Database: " . $e->getMessage());
     }
 }
Example #3
0
 public function query($sql, $params = array())
 {
     Logger::Debug("Query {$sql} ", $params);
     $reponse = $this->pdo->prepare($sql);
     if ($reponse === false) {
         $error = $this->pdo->errorInfo();
         ErrorHandler::error(500, null, "Error in SQL statement {$error[0]} ({$error[1]}) {$error[2]} in\n{$sql}");
     }
     $reponse->setFetchMode(PDO::FETCH_NAMED);
     $result = $reponse->execute($params);
     if ($result === false) {
         $error = $reponse->errorInfo();
         ErrorHandler::error(500, null, "Sql error {$error[0]} ({$error[1]}) {$error[2]} in\n{$sql}");
     }
     return $reponse;
 }
Example #4
0
 protected function update_item($r)
 {
     ErrorHandler::RaiseExceptionOnError();
     try {
         Input::ensureRequest($r, array("id"));
         $id = $r["id"];
         Logger::debug("Crud::update_item id:" . $id . " in table " . $this->model->getTableName());
         $post = $this->jsonpost();
         $this->fixValues($post);
         $item = $this->model->getById($id);
         $item->setValues($post);
         $item->save();
         Output::success(array("id" => $id));
     } catch (Exception $e) {
         Output::error($e->getMessage());
     }
 }
Example #5
0
 public static function bootstrap()
 {
     ErrorHandler::Init(__NAMESPACE__ . "\\ErrorHandler");
     self::loadConfig();
     if (array_key_exists("PATH_INFO", $_SERVER) && $_SERVER["PATH_INFO"]) {
         Rest::handle();
     }
     $conf = Config::getInstance();
     $tpt = new TemplateRes(array("title" => $conf->get("title", "CF " . CF_VERSION), "description" => $conf->get("description", null), "favicon" => $conf->get("favicon", null)));
     foreach (Plugins::dispatchAll("index", $tpt) as $index) {
         if ($index !== null) {
             $tpt->output($index);
         }
     }
     return $tpt;
 }
Example #6
0
 public static function runtests()
 {
     Cli::pinfo("Running tests");
     ErrorHandler::unregister();
     // Create Suite
     foreach (Plugins::get_plugins() as $name) {
         $result = new PHPUnit_Framework_TestResult();
         $listner = new self($name);
         $result->addListener($listner);
         $plugin = Plugins::get($name);
         $dir = $plugin->getDir() . DIRECTORY_SEPARATOR . self::TESTS_DIR;
         if (is_dir($dir)) {
             foreach (glob($dir . DIRECTORY_SEPARATOR . "*.test.php") as $file) {
                 require_once $file;
                 $testclassname = __NAMESPACE__ . "\\" . substr(basename($file), 0, -9) . "Test";
                 $suite = new PHPUnit_Framework_TestSuite(new ReflectionClass($testclassname));
                 $suite->run($result);
             }
         }
         if ($listner->dot) {
             Cli::pcolorln(Cli::ansiinfo, "]");
         }
     }
 }