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
d0898c1a
Commit
d0898c1a
authored
Sep 21, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes to allow inheritance.
parent
57ce0633
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
52 deletions
+99
-52
Builder.php
lib/Doctrine/Import/Builder.php
+53
-27
Schema.php
lib/Doctrine/Import/Schema.php
+38
-24
index.php
playground/index.php
+6
-1
schema.yml
tests/schema.yml
+2
-0
No files found.
lib/Doctrine/Import/Builder.php
View file @
d0898c1a
...
...
@@ -90,11 +90,10 @@ class Doctrine_Import_Builder
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class
%
s
extends
Doctrine_Record
class
%
s
extends
%
s
{
public
function
setTableDefinition
()
{
%
s
%
s
}
public
function
setUp
()
...
...
@@ -112,17 +111,31 @@ END;
* @param string $table
* @param array $tableColumns
*/
public
function
build
ColumnDefinition
(
array
$tableColum
ns
)
public
function
build
TableDefinition
(
array
$options
,
array
$columns
,
array
$relatio
ns
)
{
$columns
=
array
();
$i
=
1
;
foreach
(
$tableColumns
as
$name
=>
$column
)
{
$columns
[
$i
]
=
' $this->hasColumn(\''
.
$name
.
'\', \''
.
$column
[
'type'
]
.
'\''
;
$ret
=
array
();
$i
=
0
;
if
(
isset
(
$options
[
'inheritance'
])
&&
isset
(
$options
[
'inheritance'
][
'extends'
]))
{
$ret
[
$i
]
=
"
\t\t
parent::setTableDefinition();"
;
$i
++
;
}
if
(
isset
(
$options
[
'tableName'
])
&&
!
empty
(
$options
[
'tableName'
]))
{
$ret
[
$i
]
=
str_repeat
(
' '
,
8
)
.
'$this->setTableName(\''
.
$options
[
'tableName'
]
.
'\');'
;
$i
++
;
}
foreach
(
$columns
as
$name
=>
$column
)
{
$ret
[
$i
]
=
' $this->hasColumn(\''
.
$name
.
'\', \''
.
$column
[
'type'
]
.
'\''
;
if
(
$column
[
'length'
])
{
$
columns
[
$i
]
.=
', '
.
$column
[
'length'
];
$
ret
[
$i
]
.=
', '
.
$column
[
'length'
];
}
else
{
$
columns
[
$i
]
.=
', null'
;
$
ret
[
$i
]
.=
', null'
;
}
$a
=
array
();
...
...
@@ -150,24 +163,32 @@ END;
}
if
(
!
empty
(
$a
))
{
$
columns
[
$i
]
.=
', '
.
'array('
;
$length
=
strlen
(
$
columns
[
$i
]);
$
columns
[
$i
]
.=
implode
(
','
.
PHP_EOL
.
str_repeat
(
' '
,
$length
),
$a
)
.
')'
;
$
ret
[
$i
]
.=
', '
.
'array('
;
$length
=
strlen
(
$
ret
[
$i
]);
$
ret
[
$i
]
.=
implode
(
','
.
PHP_EOL
.
str_repeat
(
' '
,
$length
),
$a
)
.
')'
;
}
$columns
[
$i
]
.=
');'
;
$ret
[
$i
]
.=
');'
;
if
(
$i
<
(
count
(
$
tableC
olumns
)
-
1
))
{
$
columns
[
$i
]
.=
PHP_EOL
;
if
(
$i
<
(
count
(
$
c
olumns
)
-
1
))
{
$
ret
[
$i
]
.=
PHP_EOL
;
}
$i
++
;
}
return
implode
(
"
\n
"
,
$
columns
);
return
implode
(
"
\n
"
,
$
ret
);
}
public
function
build
RelationDefinition
(
array
$relations
)
public
function
build
SetUp
(
array
$options
,
array
$columns
,
array
$relations
)
{
$ret
=
array
();
$i
=
0
;
if
(
isset
(
$options
[
'inheritance'
])
&&
isset
(
$options
[
'inheritance'
][
'extends'
]))
{
$ret
[
1
]
=
"
\t\t
parent::setUp();"
;
$i
=
1
;
}
else
{
$i
=
0
;
}
foreach
(
$relations
as
$name
=>
$relation
)
{
$alias
=
(
isset
(
$relation
[
'alias'
])
&&
$relation
[
'alias'
]
!==
$name
)
?
' as '
.
$relation
[
'alias'
]
:
''
;
...
...
@@ -219,27 +240,32 @@ END;
$i
++
;
}
if
(
isset
(
$options
[
'inheritance'
][
'keyField'
])
&&
isset
(
$options
[
'inheritance'
][
'keyValue'
]))
{
$i
++
;
$ret
[
$i
]
=
"
\t\t
"
.
'$this->setInheritanceMap(array(\''
.
$options
[
'inheritance'
][
'keyField'
]
.
'\' => '
.
$options
[
'inheritance'
][
'keyValue'
]
.
'));'
;
}
return
implode
(
"
\n
"
,
$ret
);
}
public
function
buildDefinition
(
array
$options
,
array
$columns
,
array
$relations
=
array
())
{
if
(
!
isset
(
$options
[
'className'
]))
{
throw
new
Doctrine_Import_Builder_Exception
(
'Missing class name.'
);
}
$opt
=
isset
(
$options
[
'tableName'
])
&&
!
empty
(
$options
[
'tableName'
])
?
str_repeat
(
' '
,
8
)
.
'$this->setTableName(\''
.
$options
[
'tableName'
]
.
'\');'
:
''
;
$content
=
sprintf
(
self
::
$tpl
,
$options
[
'className'
],
$opt
,
$this
->
buildColumnDefinition
(
$columns
),
$this
->
buildRelationDefinition
(
$relations
));
$className
=
$options
[
'className'
];
$extends
=
isset
(
$options
[
'inheritance'
][
'extends'
])
?
$options
[
'inheritance'
][
'extends'
]
:
'Doctrine_Record'
;
$content
=
sprintf
(
self
::
$tpl
,
$className
,
$extends
,
$this
->
buildTableDefinition
(
$options
,
$columns
,
$relations
),
$this
->
buildSetUp
(
$options
,
$columns
,
$relations
));
return
$content
;
}
public
function
buildRecord
(
$options
,
$columns
,
$relations
)
public
function
buildRecord
(
array
$options
,
array
$columns
,
array
$relations
=
array
()
)
{
if
(
!
isset
(
$options
[
'className'
]))
{
throw
new
Doctrine_Import_Builder_Exception
(
'Missing class name.'
);
...
...
lib/Doctrine/Import/Schema.php
View file @
d0898c1a
...
...
@@ -73,8 +73,13 @@ class Doctrine_Import_Schema
$options
=
array
();
$options
[
'className'
]
=
$properties
[
'className'
];
$options
[
'fileName'
]
=
$directory
.
DIRECTORY_SEPARATOR
.
$properties
[
'className'
]
.
'.class.php'
;
$options
[
'tableName'
]
=
isset
(
$properties
[
'tableName'
])
?
$properties
[
'tableName'
]
:
null
;
$columns
=
$properties
[
'columns'
];
$options
[
'tableName'
]
=
isset
(
$properties
[
'tableName'
])
?
$properties
[
'tableName'
]
:
null
;
if
(
isset
(
$properties
[
'inheritance'
]))
{
$options
[
'inheritance'
]
=
$properties
[
'inheritance'
];
}
$columns
=
isset
(
$properties
[
'columns'
])
?
$properties
[
'columns'
]
:
array
();
$relations
=
isset
(
$this
->
relations
[
$options
[
'className'
]])
?
$this
->
relations
[
$options
[
'className'
]]
:
array
();
...
...
@@ -103,29 +108,35 @@ class Doctrine_Import_Schema
$className
=
isset
(
$table
[
'className'
])
?
(
string
)
$table
[
'className'
]
:
(
string
)
$className
;
$tableName
=
isset
(
$table
[
'tableName'
])
?
(
string
)
$table
[
'tableName'
]
:
(
string
)
$className
;
foreach
(
$table
[
'columns'
]
as
$columnName
=>
$field
)
{
$colDesc
=
array
();
$colDesc
[
'name'
]
=
isset
(
$field
[
'name'
])
?
(
string
)
$field
[
'name'
]
:
$columnName
;
$colDesc
[
'type'
]
=
isset
(
$field
[
'type'
])
?
(
string
)
$field
[
'type'
]
:
null
;
$colDesc
[
'ptype'
]
=
isset
(
$field
[
'ptype'
])
?
(
string
)
$field
[
'ptype'
]
:
(
string
)
$colDesc
[
'type'
];
$colDesc
[
'length'
]
=
isset
(
$field
[
'length'
])
?
(
int
)
$field
[
'length'
]
:
null
;
$colDesc
[
'fixed'
]
=
isset
(
$field
[
'fixed'
])
?
(
int
)
$field
[
'fixed'
]
:
null
;
$colDesc
[
'unsigned'
]
=
isset
(
$field
[
'unsigned'
])
?
(
bool
)
$field
[
'unsigned'
]
:
null
;
$colDesc
[
'primary'
]
=
isset
(
$field
[
'primary'
])
?
(
bool
)
(
isset
(
$field
[
'primary'
])
&&
$field
[
'primary'
])
:
null
;
$colDesc
[
'default'
]
=
isset
(
$field
[
'default'
])
?
(
string
)
$field
[
'default'
]
:
null
;
$colDesc
[
'notnull'
]
=
isset
(
$field
[
'notnull'
])
?
(
bool
)
(
isset
(
$field
[
'notnull'
])
&&
$field
[
'notnull'
])
:
null
;
$colDesc
[
'autoinc'
]
=
isset
(
$field
[
'autoinc'
])
?
(
bool
)
(
isset
(
$field
[
'autoinc'
])
&&
$field
[
'autoinc'
])
:
null
;
$colDesc
[
'values'
]
=
isset
(
$field
[
'values'
])
?
(
array
)
$field
[
'values'
]
:
null
;
$columns
[(
string
)
$colDesc
[
'name'
]]
=
$colDesc
;
}
$build
[
$className
][
'tableName'
]
=
$tableName
;
$build
[
$className
][
'className'
]
=
$className
;
if
(
isset
(
$table
[
'columns'
]))
{
foreach
(
$table
[
'columns'
]
as
$columnName
=>
$field
)
{
$colDesc
=
array
();
$colDesc
[
'name'
]
=
isset
(
$field
[
'name'
])
?
(
string
)
$field
[
'name'
]
:
$columnName
;
$colDesc
[
'type'
]
=
isset
(
$field
[
'type'
])
?
(
string
)
$field
[
'type'
]
:
null
;
$colDesc
[
'ptype'
]
=
isset
(
$field
[
'ptype'
])
?
(
string
)
$field
[
'ptype'
]
:
(
string
)
$colDesc
[
'type'
];
$colDesc
[
'length'
]
=
isset
(
$field
[
'length'
])
?
(
int
)
$field
[
'length'
]
:
null
;
$colDesc
[
'fixed'
]
=
isset
(
$field
[
'fixed'
])
?
(
int
)
$field
[
'fixed'
]
:
null
;
$colDesc
[
'unsigned'
]
=
isset
(
$field
[
'unsigned'
])
?
(
bool
)
$field
[
'unsigned'
]
:
null
;
$colDesc
[
'primary'
]
=
isset
(
$field
[
'primary'
])
?
(
bool
)
(
isset
(
$field
[
'primary'
])
&&
$field
[
'primary'
])
:
null
;
$colDesc
[
'default'
]
=
isset
(
$field
[
'default'
])
?
(
string
)
$field
[
'default'
]
:
null
;
$colDesc
[
'notnull'
]
=
isset
(
$field
[
'notnull'
])
?
(
bool
)
(
isset
(
$field
[
'notnull'
])
&&
$field
[
'notnull'
])
:
null
;
$colDesc
[
'autoinc'
]
=
isset
(
$field
[
'autoinc'
])
?
(
bool
)
(
isset
(
$field
[
'autoinc'
])
&&
$field
[
'autoinc'
])
:
null
;
$colDesc
[
'values'
]
=
isset
(
$field
[
'values'
])
?
(
array
)
$field
[
'values'
]
:
null
;
$build
[
$className
][
'columns'
]
=
$columns
;
$build
[
$className
][
'relations'
]
=
isset
(
$table
[
'relations'
])
?
$table
[
'relations'
]
:
array
();
$columns
[(
string
)
$colDesc
[
'name'
]]
=
$colDesc
;
}
$build
[
$className
][
'tableName'
]
=
$tableName
;
$build
[
$className
][
'columns'
]
=
$columns
;
$build
[
$className
][
'relations'
]
=
isset
(
$table
[
'relations'
])
?
$table
[
'relations'
]
:
array
();
}
if
(
isset
(
$table
[
'inheritance'
]))
{
$build
[
$className
][
'inheritance'
]
=
$table
[
'inheritance'
];
}
}
return
$build
;
...
...
@@ -134,9 +145,12 @@ class Doctrine_Import_Schema
public
function
buildRelationships
(
$array
)
{
foreach
(
$array
as
$name
=>
$properties
)
{
if
(
!
isset
(
$properties
[
'relations'
]))
{
continue
;
}
$className
=
$properties
[
'className'
];
$relations
=
$properties
[
'relations'
];
$columns
=
$properties
[
'columns'
];
foreach
(
$relations
as
$alias
=>
$relation
)
{
...
...
playground/index.php
View file @
d0898c1a
...
...
@@ -2,4 +2,9 @@
require_once
(
'playground.php'
);
require_once
(
'connection.php'
);
require_once
(
'models.php'
);
require_once
(
'data.php'
);
\ No newline at end of file
require_once
(
'data.php'
);
$tables
[
'Test'
]
=
'Test'
;
$import
=
new
Doctrine_Import_Schema
();
$import
->
importSchema
(
'../tests/schema.yml'
,
'yml'
,
'test_models'
,
$tables
);
\ No newline at end of file
tests/schema.yml
View file @
d0898c1a
---
Test
:
inheritance
:
{
extends
:
User
,
keyField
:
otype
,
keyValue
:
1
}
Account
:
tableName
:
account
className
:
Account
...
...
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