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
...
@@ -90,11 +90,10 @@ class Doctrine_Import_Builder
/**
/**
* This class has been auto-generated by the Doctrine ORM Framework
* This class has been auto-generated by the Doctrine ORM Framework
*/
*/
class
%
s
extends
Doctrine_Record
class
%
s
extends
%
s
{
{
public
function
setTableDefinition
()
public
function
setTableDefinition
()
{
{
%
s
%
s
%
s
}
}
public
function
setUp
()
public
function
setUp
()
...
@@ -112,17 +111,31 @@ END;
...
@@ -112,17 +111,31 @@ END;
* @param string $table
* @param string $table
* @param array $tableColumns
* @param array $tableColumns
*/
*/
public
function
build
ColumnDefinition
(
array
$tableColum
ns
)
public
function
build
TableDefinition
(
array
$options
,
array
$columns
,
array
$relatio
ns
)
{
{
$columns
=
array
();
$ret
=
array
();
$i
=
1
;
$i
=
0
;
foreach
(
$tableColumns
as
$name
=>
$column
)
{
$columns
[
$i
]
=
' $this->hasColumn(\''
.
$name
.
'\', \''
.
$column
[
'type'
]
.
'\''
;
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'
])
{
if
(
$column
[
'length'
])
{
$
columns
[
$i
]
.=
', '
.
$column
[
'length'
];
$
ret
[
$i
]
.=
', '
.
$column
[
'length'
];
}
else
{
}
else
{
$
columns
[
$i
]
.=
', null'
;
$
ret
[
$i
]
.=
', null'
;
}
}
$a
=
array
();
$a
=
array
();
...
@@ -150,24 +163,32 @@ END;
...
@@ -150,24 +163,32 @@ END;
}
}
if
(
!
empty
(
$a
))
{
if
(
!
empty
(
$a
))
{
$
columns
[
$i
]
.=
', '
.
'array('
;
$
ret
[
$i
]
.=
', '
.
'array('
;
$length
=
strlen
(
$
columns
[
$i
]);
$length
=
strlen
(
$
ret
[
$i
]);
$
columns
[
$i
]
.=
implode
(
','
.
PHP_EOL
.
str_repeat
(
' '
,
$length
),
$a
)
.
')'
;
$
ret
[
$i
]
.=
implode
(
','
.
PHP_EOL
.
str_repeat
(
' '
,
$length
),
$a
)
.
')'
;
}
}
$columns
[
$i
]
.=
');'
;
$ret
[
$i
]
.=
');'
;
if
(
$i
<
(
count
(
$
tableC
olumns
)
-
1
))
{
if
(
$i
<
(
count
(
$
c
olumns
)
-
1
))
{
$
columns
[
$i
]
.=
PHP_EOL
;
$
ret
[
$i
]
.=
PHP_EOL
;
}
}
$i
++
;
$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
();
$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
)
{
foreach
(
$relations
as
$name
=>
$relation
)
{
$alias
=
(
isset
(
$relation
[
'alias'
])
&&
$relation
[
'alias'
]
!==
$name
)
?
' as '
.
$relation
[
'alias'
]
:
''
;
$alias
=
(
isset
(
$relation
[
'alias'
])
&&
$relation
[
'alias'
]
!==
$name
)
?
' as '
.
$relation
[
'alias'
]
:
''
;
...
@@ -219,27 +240,32 @@ END;
...
@@ -219,27 +240,32 @@ END;
$i
++
;
$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
);
return
implode
(
"
\n
"
,
$ret
);
}
}
public
function
buildDefinition
(
array
$options
,
array
$columns
,
array
$relations
=
array
())
public
function
buildDefinition
(
array
$options
,
array
$columns
,
array
$relations
=
array
())
{
{
if
(
!
isset
(
$options
[
'className'
]))
{
if
(
!
isset
(
$options
[
'className'
]))
{
throw
new
Doctrine_Import_Builder_Exception
(
'Missing class name.'
);
throw
new
Doctrine_Import_Builder_Exception
(
'Missing class name.'
);
}
}
$opt
=
isset
(
$options
[
'tableName'
])
&&
!
empty
(
$options
[
'tableName'
])
?
str_repeat
(
' '
,
8
)
.
'$this->setTableName(\''
.
$options
[
'tableName'
]
.
'\');'
:
''
;
$className
=
$options
[
'className'
];
$extends
=
isset
(
$options
[
'inheritance'
][
'extends'
])
?
$options
[
'inheritance'
][
'extends'
]
:
'Doctrine_Record'
;
$content
=
sprintf
(
self
::
$tpl
,
$options
[
'className'
],
$opt
,
$this
->
buildColumnDefinition
(
$columns
),
$content
=
sprintf
(
self
::
$tpl
,
$className
,
$this
->
buildRelationDefinition
(
$relations
));
$extends
,
$this
->
buildTableDefinition
(
$options
,
$columns
,
$relations
),
$this
->
buildSetUp
(
$options
,
$columns
,
$relations
));
return
$content
;
return
$content
;
}
}
public
function
buildRecord
(
$options
,
$columns
,
$relations
)
public
function
buildRecord
(
array
$options
,
array
$columns
,
array
$relations
=
array
()
)
{
{
if
(
!
isset
(
$options
[
'className'
]))
{
if
(
!
isset
(
$options
[
'className'
]))
{
throw
new
Doctrine_Import_Builder_Exception
(
'Missing class name.'
);
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
...
@@ -73,8 +73,13 @@ class Doctrine_Import_Schema
$options
=
array
();
$options
=
array
();
$options
[
'className'
]
=
$properties
[
'className'
];
$options
[
'className'
]
=
$properties
[
'className'
];
$options
[
'fileName'
]
=
$directory
.
DIRECTORY_SEPARATOR
.
$properties
[
'className'
]
.
'.class.php'
;
$options
[
'fileName'
]
=
$directory
.
DIRECTORY_SEPARATOR
.
$properties
[
'className'
]
.
'.class.php'
;
$options
[
'tableName'
]
=
isset
(
$properties
[
'tableName'
])
?
$properties
[
'tableName'
]
:
null
;
$options
[
'tableName'
]
=
isset
(
$properties
[
'tableName'
])
?
$properties
[
'tableName'
]
:
null
;
$columns
=
$properties
[
'columns'
];
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
();
$relations
=
isset
(
$this
->
relations
[
$options
[
'className'
]])
?
$this
->
relations
[
$options
[
'className'
]]
:
array
();
...
@@ -103,29 +108,35 @@ class Doctrine_Import_Schema
...
@@ -103,29 +108,35 @@ class Doctrine_Import_Schema
$className
=
isset
(
$table
[
'className'
])
?
(
string
)
$table
[
'className'
]
:
(
string
)
$className
;
$className
=
isset
(
$table
[
'className'
])
?
(
string
)
$table
[
'className'
]
:
(
string
)
$className
;
$tableName
=
isset
(
$table
[
'tableName'
])
?
(
string
)
$table
[
'tableName'
]
:
(
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
;
$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
;
$columns
[(
string
)
$colDesc
[
'name'
]]
=
$colDesc
;
$build
[
$className
][
'relations'
]
=
isset
(
$table
[
'relations'
])
?
$table
[
'relations'
]
:
array
();
}
$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
;
return
$build
;
...
@@ -134,9 +145,12 @@ class Doctrine_Import_Schema
...
@@ -134,9 +145,12 @@ class Doctrine_Import_Schema
public
function
buildRelationships
(
$array
)
public
function
buildRelationships
(
$array
)
{
{
foreach
(
$array
as
$name
=>
$properties
)
{
foreach
(
$array
as
$name
=>
$properties
)
{
if
(
!
isset
(
$properties
[
'relations'
]))
{
continue
;
}
$className
=
$properties
[
'className'
];
$className
=
$properties
[
'className'
];
$relations
=
$properties
[
'relations'
];
$relations
=
$properties
[
'relations'
];
$columns
=
$properties
[
'columns'
];
foreach
(
$relations
as
$alias
=>
$relation
)
{
foreach
(
$relations
as
$alias
=>
$relation
)
{
...
...
playground/index.php
View file @
d0898c1a
...
@@ -2,4 +2,9 @@
...
@@ -2,4 +2,9 @@
require_once
(
'playground.php'
);
require_once
(
'playground.php'
);
require_once
(
'connection.php'
);
require_once
(
'connection.php'
);
require_once
(
'models.php'
);
require_once
(
'models.php'
);
require_once
(
'data.php'
);
require_once
(
'data.php'
);
\ No newline at end of file
$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
:
Account
:
tableName
:
account
tableName
:
account
className
:
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