Exemplo n.º 1
0
 public function testIsError()
 {
     //test true
     $actual = \ReusingDublin\Error::isError($this->fooError);
     $this->assertTrue($actual);
     //test false
     $actual = \ReusingDublin\Error::isError(new \stdClass());
     $this->assertFalse($actual);
 }
Exemplo n.º 2
0
 /**
  * API action method for returning sites.
  * @return Site Returns this for chaining.
  */
 public function actionApiGetSites()
 {
     //vars
     $routes = Config::getInstance()->routes;
     $db = Model::factory();
     $fields = array_splice($routes, 2);
     $sites = array();
     //map title field to address1
     if (in_array('title', $fields)) {
         $key = array_search('title', $fields);
         unset($fields[$key]);
         $fields[] = 'address1';
     }
     $fields[] = 'id';
     //always return id with rows.
     //query db
     count($fields) ? $fields = "`" . implode("`,`", $fields) . "`" : ($fields = "*");
     $query = "SELECT {$fields} FROM Site";
     $result = $db->query($query);
     //error report
     if (Error::isError($result)) {
         $result = array('error' => $result->getMessage());
     }
     //build & return results
     array_push($result, Api::factory()->hal);
     $this->result = json_encode($result);
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Check if db table exists.
  * @param string $table The table name.
  * @return boolean Default false.
  */
 public function tableExists($table)
 {
     $test = $this->query("SELECT 1 FROM {$table}");
     if (!Error::isError($test)) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 4
0
 * boostrap
 */
require_once 'bootstrap.php';
// end bootstrap
/**
 * Routing
 */
$config = \ReusingDublin\Config::getInstance();
$query = isset($_GET['q']) ? $_GET['q'] : null;
$config->set('query', $query);
// end Routing
/**
 * Controller
 */
$controller = \ReusingDublin\Controller::factory($config->routes);
/**
 * Ajax.
 * If ajax request then controller should contain json string.
 * @see Config::setQuery() Where ajax routes are defined.
 */
if (defined('REUSINGDUBLIN_API')) {
    echo $controller->result;
    die;
}
/**
 * Print View
 */
if (!\ReusingDublin\Error::isError($controller)) {
    \ReusingDublin\View::getView($controller);
}
// end Print View