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
a1708227
Commit
a1708227
authored
Sep 14, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for yml importing/exporting of schema.
parent
d62500e7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
33 deletions
+92
-33
Builder.php
lib/Doctrine/Import/Builder.php
+13
-0
Schema.php
lib/Doctrine/Import/Schema.php
+48
-7
Xml.php
lib/Doctrine/Import/Schema/Xml.php
+1
-1
Yml.php
lib/Doctrine/Import/Schema/Yml.php
+28
-22
run.php
tests/run.php
+2
-3
No files found.
lib/Doctrine/Import/Builder.php
View file @
a1708227
...
...
@@ -167,6 +167,7 @@ END;
{
$ret
=
array
();
$i
=
0
;
foreach
(
$relations
as
$name
=>
$relation
)
{
$alias
=
(
isset
(
$relation
[
'alias'
])
&&
$relation
[
'alias'
]
!==
$name
)
?
' as '
.
$relation
[
'alias'
]
:
''
;
...
...
@@ -180,31 +181,43 @@ END;
}
else
{
$ret
[
$i
]
=
' $this->hasMany(\''
.
$name
.
$alias
.
'\''
;
}
$a
=
array
();
if
(
isset
(
$relation
[
'refClass'
]))
{
$a
[]
=
'\'refClass\' => '
.
var_export
(
$relation
[
'refClass'
],
true
);
}
if
(
isset
(
$relation
[
'deferred'
])
&&
$relation
[
'deferred'
])
{
$a
[]
=
'\'default\' => '
.
var_export
(
$relation
[
'deferred'
],
true
);
}
if
(
isset
(
$relation
[
'local'
])
&&
$relation
[
'local'
])
{
$a
[]
=
'\'local\' => '
.
var_export
(
$relation
[
'local'
],
true
);
}
if
(
isset
(
$relation
[
'foreign'
])
&&
$relation
[
'foreign'
])
{
$a
[]
=
'\'foreign\' => '
.
var_export
(
$relation
[
'foreign'
],
true
);
}
if
(
isset
(
$relation
[
'onDelete'
])
&&
$relation
[
'onDelete'
])
{
$a
[]
=
'\'onDelete\' => '
.
var_export
(
$relation
[
'onDelete'
],
true
);
}
if
(
isset
(
$relation
[
'onUpdate'
])
&&
$relation
[
'onUpdate'
])
{
$a
[]
=
'\'onUpdate\' => '
.
var_export
(
$relation
[
'onUpdate'
],
true
);
}
if
(
!
empty
(
$a
))
{
$ret
[
$i
]
.=
', '
.
'array('
;
$length
=
strlen
(
$ret
[
$i
]);
$ret
[
$i
]
.=
implode
(
','
.
PHP_EOL
.
str_repeat
(
' '
,
$length
),
$a
)
.
')'
;
}
$ret
[
$i
]
.=
');'
;
$i
++
;
}
return
implode
(
"
\n
"
,
$ret
);
}
...
...
lib/Doctrine/Import/Schema.php
View file @
a1708227
...
...
@@ -38,7 +38,9 @@
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
abstract
class
Doctrine_Import_Schema
{
{
public
$relationColumns
=
array
();
/**
* Parse the schema and return it in an array
*
...
...
@@ -78,16 +80,55 @@ abstract class Doctrine_Import_Schema
{
$builder
=
new
Doctrine_Import_Builder
();
$builder
->
setTargetPath
(
$directory
);
$array
=
$this
->
parseSchema
(
$schema
);
$array
=
array
();
foreach
((
array
)
$schema
AS
$s
)
{
$array
=
array_merge
(
$array
,
$this
->
parseSchema
(
$s
));
}
$this
->
buildRelations
(
$array
);
foreach
(
$array
as
$name
=>
$properties
)
{
$options
[
'className'
]
=
$properties
[
'class'
];
$options
[
'fileName'
]
=
$directory
.
DIRECTORY_SEPARATOR
.
$properties
[
'class'
]
.
'.class.php'
;
$options
=
array
();
$options
[
'className'
]
=
$properties
[
'className'
];
$options
[
'fileName'
]
=
$directory
.
DIRECTORY_SEPARATOR
.
$properties
[
'className'
]
.
'.class.php'
;
$columns
=
$properties
[
'columns'
];
$builder
->
buildRecord
(
$options
,
$columns
,
array
());
$relations
=
isset
(
$this
->
relations
[
$options
[
'className'
]])
?
$this
->
relations
[
$options
[
'className'
]]
:
array
();
$builder
->
buildRecord
(
$options
,
$columns
,
$relations
);
}
}
public
function
buildRelations
(
$array
)
{
foreach
(
$array
AS
$name
=>
$properties
)
{
$className
=
$properties
[
'className'
];
$columns
=
$properties
[
'columns'
];
foreach
(
$columns
as
$column
)
{
if
(
$this
->
isRelation
(
$column
))
{
$this
->
addRelationColumn
(
$className
,
$column
);
}
}
}
}
$this
->
processRelationships
();
}
public
function
isRelation
(
$column
)
{
return
isset
(
$column
[
'foreignClass'
])
&&
isset
(
$column
[
'foreignReference'
]);
}
public
function
addRelationColumn
(
$className
,
$column
)
{
$this
->
relationColumns
[
$className
][]
=
$column
;
}
public
function
processRelationships
()
{
}
}
\ No newline at end of file
lib/Doctrine/Import/Schema/Xml.php
View file @
a1708227
...
...
@@ -52,7 +52,7 @@ class Doctrine_Import_Schema_Xml extends Doctrine_Import_Schema
{
$xmlObj
=
$this
->
parse
(
$schema
);
foreach
(
$xmlObj
->
tables
->
table
as
$table
)
{
foreach
(
$xmlObj
->
tables
as
$table
)
{
$columns
=
array
();
// Go through all columns...
...
...
lib/Doctrine/Import/Schema/Yml.php
View file @
a1708227
...
...
@@ -51,34 +51,40 @@ class Doctrine_Import_Schema_Yml extends Doctrine_Import_Schema
public
function
parseSchema
(
$schema
)
{
$array
=
$this
->
parse
(
$schema
);
$tables
=
$array
[
'schema'
][
'tables'
];
foreach
(
$tables
as
$table
)
{
foreach
(
$array
as
$tableName
=>
$table
)
{
$columns
=
array
();
foreach
(
$table
[
'columns'
]
as
$field
)
{
$colDesc
=
array
(
'name'
=>
isset
(
$field
[
'name'
])
?
(
string
)
$field
[
'name'
]
:
null
,
'type'
=>
isset
(
$field
[
'type'
])
?
(
string
)
$field
[
'type'
]
:
null
,
'ptype'
=>
isset
(
$field
[
'type'
])
?
(
string
)
$field
[
'type'
]
:
null
,
'length'
=>
isset
(
$field
[
'length'
])
?
(
int
)
$field
[
'length'
]
:
null
,
'fixed'
=>
isset
(
$field
[
'fixed'
])
?
(
int
)
$field
[
'fixed'
]
:
null
,
'unsigned'
=>
isset
(
$field
[
'unsigned'
])
?
(
bool
)
$field
[
'unsigned'
]
:
null
,
'primary'
=>
isset
(
$field
[
'primary'
])
?
(
bool
)
(
isset
(
$field
[
'primary'
])
&&
$field
[
'primary'
])
:
null
,
'default'
=>
isset
(
$field
[
'default'
])
?
(
string
)
$field
[
'default'
]
:
null
,
'notnull'
=>
isset
(
$field
[
'notnull'
])
?
(
bool
)
(
isset
(
$field
[
'notnull'
])
&&
$field
[
'notnull'
])
:
null
,
'autoinc'
=>
isset
(
$field
[
'autoincrement'
])
?
(
bool
)
(
isset
(
$field
[
'autoincrement'
])
&&
$field
[
'autoincrement'
])
:
null
,
);
$tableName
=
isset
(
$table
[
'tableName'
])
?
(
string
)
$table
[
'tableName'
]
:
(
string
)
$tableName
;
$className
=
isset
(
$table
[
'className'
])
?
(
string
)
$table
[
'className'
]
:
(
string
)
$tableName
;
$columns
[(
string
)
$field
[
'name'
]]
=
$colDesc
;
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
[
'foreignClass'
]
=
isset
(
$field
[
'foreignClass'
])
?
(
string
)
$field
[
'foreignClass'
]
:
null
;
$colDesc
[
'foreignReference'
]
=
isset
(
$field
[
'foreignReference'
])
?
(
string
)
$field
[
'foreignReference'
]
:
null
;
$colDesc
[
'localName'
]
=
isset
(
$field
[
'localName'
])
?
(
string
)
$field
[
'localName'
]
:
null
;
$colDesc
[
'foreignName'
]
=
isset
(
$field
[
'foreignName'
])
?
(
string
)
$field
[
'foreignName'
]
:
null
;
$colDesc
[
'counterpart'
]
=
isset
(
$field
[
'counterpart'
])
?
(
string
)
$field
[
'counterpart'
]
:
null
;
$colDesc
[
'onDelete'
]
=
isset
(
$field
[
'onDelete'
])
?
(
string
)
$field
[
'onDelete'
]
:
null
;
$colDesc
[
'onUpdate'
]
=
isset
(
$field
[
'onUpdate'
])
?
(
string
)
$field
[
'onUpdate'
]
:
null
;
$columns
[(
string
)
$colDesc
[
'name'
]]
=
$colDesc
;
}
$class
=
$table
[
'class'
]
?
(
string
)
$table
[
'class'
]
:
(
string
)
$table
[
'name'
];
$tables
[
(
string
)
$table
[
'name'
]][
'name'
]
=
(
string
)
$table
[
'name'
]
;
$tables
[
(
string
)
$table
[
'name'
]][
'class'
]
=
(
string
)
$class
;
$tables
[
$tableName
][
'tableName'
]
=
$tableName
;
$tables
[
$tableName
][
'className'
]
=
$className
;
$tables
[
(
string
)
$table
[
'name'
]
][
'columns'
]
=
$columns
;
$tables
[
$tableName
][
'columns'
]
=
$columns
;
}
return
$tables
;
...
...
tests/run.php
View file @
a1708227
...
...
@@ -304,11 +304,10 @@ $test->addTestCase(new Doctrine_RawSql_TestCase());
$test
->
addTestCase
(
new
Doctrine_NewCore_TestCase
());
//$test->addTestCase(new Doctrine_Import_Schema_Xml_TestCase());
//$test->addTestCase(new Doctrine_Export_Schema_Xml_TestCase());
$test
->
addTestCase
(
new
Doctrine_Import_Schema_Yml_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Import_Schema_Xml_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Export_Schema_Yml_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Export_Schema_Xml_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Template_TestCase
());
...
...
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