/** * Constructor. Creates a query and sets all parameters. * @param string $method HTTP method. Used to lock other methods for use current endpoint. * @param string $endpoint Endpoint name. * @param string $verb Endpoint verb. Used to guess database verb to use. * @param array $params Endpoint parameters. */ public function __construct($method, $endpoint, $verb = NULL, $params = array()) { // Table alias option if (isset($params['table_alias'])) { $endpoint = $params['table_alias']; } // Creates a database driver instance if (array_search(DB_ENGINE, $this->supported_drivers) === FALSE) { throw new APIexception("DB driver not supported", 8, 400); } require_once "db_drivers/" . ucfirst(DB_ENGINE) . ".driver.php"; $dbclass = ucfirst(DB_ENGINE) . "_driver"; self::$db = new $dbclass(); // Search for column prefix $col_prefix = isset($params['col_prefix']) ? $params['col_prefix'] : ""; // Creates a new table on flag if (isset($params['create_new_table']) && isset($params['columns'])) { self::$db->create_new_table($endpoint, $params['columns'], $col_prefix); } // Modifies existing table on flag if (isset($params['modify_existing_table'])) { self::$db->modify_existing_table($endpoint, $params['columns'], $col_prefix); } // Constructs endpoint based on given verb if exists, else, on method name if ($verb) { $this->query = self::$db->construct_query($verb, $endpoint, $params); } else { $this->query = self::$db->construct_query($method, $endpoint, $params); } // Fills class variables $this->method = $method; $this->action = strtolower(self::$db->get_action()); }