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
a98961bd
Commit
a98961bd
authored
Oct 14, 2007
by
phuson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented generation of indexes and their definitions from schema files.
parent
4805dab4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
435 additions
and
374 deletions
+435
-374
Builder.php
lib/Doctrine/Import/Builder.php
+420
-366
Schema.php
lib/Doctrine/Import/Schema.php
+15
-8
No files found.
lib/Doctrine/Import/Builder.php
View file @
a98961bd
...
...
@@ -128,7 +128,7 @@ END;
* @param string $table
* @param array $tableColumns
*/
public
function
buildTableDefinition
(
array
$options
,
array
$columns
,
array
$relations
)
public
function
buildTableDefinition
(
array
$options
,
array
$columns
,
array
$relations
,
array
$indexes
)
{
$ret
=
array
();
...
...
@@ -192,6 +192,60 @@ END;
$i
++
;
}
foreach
(
$indexes
as
$indexName
=>
$definitions
)
{
$ret
[
$i
]
=
"
\n
"
.
' $this->index(\''
.
$indexName
.
'\', array('
;
foreach
(
$definitions
as
$name
=>
$value
)
{
// parse fields
if
(
$name
===
'fields'
)
{
$ret
[
$i
]
.=
'\'fields\' => array('
;
foreach
(
$value
as
$fieldName
=>
$fieldValue
)
{
$ret
[
$i
]
.=
'\''
.
$fieldName
.
'\' => array( '
;
// parse options { sorting, length, primary }
if
(
isset
(
$fieldValue
)
&&
$fieldValue
)
{
foreach
(
$fieldValue
as
$optionName
=>
$optionValue
)
{
$ret
[
$i
]
.=
'\''
.
$optionName
.
'\' => '
;
// check primary option, mark either as true or false
if
(
$optionName
===
'primary'
)
{
$ret
[
$i
]
.=
((
$optionValue
==
'true'
)
?
'true'
:
'false'
)
.
', '
;
continue
;
}
// convert sorting option to uppercase, for instance, asc -> ASC
if
(
$optionName
===
'sorting'
)
{
$ret
[
$i
]
.=
'\''
.
strtoupper
(
$optionValue
)
.
'\', '
;
continue
;
}
// check the rest of the options
$ret
[
$i
]
.=
'\''
.
$optionValue
.
'\', '
;
}
}
$ret
[
$i
]
.=
'), '
;
}
}
// parse index type option, 4 choices { unique, fulltext, gist, gin }
if
(
$name
===
'type'
)
{
$ret
[
$i
]
.=
'), \'type\' => \''
.
$value
.
'\''
;
}
// add extra ) if type definition is not declared
if
(
!
isset
(
$definitions
[
'type'
]))
{
$ret
[
$i
]
.=
')'
;
}
}
$ret
[
$i
]
.=
'));'
;
$i
++
;
}
if
(
!
empty
(
$ret
))
{
return
"
\n\t
public function setTableDefinition()"
.
"
\n\t
{\n"
.
implode
(
"
\n
"
,
$ret
)
.
"
\n\t
}"
;
}
...
...
@@ -268,7 +322,7 @@ END;
}
}
public
function
buildDefinition
(
array
$options
,
array
$columns
,
array
$relations
=
array
()
)
public
function
buildDefinition
(
array
$options
,
array
$columns
,
array
$relations
=
array
()
,
array
$indexes
=
array
())
{
if
(
!
isset
(
$options
[
'className'
]))
{
throw
new
Doctrine_Import_Builder_Exception
(
'Missing class name.'
);
...
...
@@ -277,7 +331,7 @@ END;
$abstract
=
isset
(
$options
[
'abstract'
])
?
'abstract '
:
null
;
$className
=
$options
[
'className'
];
$extends
=
isset
(
$options
[
'inheritance'
][
'extends'
])
?
$options
[
'inheritance'
][
'extends'
]
:
'Doctrine_Record'
;
$definition
=
!
isset
(
$options
[
'no_definition'
])
?
$this
->
buildTableDefinition
(
$options
,
$columns
,
$relations
)
:
null
;
$definition
=
!
isset
(
$options
[
'no_definition'
])
?
$this
->
buildTableDefinition
(
$options
,
$columns
,
$relations
,
$indexes
)
:
null
;
$setUp
=
!
isset
(
$options
[
'no_definition'
])
?
$this
->
buildSetUp
(
$options
,
$columns
,
$relations
)
:
null
;
$content
=
sprintf
(
self
::
$tpl
,
$abstract
,
...
...
@@ -289,7 +343,7 @@ END;
return
$content
;
}
public
function
buildRecord
(
array
$options
,
array
$columns
,
array
$relations
=
array
()
)
public
function
buildRecord
(
array
$options
,
array
$columns
,
array
$relations
=
array
()
,
array
$indexes
=
array
())
{
if
(
!
isset
(
$options
[
'className'
]))
{
throw
new
Doctrine_Import_Builder_Exception
(
'Missing class name.'
);
...
...
@@ -334,15 +388,15 @@ END;
$options
[
'abstract'
]
=
true
;
$options
[
'fileName'
]
=
$generatedPath
.
DIRECTORY_SEPARATOR
.
$options
[
'className'
]
.
$this
->
suffix
;
$this
->
writeDefinition
(
$options
,
$columns
,
$relations
);
$this
->
writeDefinition
(
$options
,
$columns
,
$relations
,
$indexes
);
}
else
{
$this
->
writeDefinition
(
$options
,
$columns
,
$relations
);
$this
->
writeDefinition
(
$options
,
$columns
,
$relations
,
$indexes
);
}
}
public
function
writeDefinition
(
array
$options
,
array
$columns
,
array
$relations
=
array
()
)
public
function
writeDefinition
(
array
$options
,
array
$columns
,
array
$relations
=
array
()
,
array
$indexes
=
array
())
{
$content
=
$this
->
buildDefinition
(
$options
,
$columns
,
$relations
);
$content
=
$this
->
buildDefinition
(
$options
,
$columns
,
$relations
,
$indexes
);
$code
=
"<?php
\n
"
;
...
...
lib/Doctrine/Import/Schema.php
View file @
a98961bd
...
...
@@ -40,6 +40,7 @@
class
Doctrine_Import_Schema
{
public
$relations
=
array
();
public
$indexes
=
array
();
public
$generateBaseClasses
=
false
;
public
function
generateBaseClasses
(
$bool
=
null
)
...
...
@@ -59,7 +60,7 @@ class Doctrine_Import_Schema
$this
->
buildRelationships
(
$array
);
return
array
(
'schema'
=>
$array
,
'relations'
=>
$this
->
relations
);
return
array
(
'schema'
=>
$array
,
'relations'
=>
$this
->
relations
,
'indexes'
=>
$this
->
indexes
);
}
/**
* importSchema
...
...
@@ -119,6 +120,11 @@ class Doctrine_Import_Schema
return
isset
(
$this
->
relations
[
$properties
[
'className'
]])
?
$this
->
relations
[
$properties
[
'className'
]]
:
array
();
}
public
function
getIndexes
(
$properties
)
{
return
isset
(
$properties
[
'indexes'
])
?
$properties
[
'indexes'
]
:
array
();;
}
/**
* parseSchema
*
...
...
@@ -164,6 +170,7 @@ class Doctrine_Import_Schema
$build
[
$className
][
'tableName'
]
=
$tableName
;
$build
[
$className
][
'columns'
]
=
$columns
;
$build
[
$className
][
'relations'
]
=
isset
(
$table
[
'relations'
])
?
$table
[
'relations'
]
:
array
();
$build
[
$className
][
'indexes'
]
=
isset
(
$table
[
'indexes'
])
?
$table
[
'indexes'
]
:
array
();
}
if
(
isset
(
$table
[
'inheritance'
]))
{
...
...
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