From 7acf7afe98748a3205eba79c75b997548994a507 Mon Sep 17 00:00:00 2001 From: Lenin Paulino Date: Fri, 22 Jun 2018 10:56:54 -0400 Subject: [PATCH 1/8] Add verbose declaration of the HEAD method Add a function to handle HEAD HTTP requests --- src/RouterCollection.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/RouterCollection.php b/src/RouterCollection.php index 7884770..df2f2b5 100755 --- a/src/RouterCollection.php +++ b/src/RouterCollection.php @@ -182,4 +182,15 @@ public function options(string $pattern, array $param) { return $this->call('options', $pattern, $param[0], $param[1]); } + + /** + * Instead of using magic we define each method function + * + * @param string $pattern + * @param array $param + */ + public function head(string $pattern, array $param) + { + return $this->call('head', $pattern, $param[0], $param[1]); + } } From 94cefc28e2aadcf9f009ceb8e84061b2ea31109c Mon Sep 17 00:00:00 2001 From: Andres Ortega Date: Mon, 16 Jul 2018 15:37:23 -0400 Subject: [PATCH 2/8] Fix casting a field to string for using LIKE operator --- src/QueryParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QueryParser.php b/src/QueryParser.php index bdff19e..0e85535 100755 --- a/src/QueryParser.php +++ b/src/QueryParser.php @@ -211,7 +211,7 @@ protected function prepareSearch(array $unparsed, bool $isSearch = false, $hasSu $values = array_values($tmpMapped); foreach ($keys as $key => $field) { - $conditions .= " AND {$field} LIKE ?{$key}"; + $conditions .= " AND CAST({$field} AS TEXT) LIKE ?{$key}"; } if (isset($betweenMap)) { From 109c6bdb1e4f3915b232f9ace48a66ecd3ff9589 Mon Sep 17 00:00:00 2001 From: Andres Ortega Date: Mon, 16 Jul 2018 16:25:00 -0400 Subject: [PATCH 3/8] Fix casting a field to string for using LIKE operator when using postgresql. --- src/QueryParser.php | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/QueryParser.php b/src/QueryParser.php index 0e85535..73a7b6a 100755 --- a/src/QueryParser.php +++ b/src/QueryParser.php @@ -2,9 +2,9 @@ namespace Baka\Http; -use Exception; -use Phalcon\Mvc\Model; +use Phalcon\Di; use Phalcon\Mvc\Model\ResultsetInterface; +use Phalcon\Mvc\Model; /** * Base QueryParser. Parse GET request for a API to a array Phalcon Model find and FindFirst can intepret @@ -110,7 +110,7 @@ public function request(): array * @param string $unparsed Unparsed search string * @return array An array of fieldname=>value search parameters */ - public function parseSearchParameters(string $unparsed): array + protected function parseSearchParameters(string $unparsed): array { // Strip parens that come with the request string $unparsed = trim($unparsed, '()'); @@ -145,7 +145,7 @@ public function parseSearchParameters(string $unparsed): array protected function parseSubquery(string $unparsed): array { // Strip parens that come with the request string - $tableName = explode('(', $unparsed, 2); + $tableName = explode("(", $unparsed, 2); //print_r($tableName);die(); $tableName = strtolower($tableName[0]); @@ -168,7 +168,7 @@ protected function parseSubquery(string $unparsed): array $action = 'in'; $fieldsToRelate = explode('::', $splitFields[0]); } else { - throw new \Exception('Error Processing Subquery', 1); + throw new \Exception("Error Processing Subquery", 1); } $subquery = [ @@ -190,7 +190,7 @@ protected function parseSubquery(string $unparsed): array protected function prepareSearch(array $unparsed, bool $isSearch = false, $hasSubquery = false): array { $statement = [ - 'conditions' => '1 = 1', + 'conditions' => "1 = 1", 'bind' => [], ]; @@ -210,8 +210,15 @@ protected function prepareSearch(array $unparsed, bool $isSearch = false, $hasSu $keys = array_keys($tmpMapped); $values = array_values($tmpMapped); + $di = Di::getDefault(); + foreach ($keys as $key => $field) { - $conditions .= " AND CAST({$field} AS TEXT) LIKE ?{$key}"; + if ($di->get('config')->database->adapter == 'Postgresql') { + $conditions .= " AND CAST({$field} AS TEXT) LIKE ?{$key}"; + } + else { + $conditions .= " AND {$field} LIKE ?{$key}"; + } } if (isset($betweenMap)) { @@ -259,11 +266,11 @@ protected function parsePartialFields(string $unparsed): array } /** - * Based on the given relaitonship, add the relation array to the Resultset + * Based on the given relaitonship , add the relation array to the Resultset * * @param string $relationships - * @param [array|object] $results - * @return array + * @param [array|object] $results by reference to clean the object + * @return mixed */ public static function parseRelationShips(string $relationships, &$results): array { @@ -271,11 +278,11 @@ public static function parseRelationShips(string $relationships, &$results): arr $newResults = []; - // if its a list + //if its a list if ($results instanceof ResultsetInterface && count($results) >= 1) { foreach ($results as $key => $result) { //clean records conver to array - $newResults[$key] = $result->toArray(); + $newResults[$key] = $result->toArray(); foreach ($relationships as $relationship) { if ($results[$key]->$relationship) { $newResults[$key][$relationship] = $results[$key]->$relationship; @@ -283,7 +290,7 @@ public static function parseRelationShips(string $relationships, &$results): arr } } } else { - // if its only 1 record + //if its only 1 record if ($results instanceof Model) { $newResults = $results->toArray(); foreach ($relationships as $relationship) { From ebf54d6d7c7d6e57d732db2736d9ef5541055afc Mon Sep 17 00:00:00 2001 From: Andres Ortega Date: Mon, 23 Jul 2018 10:45:33 -0400 Subject: [PATCH 4/8] Revert function parseSearchParameters back to public --- src/QueryParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QueryParser.php b/src/QueryParser.php index 73a7b6a..4fa794c 100755 --- a/src/QueryParser.php +++ b/src/QueryParser.php @@ -110,7 +110,7 @@ public function request(): array * @param string $unparsed Unparsed search string * @return array An array of fieldname=>value search parameters */ - protected function parseSearchParameters(string $unparsed): array + public function parseSearchParameters(string $unparsed): array { // Strip parens that come with the request string $unparsed = trim($unparsed, '()'); From f0e5993120ffc2c0fb17568bc6f24754296de76d Mon Sep 17 00:00:00 2001 From: Max Castro Date: Sat, 6 Oct 2018 19:54:31 -0300 Subject: [PATCH 5/8] Update BaseController.php --- src/Rest/BaseController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rest/BaseController.php b/src/Rest/BaseController.php index 4ba0fde..6ee27de 100755 --- a/src/Rest/BaseController.php +++ b/src/Rest/BaseController.php @@ -36,7 +36,7 @@ public function response($content, int $statusCode = 200, string $statusMessage $response->setStatusCode($statusCode, $statusMessage); $response->setJsonContent($content); - return $response; + return $response->send(); } /** From b822c912353d3fdb53ded89046417e75bfab772f Mon Sep 17 00:00:00 2001 From: Max Castro Date: Sat, 6 Oct 2018 21:57:29 -0300 Subject: [PATCH 6/8] Update BaseController.php --- src/Rest/BaseController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rest/BaseController.php b/src/Rest/BaseController.php index 6ee27de..4ba0fde 100755 --- a/src/Rest/BaseController.php +++ b/src/Rest/BaseController.php @@ -36,7 +36,7 @@ public function response($content, int $statusCode = 200, string $statusMessage $response->setStatusCode($statusCode, $statusMessage); $response->setJsonContent($content); - return $response->send(); + return $response; } /** From 2231e58b7eb3f168a72965db278c24a5bec79d9b Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 25 Oct 2018 14:55:49 -0400 Subject: [PATCH 7/8] Add connection to any db for query --- src/QueryParserCustomFields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QueryParserCustomFields.php b/src/QueryParserCustomFields.php index 5b8112d..1aa955e 100755 --- a/src/QueryParserCustomFields.php +++ b/src/QueryParserCustomFields.php @@ -636,7 +636,7 @@ public function parseSearchParameters(string $unparsed): array */ private function getTextFields($table): array { - $columnsData = $this->db->describeColumns($table); + $columnsData = $this->model->getReadConnection()->describeColumns($table); $textFields = []; foreach ($columnsData as $column) { From 269217d55e73a34f8fcf973b8943d449e672a18c Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 16 Nov 2018 15:50:35 -0400 Subject: [PATCH 8/8] Fix package --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9356fd1..b9ff5ae 100755 --- a/README.md +++ b/README.md @@ -289,7 +289,7 @@ Thats it, your controller now manages the custom fields as if they wher properti # Normal API CRUD -Just extend your API controller from CrudController and you will have the following functions +Just extend your API controller from CrudController and you will have the following functions: The CRUD handles the default behaviero: - GET /v1/leads -> get all