Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
476c2f97
Commit
476c2f97
authored
Jun 01, 2017
by
Marco Pivetta
Committed by
GitHub
Jun 01, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2724 from evgpisarchik/issue_2722
Table->getColumns() performance
parents
16ddeacf
7b53b5e8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
16 deletions
+29
-16
Table.php
lib/Doctrine/DBAL/Schema/Table.php
+29
-16
No files found.
lib/Doctrine/DBAL/Schema/Table.php
View file @
476c2f97
...
@@ -616,29 +616,43 @@ class Table extends AbstractAsset
...
@@ -616,29 +616,43 @@ class Table extends AbstractAsset
}
}
/**
/**
* Returns ordered list of columns (primary keys are first, then foreign keys, then the rest)
* @return Column[]
* @return Column[]
*/
*/
public
function
getColumns
()
public
function
getColumns
()
{
{
$columns
=
$this
->
_columns
;
$primaryKeyColumns
=
[];
$pkCols
=
array
();
$fkCols
=
array
();
if
(
$this
->
hasPrimaryKey
())
{
if
(
$this
->
hasPrimaryKey
())
{
$p
kCols
=
$this
->
getPrimaryKey
()
->
getColumns
(
);
$p
rimaryKeyColumns
=
$this
->
filterColumns
(
$this
->
getPrimaryKey
()
->
getColumns
()
);
}
}
foreach
(
$this
->
getForeignKeys
()
as
$fk
)
{
/* @var $fk ForeignKeyConstraint */
$fkCols
=
array_merge
(
$fkCols
,
$fk
->
getColumns
());
}
$colNames
=
array_unique
(
array_merge
(
$pkCols
,
$fkCols
,
array_keys
(
$columns
)));
uksort
(
$columns
,
function
(
$a
,
$b
)
use
(
$colNames
)
{
return
array_merge
(
$primaryKeyColumns
,
$this
->
getForeignKeyColumns
(),
$this
->
_columns
);
return
(
array_search
(
$a
,
$colNames
)
>=
array_search
(
$b
,
$colNames
));
}
});
/**
* Returns foreign key columns
* @return Column[]
*/
private
function
getForeignKeyColumns
()
{
$foreignKeyColumns
=
[];
foreach
(
$this
->
getForeignKeys
()
as
$foreignKey
)
{
/* @var $foreignKey ForeignKeyConstraint */
$foreignKeyColumns
=
array_merge
(
$foreignKeyColumns
,
$foreignKey
->
getColumns
());
}
return
$this
->
filterColumns
(
$foreignKeyColumns
);
}
return
$columns
;
/**
* Returns only columns that have specified names
* @param array $columnNames
* @return Column[]
*/
private
function
filterColumns
(
array
$columnNames
)
{
return
array_filter
(
$this
->
_columns
,
function
(
$columnName
)
use
(
$columnNames
)
{
return
in_array
(
$columnName
,
$columnNames
,
true
);
},
ARRAY_FILTER_USE_KEY
);
}
}
/**
/**
...
@@ -700,7 +714,6 @@ class Table extends AbstractAsset
...
@@ -700,7 +714,6 @@ class Table extends AbstractAsset
if
(
!
$this
->
hasPrimaryKey
())
{
if
(
!
$this
->
hasPrimaryKey
())
{
throw
new
DBALException
(
"Table "
.
$this
->
getName
()
.
" has no primary key."
);
throw
new
DBALException
(
"Table "
.
$this
->
getName
()
.
" has no primary key."
);
}
}
return
$this
->
getPrimaryKey
()
->
getColumns
();
return
$this
->
getPrimaryKey
()
->
getColumns
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment