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
ad55d163
Commit
ad55d163
authored
Sep 20, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for schema importing.
parent
29ff0dee
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
82 additions
and
72 deletions
+82
-72
Doctrine.php
lib/Doctrine.php
+2
-2
Schema.php
lib/Doctrine/Export/Schema.php
+51
-53
Schema.php
lib/Doctrine/Import/Schema.php
+20
-8
Yml.php
lib/Doctrine/Import/Schema/Yml.php
+7
-7
YmlTestCase.php
tests/Import/Schema/YmlTestCase.php
+2
-2
No files found.
lib/Doctrine.php
View file @
ad55d163
...
...
@@ -442,7 +442,7 @@ final class Doctrine
*/
public
static
function
loadModels
(
$directory
)
{
$declared
=
get_declared_classes
();
$declared
=
array
();
if
(
$directory
!==
null
)
{
foreach
((
array
)
$directory
as
$dir
)
{
...
...
@@ -457,7 +457,7 @@ final class Doctrine
}
}
$declared
=
array_diff
(
get_declared_classes
(),
$declared
);
$declared
=
get_declared_classes
(
);
}
return
self
::
getLoadedModels
(
$declared
);
...
...
lib/Doctrine/Export/Schema.php
View file @
ad55d163
...
...
@@ -36,7 +36,7 @@
* @version $Revision: 1838 $
* @author Nicolas Bérard-Nault <nicobn@gmail.com>
*/
abstract
class
Doctrine_Export_Schema
class
Doctrine_Export_Schema
{
/**
* build
...
...
@@ -46,7 +46,10 @@ abstract class Doctrine_Export_Schema
* @param string $array
* @return void
*/
abstract
function
build
(
$array
);
public
function
build
(
$array
)
{
throw
new
Doctrine_Export_Exception
(
'This functionality is implemented by the driver'
);
}
/**
* dump
...
...
@@ -64,43 +67,6 @@ abstract class Doctrine_Export_Schema
file_put_contents
(
$schema
,
$data
);
}
public
function
getDirectoryTables
(
$directory
)
{
$parent
=
new
ReflectionClass
(
'Doctrine_Record'
);
$declared
=
get_declared_classes
();
if
(
$directory
!==
null
)
{
foreach
((
array
)
$directory
as
$dir
)
{
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$dir
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
foreach
(
$it
as
$file
)
{
$e
=
explode
(
'.'
,
$file
->
getFileName
());
if
(
end
(
$e
)
===
'php'
&&
strpos
(
$file
->
getFileName
(),
'.inc'
)
===
false
)
{
require_once
$file
->
getPathName
();
}
}
}
$declared
=
get_declared_classes
();
$tables
=
array
();
foreach
(
$declared
as
$name
)
{
$class
=
new
ReflectionClass
(
$name
);
if
(
$class
->
isSubclassOf
(
$parent
)
AND
!
$class
->
isAbstract
())
{
$tables
[
$name
]
=
$name
;
}
}
return
$tables
;
}
}
/**
* buildSchema
*
...
...
@@ -109,11 +75,11 @@ abstract class Doctrine_Export_Schema
* @param string $directory
* @return void
*/
public
function
buildSchema
(
$directory
)
public
function
buildSchema
(
$directory
,
$models
=
array
()
)
{
$array
=
array
(
'tables'
=>
array
()
);
$array
=
array
();
$
tables
=
$this
->
getDirectoryTable
s
(
$directory
);
$
loadedModels
=
Doctrine
::
loadModel
s
(
$directory
);
$parent
=
new
ReflectionClass
(
'Doctrine_Record'
);
...
...
@@ -122,7 +88,11 @@ abstract class Doctrine_Export_Schema
// we iterate trhough the diff of previously declared classes
// and currently declared classes
foreach
(
$tables
as
$name
)
{
foreach
(
$loadedModels
as
$name
)
{
if
(
!
empty
(
$models
)
&&
!
in_array
(
$name
,
$models
))
{
continue
;
}
$class
=
new
ReflectionClass
(
$name
);
// check if class is an instance of Doctrine_Record and not abstract
...
...
@@ -146,22 +116,47 @@ abstract class Doctrine_Export_Schema
}
$record
=
new
$name
();
$
t
able
=
$record
->
getTable
();
$
recordT
able
=
$record
->
getTable
();
$data
=
$
t
able
->
getExportableFormat
();
$data
=
$
recordT
able
->
getExportableFormat
();
$table
=
array
();
$table
[
'
n
ame'
]
=
$data
[
'tableName'
];
$table
[
'class'
]
=
get_class
(
$record
);
$table
[
'
tableN
ame'
]
=
$data
[
'tableName'
];
$table
[
'class
Name
'
]
=
get_class
(
$record
);
foreach
(
$data
[
'columns'
]
AS
$name
=>
$column
)
{
foreach
(
$data
[
'columns'
]
AS
$name
=>
$column
)
{
$data
[
'columns'
][
$name
][
'name'
]
=
$name
;
}
$table
[
'columns'
]
=
$data
[
'columns'
];
$array
[
'tables'
][
$data
[
'tableName'
]]
=
$table
;
$relations
=
$recordTable
->
getRelations
();
foreach
(
$relations
as
$key
=>
$relation
)
{
$relationData
=
$relation
->
toArray
();
$relationKey
=
$relationData
[
'alias'
];
if
(
isset
(
$relationData
[
'refTable'
])
&&
$relationData
[
'refTable'
])
{
$table
[
'relations'
][
$relationKey
][
'refClass'
]
=
$relationData
[
'refTable'
]
->
getComponentName
();
}
if
(
isset
(
$relationData
[
'class'
])
&&
$relationData
[
'class'
]
&&
$relation
[
'class'
]
!=
$relationKey
)
{
$table
[
'relations'
][
$relationKey
][
'class'
]
=
$relationData
[
'class'
];
}
$table
[
'relations'
][
$relationKey
][
'local'
]
=
$relationData
[
'local'
];
$table
[
'relations'
][
$relationKey
][
'foreign'
]
=
$relationData
[
'foreign'
];
if
(
$relationData
[
'type'
]
===
Doctrine_Relation
::
ONE
)
{
$table
[
'relations'
][
$relationKey
][
'type'
]
=
'one'
;
}
else
if
(
$relationData
[
'type'
]
===
Doctrine_Relation
::
MANY
)
{
$table
[
'relations'
][
$relationKey
][
'type'
]
=
'many'
;
}
else
{
$table
[
'relations'
][
$relationKey
][
'type'
]
=
'one'
;
}
}
$array
[
$table
[
'className'
]]
=
$table
;
}
return
$array
;
...
...
@@ -174,10 +169,13 @@ abstract class Doctrine_Export_Schema
* @param string $directory
* @return void
*/
public
function
exportSchema
(
$schema
,
$
directory
)
public
function
exportSchema
(
$schema
,
$
format
,
$directory
,
$models
=
array
()
)
{
$array
=
$this
->
buildSchema
(
$directory
);
$className
=
'Doctrine_Export_Schema_'
.
ucwords
(
$format
);
$export
=
new
$className
();
$array
=
$export
->
buildSchema
(
$directory
,
$models
);
return
$
this
->
dump
(
$array
,
$schema
);
return
$
export
->
dump
(
$array
,
$schema
);
}
}
\ No newline at end of file
lib/Doctrine/Import/Schema.php
View file @
ad55d163
...
...
@@ -37,7 +37,7 @@
* @author Nicolas Bérard-Nault <nicobn@gmail.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
abstract
class
Doctrine_Import_Schema
class
Doctrine_Import_Schema
{
public
$relations
=
array
();
...
...
@@ -47,7 +47,10 @@ abstract class Doctrine_Import_Schema
* @param string $schema
* @access public
*/
abstract
function
parseSchema
(
$schema
);
public
function
parseSchema
(
$schema
)
{
throw
new
Doctrine_Import_Exception
(
'This functionality is implemented by the driver'
);
}
/**
* parse
...
...
@@ -72,30 +75,39 @@ abstract class Doctrine_Import_Schema
* A method to import a Schema and translate it into a Doctrine_Record object
*
* @param string $schema The file containing the XML schema
* @param string $directory The directory where the Doctrine_Record class will
* be written
* @param string $directory The directory where the Doctrine_Record class will be written
* @param array $models Optional array of models to import
*
* @access public
*/
public
function
importSchema
(
$schema
,
$
directory
)
public
function
importSchema
(
$schema
,
$
format
,
$directory
,
$models
=
array
()
)
{
$className
=
'Doctrine_Import_Schema_'
.
ucwords
(
$format
);
$import
=
new
$className
();
$builder
=
new
Doctrine_Import_Builder
();
$builder
->
setTargetPath
(
$directory
);
$array
=
array
();
foreach
((
array
)
$schema
AS
$s
)
{
$array
=
array_merge
(
$array
,
$
this
->
parseSchema
(
$s
));
$array
=
array_merge
(
$array
,
$
import
->
parseSchema
(
$s
));
}
$
this
->
buildRelationships
(
$array
);
$
import
->
buildRelationships
(
$array
);
foreach
(
$array
as
$name
=>
$properties
)
{
if
(
!
empty
(
$models
)
&&
!
in_array
(
$properties
[
'className'
],
$models
))
{
continue
;
}
$options
=
array
();
$options
[
'className'
]
=
$properties
[
'className'
];
$options
[
'fileName'
]
=
$directory
.
DIRECTORY_SEPARATOR
.
$properties
[
'className'
]
.
'.class.php'
;
$columns
=
$properties
[
'columns'
];
$relations
=
isset
(
$
this
->
relations
[
$options
[
'className'
]])
?
$this
->
relations
[
$options
[
'className'
]]
:
array
();
$relations
=
isset
(
$
import
->
relations
[
$options
[
'className'
]])
?
$import
->
relations
[
$options
[
'className'
]]
:
array
();
$builder
->
buildRecord
(
$options
,
$columns
,
$relations
);
}
...
...
lib/Doctrine/Import/Schema/Yml.php
View file @
ad55d163
...
...
@@ -52,11 +52,11 @@ class Doctrine_Import_Schema_Yml extends Doctrine_Import_Schema
{
$array
=
$this
->
parse
(
$schema
);
foreach
(
$array
as
$
table
Name
=>
$table
)
{
foreach
(
$array
as
$
class
Name
=>
$table
)
{
$columns
=
array
();
$
tableName
=
isset
(
$table
[
'tableName'
])
?
(
string
)
$table
[
'tableName'
]
:
(
string
)
$table
Name
;
$
className
=
isset
(
$table
[
'className'
])
?
(
string
)
$table
[
'className'
]
:
(
string
)
$table
Name
;
$
className
=
isset
(
$table
[
'className'
])
?
(
string
)
$table
[
'className'
]
:
(
string
)
$class
Name
;
$
tableName
=
isset
(
$table
[
'tableName'
])
?
(
string
)
$table
[
'tableName'
]
:
(
string
)
$class
Name
;
foreach
(
$table
[
'columns'
]
as
$columnName
=>
$field
)
{
...
...
@@ -75,11 +75,11 @@ class Doctrine_Import_Schema_Yml extends Doctrine_Import_Schema
$columns
[(
string
)
$colDesc
[
'name'
]]
=
$colDesc
;
}
$tables
[
$
table
Name
][
'tableName'
]
=
$tableName
;
$tables
[
$
table
Name
][
'className'
]
=
$className
;
$tables
[
$
class
Name
][
'tableName'
]
=
$tableName
;
$tables
[
$
class
Name
][
'className'
]
=
$className
;
$tables
[
$
table
Name
][
'columns'
]
=
$columns
;
$tables
[
$
table
Name
][
'relations'
]
=
isset
(
$table
[
'relations'
])
?
$table
[
'relations'
]
:
array
();
$tables
[
$
class
Name
][
'columns'
]
=
$columns
;
$tables
[
$
class
Name
][
'relations'
]
=
isset
(
$table
[
'relations'
])
?
$table
[
'relations'
]
:
array
();
}
return
$tables
;
...
...
tests/Import/Schema/YmlTestCase.php
View file @
ad55d163
...
...
@@ -34,8 +34,8 @@ class Doctrine_Import_Schema_Yml_TestCase extends Doctrine_UnitTestCase
{
public
function
testYmlImport
()
{
$import
=
new
Doctrine_Import_Schema
_Yml
();
$import
->
importSchema
(
'schema.yml'
,
'classes'
);
$import
=
new
Doctrine_Import_Schema
();
$import
->
importSchema
(
'schema.yml'
,
'
yml'
,
'
classes'
);
if
(
!
file_exists
(
'classes/User.class.php'
))
{
$this
->
fail
();
...
...
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