Skip to content

Commit

Permalink
Merge pull request #6 from phalcon/4.0.x
Browse files Browse the repository at this point in the history
4.0.x
  • Loading branch information
zsilbi authored Apr 23, 2019
2 parents c57d12e + 23e92d3 commit 61647f4
Show file tree
Hide file tree
Showing 26 changed files with 596 additions and 184 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added `chunk()`, `first()`, `firstKey()`, `flatten()`, `group()`, `isUnique()`, `last()`, `lastKey()`, `order()`, `pluck()`, `sliceLeft()`, `sliceRight()`, `split()`, `tail()`, `validateAll()`, `validateAny()` to `Phalcon\Helper\Arr` [#13954](https://github.com/phalcon/cphalcon/pull/13954)
- Added `camelize()`, `concat()`, `countVowels()`, `decapitalize()`, `dynamic()`, `endsWith()`, `firstStringBetween()`, `includes()`, `increment()`, `isAnagram()`, `isLower()`, `isPalindrome()`, `isUpper()`, `lower()`, `random()`, `reduceSlashes()`, `startsWith()`, `uncamelize()`, `underscore()`, `upper()` to `Phalcon\Helper\Str` [#13954](https://github.com/phalcon/cphalcon/pull/13954)
- Added `Phalcon\Mvc\Model\Query\BuilderInterface::getModels()` returns the models involved in the query
- Added `addConnect()`, `addPurge()` and `addTrace()` to `Phalcon\Mvc\Router\Group` and its interface. [#14001](https://github.com/phalcon/cphalcon/pull/14001)

## Changed
- Refactored `Phalcon\Events\Manager` to only use `SplPriorityQueue` to store events. [#13924](https://github.com/phalcon/cphalcon/pull/13924)
Expand All @@ -31,6 +32,7 @@
- Query Builder's `GROUP BY` field is now always an array. [#13962](https://github.com/phalcon/cphalcon/pull/13962)
- Renamed `Phalcon\Paginator\Adapter::getPaginate()` to `paginate()` in documentation/tests (originally renamed in 4.0.0-alpha.1). [#13973](https://github.com/phalcon/cphalcon/pull/13973)
- Fixed the exception message in `Phalcon\Security::computeHmac()` by removing `"%s"` from output.
- `Phalcon\Mvc\Model\Relation::isForeignKey()` now returns false if the `foreignKey` option is set to `false`.

## Removed
- Removed `arrayHelpers` property from the Volt compiler. [#13925](https://github.com/phalcon/cphalcon/pull/13925)
Expand Down
2 changes: 1 addition & 1 deletion phalcon/Annotations/Reflection.zep
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Reflection
*/
public function getMethodsAnnotations() -> <Collection[]> | bool
{
var reflectionMethods, collections, methodName, reflectionMethod;
var reflectionMethods, methodName, reflectionMethod;

if this->methodAnnotations === null {
if fetch reflectionMethods, this->reflectionData["methods"] {
Expand Down
27 changes: 14 additions & 13 deletions phalcon/Db/Adapter.zep
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
*/
if typeof dialectClass == "string" {
let this->dialect = new {dialectClass}();
} else {
if typeof dialectClass == "object" {
let this->dialect = dialectClass;
}
} elseif typeof dialectClass == "object" {
let this->dialect = dialectClass;
}

let this->descriptor = descriptor;
Expand Down Expand Up @@ -270,10 +268,10 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface

let escapedTable = this->escapeIdentifier(table);

let sql = "DELETE FROM " . escapedTable;

if !empty whereCondition {
let sql = "DELETE FROM " . escapedTable . " WHERE " . whereCondition;
} else {
let sql = "DELETE FROM " . escapedTable;
let sql .= " WHERE " . whereCondition;
}

/**
Expand Down Expand Up @@ -587,13 +585,16 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
var result;

let result = this->{"query"}(sqlQuery, bindParams, bindTypes);
if typeof result == "object" {
if typeof fetchMode !== "null" {
result->setFetchMode(fetchMode);
}
return result->$fetch();

if typeof result != "object" {
return [];
}
return [];

if typeof fetchMode !== "null" {
result->setFetchMode(fetchMode);
}

return result->$fetch();
}

/**
Expand Down
1 change: 0 additions & 1 deletion phalcon/Db/AdapterInterface.zep
Original file line number Diff line number Diff line change
Expand Up @@ -425,5 +425,4 @@ interface AdapterInterface
* Generates SQL checking for the existence of a schema.view
*/
public function viewExists(string! viewName, string! schemaName = null) -> bool;

}
8 changes: 3 additions & 5 deletions phalcon/Db/Column.zep
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use Phalcon\Db\ColumnInterface;
*/
class Column implements ColumnInterface
{

/**
* Bind Type Blob
*/
Expand Down Expand Up @@ -329,12 +328,12 @@ class Column implements ColumnInterface
/**
* Get the column type, one of the TYPE_* constants
*/
if fetch type, definition["type"] {
let this->type = type;
} else {
if !fetch type, definition["type"] {
throw new Exception("Column type is required");
}

let this->type = type;

if fetch typeReference, definition["typeReference"] {
let this->typeReference = typeReference;
}
Expand Down Expand Up @@ -445,7 +444,6 @@ class Column implements ColumnInterface
if fetch bindType, definition["bindType"] {
let this->bindType = bindType;
}

}

/**
Expand Down
10 changes: 0 additions & 10 deletions phalcon/Db/ColumnInterface.zep
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,21 @@ interface ColumnInterface

/**
* Returns column name
*
* @return string
*/
public function getName() -> string;

/**
* Returns column scale
*
* @return int
*/
public function getScale() -> int;

/**
* Returns schema's table related to column
*
* @return string
*/
public function getSchemaName() -> string;

/**
* Returns column size
*
* @return int
*/
public function getSize() -> int;

Expand All @@ -78,8 +70,6 @@ interface ColumnInterface

/**
* Returns column type reference
*
* @return int
*/
public function getTypeReference() -> int;

Expand Down
1 change: 0 additions & 1 deletion phalcon/Db/Dialect.zep
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace Phalcon\Db;
*/
abstract class Dialect implements DialectInterface
{

protected escapeChar;

protected customFunctions;
Expand Down
7 changes: 1 addition & 6 deletions phalcon/Db/Dialect/Mysql.zep
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use Phalcon\Db\DialectInterface;
*/
class Mysql extends Dialect
{

protected escapeChar = "`";

/**
Expand Down Expand Up @@ -579,11 +578,7 @@ class Mysql extends Dialect
*/
public function getForeignKeyChecks() -> string
{
var sql;

let sql = "SELECT @@foreign_key_checks";

return sql;
return "SELECT @@foreign_key_checks";
}

/**
Expand Down
80 changes: 40 additions & 40 deletions phalcon/Db/Dialect/Postgresql.zep
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use Phalcon\Db\DialectInterface;
*/
class Postgresql extends Dialect
{

protected escapeChar = "\"";

/**
Expand Down Expand Up @@ -56,28 +55,28 @@ class Postgresql extends Dialect
*/
public function addForeignKey(string! tableName, string! schemaName, <ReferenceInterface> reference) -> string
{
var sql, onDelete, onUpdate;

let sql = "ALTER TABLE " . this->prepareTable(tableName, schemaName) . " ADD";
if reference->getName() {
let sql .= " CONSTRAINT \"" . reference->getName() . "\"";
}
let sql .= " FOREIGN KEY (" . this->getColumnList(reference->getColumns()) . ")"
. " REFERENCES \"" . reference->getReferencedTable() . "\" (" . this->getColumnList(reference->getReferencedColumns()) . ")";
var sql, onDelete, onUpdate;

let onDelete = reference->getOnDelete();
if !empty onDelete {
let sql .= " ON DELETE " . onDelete;
}
let sql = "ALTER TABLE " . this->prepareTable(tableName, schemaName) . " ADD";
if reference->getName() {
let sql .= " CONSTRAINT \"" . reference->getName() . "\"";
}
let sql .= " FOREIGN KEY (" . this->getColumnList(reference->getColumns()) . ")"
. " REFERENCES \"" . reference->getReferencedTable() . "\" (" . this->getColumnList(reference->getReferencedColumns()) . ")";

let onUpdate = reference->getOnUpdate();
if !empty onUpdate {
let sql .= " ON UPDATE " . onUpdate;
}
let onDelete = reference->getOnDelete();
if !empty onDelete {
let sql .= " ON DELETE " . onDelete;
}

return sql;
let onUpdate = reference->getOnUpdate();
if !empty onUpdate {
let sql .= " ON UPDATE " . onUpdate;
}

return sql;
}

/**
* Generates SQL to add an index to a table
*/
Expand Down Expand Up @@ -273,10 +272,11 @@ class Postgresql extends Dialect
*/
public function describeColumns(string! table, string schema = null) -> string
{
if schema {
return "SELECT DISTINCT c.column_name AS Field, c.data_type AS Type, c.character_maximum_length AS Size, c.numeric_precision AS NumericSize, c.numeric_scale AS NumericScale, c.is_nullable AS Null, CASE WHEN pkc.column_name NOTNULL THEN 'PRI' ELSE '' END AS Key, CASE WHEN c.data_type LIKE '%int%' AND c.column_default LIKE '%nextval%' THEN 'auto_increment' ELSE '' END AS Extra, c.ordinal_position AS Position, c.column_default FROM information_schema.columns c LEFT JOIN ( SELECT kcu.column_name, kcu.table_name, kcu.table_schema FROM information_schema.table_constraints tc INNER JOIN information_schema.key_column_usage kcu on (kcu.constraint_name = tc.constraint_name and kcu.table_name=tc.table_name and kcu.table_schema=tc.table_schema) WHERE tc.constraint_type='PRIMARY KEY') pkc ON (c.column_name=pkc.column_name AND c.table_schema = pkc.table_schema AND c.table_name=pkc.table_name) WHERE c.table_schema='" . schema . "' AND c.table_name='" . table . "' ORDER BY c.ordinal_position";
if schema === null {
let schema = "public";
}
return "SELECT DISTINCT c.column_name AS Field, c.data_type AS Type, c.character_maximum_length AS Size, c.numeric_precision AS NumericSize, c.numeric_scale AS NumericScale, c.is_nullable AS Null, CASE WHEN pkc.column_name NOTNULL THEN 'PRI' ELSE '' END AS Key, CASE WHEN c.data_type LIKE '%int%' AND c.column_default LIKE '%nextval%' THEN 'auto_increment' ELSE '' END AS Extra, c.ordinal_position AS Position, c.column_default FROM information_schema.columns c LEFT JOIN ( SELECT kcu.column_name, kcu.table_name, kcu.table_schema FROM information_schema.table_constraints tc INNER JOIN information_schema.key_column_usage kcu on (kcu.constraint_name = tc.constraint_name and kcu.table_name=tc.table_name and kcu.table_schema=tc.table_schema) WHERE tc.constraint_type='PRIMARY KEY') pkc ON (c.column_name=pkc.column_name AND c.table_schema = pkc.table_schema AND c.table_name=pkc.table_name) WHERE c.table_schema='public' AND c.table_name='" . table . "' ORDER BY c.ordinal_position";

return "SELECT DISTINCT c.column_name AS Field, c.data_type AS Type, c.character_maximum_length AS Size, c.numeric_precision AS NumericSize, c.numeric_scale AS NumericScale, c.is_nullable AS Null, CASE WHEN pkc.column_name NOTNULL THEN 'PRI' ELSE '' END AS Key, CASE WHEN c.data_type LIKE '%int%' AND c.column_default LIKE '%nextval%' THEN 'auto_increment' ELSE '' END AS Extra, c.ordinal_position AS Position, c.column_default FROM information_schema.columns c LEFT JOIN ( SELECT kcu.column_name, kcu.table_name, kcu.table_schema FROM information_schema.table_constraints tc INNER JOIN information_schema.key_column_usage kcu on (kcu.constraint_name = tc.constraint_name and kcu.table_name=tc.table_name and kcu.table_schema=tc.table_schema) WHERE tc.constraint_type='PRIMARY KEY') pkc ON (c.column_name=pkc.column_name AND c.table_schema = pkc.table_schema AND c.table_name=pkc.table_name) WHERE c.table_schema='" . schema . "' AND c.table_name='" . table . "' ORDER BY c.ordinal_position";
}

/**
Expand All @@ -292,15 +292,11 @@ class Postgresql extends Dialect
*/
public function describeReferences(string! table, string schema = null) -> string
{
var sql = "SELECT DISTINCT tc.table_name AS TABLE_NAME, kcu.column_name AS COLUMN_NAME, tc.constraint_name AS CONSTRAINT_NAME, tc.table_catalog AS REFERENCED_TABLE_SCHEMA, ccu.table_name AS REFERENCED_TABLE_NAME, ccu.column_name AS REFERENCED_COLUMN_NAME, rc.update_rule AS UPDATE_RULE, rc.delete_rule AS DELETE_RULE FROM information_schema.table_constraints AS tc JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name JOIN information_schema.referential_constraints rc ON tc.constraint_catalog = rc.constraint_catalog AND tc.constraint_schema = rc.constraint_schema AND tc.constraint_name = rc.constraint_name AND tc.constraint_type = 'FOREIGN KEY' WHERE constraint_type = 'FOREIGN KEY' AND ";

if schema {
let sql .= "tc.table_schema = '" . schema . "' AND tc.table_name='" . table . "'";
} else {
let sql .= "tc.table_schema = 'public' AND tc.table_name='" . table . "'";
if schema === null {
let schema = "public";
}

return sql;
return "SELECT DISTINCT tc.table_name AS TABLE_NAME, kcu.column_name AS COLUMN_NAME, tc.constraint_name AS CONSTRAINT_NAME, tc.table_catalog AS REFERENCED_TABLE_SCHEMA, ccu.table_name AS REFERENCED_TABLE_NAME, ccu.column_name AS REFERENCED_COLUMN_NAME, rc.update_rule AS UPDATE_RULE, rc.delete_rule AS DELETE_RULE FROM information_schema.table_constraints AS tc JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name JOIN information_schema.referential_constraints rc ON tc.constraint_catalog = rc.constraint_catalog AND tc.constraint_schema = rc.constraint_schema AND tc.constraint_name = rc.constraint_name AND tc.constraint_type = 'FOREIGN KEY' WHERE constraint_type = 'FOREIGN KEY' AND tc.table_schema = '" . schema . "' AND tc.table_name='" . table . "'";
}

/**
Expand Down Expand Up @@ -509,21 +505,23 @@ class Postgresql extends Dialect
*/
public function listTables(string schemaName = null) -> string
{
if schemaName {
return "SELECT table_name FROM information_schema.tables WHERE table_schema = '" . schemaName . "' ORDER BY table_name";
if schemaName === null {
let schemaName = "public";
}
return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name";

return "SELECT table_name FROM information_schema.tables WHERE table_schema = '" . schemaName . "' ORDER BY table_name";
}

/**
* Generates the SQL to list all views of a schema or user
*/
public function listViews(string schemaName = null) -> string
{
if schemaName {
return "SELECT viewname AS view_name FROM pg_views WHERE schemaname = '" . schemaName . "' ORDER BY view_name";
if schemaName === null {
let schemaName = "public";
}
return "SELECT viewname AS view_name FROM pg_views WHERE schemaname = 'public' ORDER BY view_name";

return "SELECT viewname AS view_name FROM pg_views WHERE schemaname = '" . schemaName . "' ORDER BY view_name";
}

/**
Expand Down Expand Up @@ -599,10 +597,11 @@ class Postgresql extends Dialect
*/
public function tableExists(string! tableName, string schemaName = null) -> string
{
if schemaName {
return "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM information_schema.tables WHERE table_schema = '" . schemaName . "' AND table_name='" . tableName . "'";
if schemaName === null {
let schemaName = "public";
}
return "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM information_schema.tables WHERE table_schema = 'public' AND table_name='" . tableName . "'";

return "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM information_schema.tables WHERE table_schema = '" . schemaName . "' AND table_name='" . tableName . "'";
}

/**
Expand Down Expand Up @@ -636,10 +635,11 @@ class Postgresql extends Dialect
*/
public function viewExists(string! viewName, string schemaName = null) -> string
{
if schemaName {
return "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM pg_views WHERE viewname='" . viewName . "' AND schemaname='" . schemaName . "'";
if schemaName === null {
let schemaName = "public";
}
return "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM pg_views WHERE viewname='" . viewName . "' AND schemaname='public'";

return "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM pg_views WHERE viewname='" . viewName . "' AND schemaname='" . schemaName . "'";
}

protected function castDefault(<ColumnInterface> column) -> string
Expand Down
1 change: 0 additions & 1 deletion phalcon/Db/Dialect/Sqlite.zep
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use Phalcon\Db\ReferenceInterface;
*/
class Sqlite extends Dialect
{

protected escapeChar = "\"";

/**
Expand Down
1 change: 0 additions & 1 deletion phalcon/Db/Profiler/Item.zep
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class Item
*/
protected sqlVariables { set, get };


/**
* Returns the total time in seconds spent by the profile
*/
Expand Down
13 changes: 4 additions & 9 deletions phalcon/Db/RawValue.zep
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ namespace Phalcon\Db;
*/
class RawValue
{

/**
* Raw value without quoting or formatting
*
Expand All @@ -41,16 +40,12 @@ class RawValue
*/
public function __construct(var value) -> void
{
if typeof value == "string" && value == "" {
if value === "" {
let this->value = "''";
return;
}

if value === null {
} elseif value === null {
let this->value = "NULL";
return;
} else {
let this->value = (string) value;
}

let this->value = (string) value;
}
}
Loading

0 comments on commit 61647f4

Please sign in to comment.