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
0da62430
Commit
0da62430
authored
Oct 25, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes to model generation.
parent
bb1e87b0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
122 additions
and
102 deletions
+122
-102
Builder.php
lib/Doctrine/Import/Builder.php
+37
-26
Schema.php
lib/Doctrine/Import/Schema.php
+85
-76
No files found.
lib/Doctrine/Import/Builder.php
View file @
0da62430
...
...
@@ -38,13 +38,6 @@
*/
class
Doctrine_Import_Builder
{
/**
* written
*
* @var array
*/
private
$written
=
array
();
/**
* Path
*
...
...
@@ -59,7 +52,7 @@ class Doctrine_Import_Builder
*
* @var string
*/
private
$packagePrefix
=
'Package'
;
private
$package
s
Prefix
=
'Package'
;
/**
* packagesPath
...
...
@@ -102,6 +95,13 @@ class Doctrine_Import_Builder
*/
private
$baseClassesDirectory
=
'generated'
;
/**
* baseClassName
*
* @var string
*/
private
$baseClassName
=
'Doctrine_Record'
;
/**
* tpl
*
...
...
@@ -141,12 +141,12 @@ class Doctrine_Import_Builder
/**
* setPackagePath
*
* @param string $packagePrefix
* @param string $package
s
Prefix
* @return void
*/
public
function
setPackage
Prefix
(
$package
Prefix
)
public
function
setPackage
sPrefix
(
$packages
Prefix
)
{
$this
->
package
Prefix
=
$package
Prefix
;
$this
->
package
sPrefix
=
$packages
Prefix
;
}
/**
...
...
@@ -204,6 +204,16 @@ class Doctrine_Import_Builder
$this
->
baseClassesDirectory
;
}
/**
* setBaseClassName
*
* @package default
*/
public
function
setBaseClassName
(
$className
)
{
$this
->
baseClassName
=
$className
;
}
/**
* setSuffix
*
...
...
@@ -289,7 +299,7 @@ END;
$i
=
0
;
if
(
isset
(
$options
[
'inheritance'
][
'extends'
])
&&
!
isset
(
$options
[
'override_parent'
]
))
{
if
(
isset
(
$options
[
'inheritance'
][
'extends'
])
&&
!
(
isset
(
$options
[
'override_parent'
])
&&
$options
[
'override_parent'
]
==
false
))
{
$ret
[
$i
]
=
"
\t\t
parent::setTableDefinition();"
;
$i
++
;
}
...
...
@@ -358,8 +368,11 @@ END;
$ret
[
$i
]
=
$this
->
buildActAs
(
$actAs
);
if
(
!
empty
(
$ret
))
{
return
"
\n\t
public function setTableDefinition()"
.
"
\n\t
{\n"
.
implode
(
"
\n
"
,
$ret
)
.
"
\n\t
}"
;
$code
=
implode
(
"
\n
"
,
$ret
);
$code
=
trim
(
$code
);
if
(
$code
)
{
return
"
\n\t
public function setTableDefinition()"
.
"
\n\t
{
\n\t\t".$code."\n\t
}
"
;
}
}
...
...
@@ -539,7 +552,7 @@ END;
$ret
=
array
();
$i
=
0
;
if
(
!
(
isset
(
$options
[
'override_parent'
])
&&
$options
[
'override_parent'
]
===
tru
e
))
{
if
(
isset
(
$options
[
'inheritance'
][
'extends'
])
&&
!
(
isset
(
$options
[
'override_parent'
])
&&
$options
[
'override_parent'
]
==
fals
e
))
{
$ret
[
$i
]
=
"
\t\t
parent::setUp();"
;
$i
++
;
}
...
...
@@ -604,8 +617,11 @@ END;
$ret
[
$i
]
=
"
\t\t
"
.
'$this->setInheritanceMap(array(\''
.
$options
[
'inheritance'
][
'keyField'
]
.
'\' => '
.
$options
[
'inheritance'
][
'keyValue'
]
.
'));'
;
}
if
(
!
empty
(
$ret
))
{
return
"
\n\t
public function setUp()
\n\t
{\n"
.
implode
(
"
\n
"
,
$ret
)
.
"
\n\t
}"
;
$code
=
implode
(
"
\n
"
,
$ret
);
$code
=
trim
(
$code
);
if
(
$code
)
{
return
"
\n\t
public function setUp()
\n\t
{
\n\t\t".$code."\n\t
}
"
;
}
}
...
...
@@ -629,7 +645,7 @@ END;
$abstract
=
isset
(
$options
[
'abstract'
])
&&
$options
[
'abstract'
]
===
true
?
'abstract '
:
null
;
$className
=
$options
[
'className'
];
$extends
=
isset
(
$options
[
'inheritance'
][
'extends'
])
?
$options
[
'inheritance'
][
'extends'
]
:
'Doctrine_Record'
;
$extends
=
isset
(
$options
[
'inheritance'
][
'extends'
])
?
$options
[
'inheritance'
][
'extends'
]
:
$this
->
baseClassName
;
if
(
!
(
isset
(
$options
[
'no_definition'
])
&&
$options
[
'no_definition'
]
===
true
))
{
$definition
=
$this
->
buildTableDefinition
(
$options
,
$columns
,
$relations
,
$indexes
,
$attributes
,
$templates
,
$actAs
);
...
...
@@ -686,7 +702,7 @@ END;
// If we have a package then we need to make this extend the package definition and not the base definition
// The package definition will then extends the base definition
$topLevel
[
'inheritance'
][
'extends'
]
=
(
isset
(
$topLevel
[
'package'
])
&&
$topLevel
[
'package'
])
?
$this
->
packagePrefix
.
$topLevel
[
'className'
]
:
'Base'
.
$topLevel
[
'className'
];
$topLevel
[
'inheritance'
][
'extends'
]
=
(
isset
(
$topLevel
[
'package'
])
&&
$topLevel
[
'package'
])
?
$this
->
package
s
Prefix
.
$topLevel
[
'className'
]
:
'Base'
.
$topLevel
[
'className'
];
$topLevel
[
'no_definition'
]
=
true
;
$topLevel
[
'generate_once'
]
=
true
;
$topLevel
[
'is_main_class'
]
=
true
;
...
...
@@ -744,8 +760,6 @@ END;
$writePath
=
$path
.
DIRECTORY_SEPARATOR
.
$className
.
$this
->
suffix
;
$this
->
written
[
$className
]
=
$writePath
;
if
(
!
file_exists
(
$writePath
))
{
file_put_contents
(
$writePath
,
$content
);
}
...
...
@@ -835,9 +849,6 @@ END;
$code
.=
PHP_EOL
.
$definition
;
$this
->
written
[
$options
[
'className'
]]
=
$writePath
;
if
(
isset
(
$options
[
'generate_once'
])
&&
$options
[
'generate_once'
]
===
true
)
{
if
(
!
file_exists
(
$writePath
))
{
$bytes
=
file_put_contents
(
$writePath
,
$code
);
...
...
lib/Doctrine/Import/Schema.php
View file @
0da62430
...
...
@@ -39,26 +39,40 @@
*/
class
Doctrine_Import_Schema
{
public
$relations
=
array
();
public
$generateBaseClasses
=
false
;
protected
$relations
=
array
();
protected
$options
=
array
(
'packagesPrefix'
=>
'Package'
,
'packagesPath'
=>
''
,
'generateBaseClasses'
=>
true
,
'generateTableClasses'
=>
true
,
'baseClassesDirectory'
=>
'generated'
,
'baseClassName'
=>
'Doctrine_Record'
,
'suffix'
=>
'.class.php'
);
/**
* ge
nerateBaseClasses
* ge
tOption
*
* Specify whether or not to generate base classes with the model definition in it. The base is generated everytime
* But another child class that extends the base is only generated once. Allowing you to customize your models
* Without losing the changes when you regenerate
*
* @param string $bool
* @return bool $generateBaseClasses
* @param string $name
* @return void
*/
public
function
ge
nerateBaseClasses
(
$bool
=
null
)
public
function
ge
tOption
(
$name
)
{
if
(
$bool
!==
null
)
{
$this
->
generateBaseClasses
=
$bool
;
if
(
isset
(
$this
->
options
[
$name
]))
{
return
$this
->
options
[
$name
];
}
}
return
$this
->
generateBaseClasses
;
/**
* setOption
*
* @param string $name
* @param string $value
* @return void
*/
public
function
setOption
(
$name
,
$value
)
{
if
(
isset
(
$this
->
options
[
$name
]))
{
$this
->
options
[
$name
]
=
$value
;
}
}
/**
...
...
@@ -110,13 +124,23 @@ class Doctrine_Import_Schema
{
$builder
=
new
Doctrine_Import_Builder
();
$builder
->
setTargetPath
(
$directory
);
$builder
->
generateBaseClasses
(
$this
->
generateBaseClasses
());
$builder
->
generateBaseClasses
(
$this
->
getOption
(
'generateBaseClasses'
));
$builder
->
generateTableClasses
(
$this
->
getOption
(
'generateTableClasses'
));
$builder
->
setBaseClassesDirectory
(
$this
->
getOption
(
'baseClassesDirectory'
));
$builder
->
setBaseClassName
(
$this
->
getOption
(
'baseClassName'
));
$builder
->
setPackagesPath
(
$this
->
getOption
(
'packagesPath'
));
$builder
->
setPackagesPrefix
(
$this
->
getOption
(
'packagesPrefix'
));
$builder
->
setSuffix
(
$this
->
getOption
(
'suffix'
));
$schema
=
$this
->
buildSchema
(
$schema
,
$format
);
$array
=
$schema
[
'schema'
];
foreach
(
$array
as
$name
=>
$properties
)
{
if
(
!
isset
(
$properties
[
'className'
]))
{
print_r
(
$properties
);
exit
;
}
if
(
!
empty
(
$models
)
&&
!
in_array
(
$properties
[
'className'
],
$models
))
{
continue
;
}
...
...
@@ -253,7 +277,16 @@ class Doctrine_Import_Schema
$columns
=
array
();
$className
=
isset
(
$table
[
'className'
])
?
(
string
)
$table
[
'className'
]
:
(
string
)
$className
;
$tableName
=
isset
(
$table
[
'tableName'
])
?
(
string
)
$table
[
'tableName'
]
:
(
string
)
Doctrine
::
tableize
(
$className
);
if
(
isset
(
$table
[
'tableName'
])
&&
$table
[
'tableName'
])
{
$tableName
=
$table
[
'tableName'
];
}
else
{
if
(
isset
(
$table
[
'inheritance'
][
'extends'
])
&&
isset
(
$table
[
'inheritance'
][
'extends'
][
'keyType'
])
&&
isset
(
$table
[
'inheritance'
][
'extends'
][
'keyValue'
]))
{
$tableName
=
null
;
}
else
{
$tableName
=
Doctrine
::
tableize
(
$className
);
}
}
$columns
=
isset
(
$table
[
'columns'
])
?
$table
[
'columns'
]
:
array
();
$columns
=
isset
(
$table
[
'fields'
])
?
$table
[
'fields'
]
:
$columns
;
...
...
@@ -262,10 +295,19 @@ class Doctrine_Import_Schema
foreach
(
$columns
as
$columnName
=>
$field
)
{
$colDesc
=
array
();
$colDesc
[
'name'
]
=
isset
(
$field
[
'name'
])
?
(
string
)
$field
[
'name'
]
:
$columnName
;
$e
=
explode
(
'('
,
$field
[
'type'
]);
if
(
isset
(
$e
[
0
])
&&
isset
(
$e
[
1
]))
{
$colDesc
[
'type'
]
=
$e
[
0
];
$colDesc
[
'length'
]
=
substr
(
$e
[
1
],
0
,
strlen
(
$e
[
1
])
-
1
);
}
else
{
$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
[
'length'
]
=
isset
(
$field
[
'size'
])
?
(
int
)
$field
[
'size'
]
:
$colDesc
[
'length'
];
}
$colDesc
[
'ptype'
]
=
isset
(
$field
[
'ptype'
])
?
(
string
)
$field
[
'ptype'
]
:
(
string
)
$colDesc
[
'type'
];
$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
;
...
...
@@ -278,6 +320,7 @@ class Doctrine_Import_Schema
$columns
[(
string
)
$colDesc
[
'name'
]]
=
$colDesc
;
}
}
$build
[
$className
][
'connection'
]
=
isset
(
$table
[
'connection'
])
?
$table
[
'connection'
]
:
null
;
$build
[
$className
][
'className'
]
=
$className
;
...
...
@@ -289,7 +332,6 @@ class Doctrine_Import_Schema
$build
[
$className
][
'templates'
]
=
isset
(
$table
[
'templates'
])
?
$table
[
'templates'
]
:
array
();
$build
[
$className
][
'actAs'
]
=
isset
(
$table
[
'actAs'
])
?
$table
[
'actAs'
]
:
array
();
$build
[
$className
][
'package'
]
=
isset
(
$table
[
'package'
])
?
$table
[
'package'
]
:
null
;
}
if
(
isset
(
$table
[
'inheritance'
]))
{
$build
[
$className
][
'inheritance'
]
=
$table
[
'inheritance'
];
...
...
@@ -347,33 +389,6 @@ class Doctrine_Import_Schema
$relation
[
'foreignType'
]
=
$relation
[
'foreignType'
]
===
'one'
?
Doctrine_Relation
::
ONE
:
Doctrine_Relation
::
MANY
;
}
if
(
isset
(
$relation
[
'refClass'
])
&&
!
empty
(
$relation
[
'refClass'
])
&&
(
!
isset
(
$array
[
$relation
[
'refClass'
]][
'relations'
])
||
empty
(
$array
[
$relation
[
'refClass'
]][
'relations'
])))
{
if
(
!
isset
(
$array
[
$relation
[
'refClass'
]][
'relations'
][
$className
][
'local'
]))
{
$array
[
$relation
[
'refClass'
]][
'relations'
][
$className
][
'local'
]
=
$relation
[
'local'
];
}
if
(
!
isset
(
$array
[
$relation
[
'refClass'
]][
'relations'
][
$className
][
'foreign'
]))
{
$array
[
$relation
[
'refClass'
]][
'relations'
][
$className
][
'foreign'
]
=
$relation
[
'foreign'
];
}
$array
[
$relation
[
'refClass'
]][
'relations'
][
$className
][
'ignore'
]
=
true
;
if
(
!
isset
(
$array
[
$relation
[
'refClass'
]][
'relations'
][
$relation
[
'class'
]][
'local'
]))
{
$array
[
$relation
[
'refClass'
]][
'relations'
][
$relation
[
'class'
]][
'local'
]
=
$relation
[
'local'
];
}
if
(
!
isset
(
$array
[
$relation
[
'refClass'
]][
'relations'
][
$relation
[
'class'
]][
'foreign'
]))
{
$array
[
$relation
[
'refClass'
]][
'relations'
][
$relation
[
'class'
]][
'foreign'
]
=
$relation
[
'foreign'
];
}
$array
[
$relation
[
'refClass'
]][
'relations'
][
$relation
[
'class'
]][
'ignore'
]
=
true
;
if
(
isset
(
$relation
[
'foreignAlias'
]))
{
$array
[
$relation
[
'class'
]][
'relations'
][
$relation
[
'foreignAlias'
]]
=
array
(
'type'
=>
$relation
[
'type'
],
'local'
=>
$relation
[
'foreign'
],
'foreign'
=>
$relation
[
'local'
],
'refClass'
=>
$relation
[
'refClass'
],
'class'
=>
$className
);
}
}
$this
->
relations
[
$className
][
$alias
]
=
$relation
;
}
}
...
...
@@ -393,33 +408,27 @@ class Doctrine_Import_Schema
{
foreach
(
$this
->
relations
as
$className
=>
$relations
)
{
foreach
(
$relations
AS
$alias
=>
$relation
)
{
if
(
isset
(
$relation
[
'ignore'
])
&&
$relation
[
'ignore'
]
||
isset
(
$relation
[
'refClass'
])
||
isset
(
$this
->
relations
[
$relation
[
'class'
]][
'relations'
][
$className
]))
{
continue
;
}
$newRelation
=
array
();
$newRelation
[
'foreign'
]
=
$relation
[
'local'
];
$newRelation
[
'local'
]
=
$relation
[
'foreign'
];
$newRelation
[
'class'
]
=
$className
;
$newRelation
[
'alias'
]
=
isset
(
$relation
[
'foreignAlias'
])
?
$relation
[
'foreignAlias'
]
:
$className
;
$newRelation
[
'class'
]
=
isset
(
$relation
[
'foreignClass'
])
?
$relation
[
'foreignClass'
]
:
$className
;
$newRelation
[
'alias'
]
=
isset
(
$relation
[
'foreignAlias'
])
?
$relation
[
'foreignAlias'
]
:
$className
;
if
(
isset
(
$relation
[
'refClass'
]))
{
$newRelation
[
'refClass'
]
=
$relation
[
'refClass'
];
$newRelation
[
'type'
]
=
isset
(
$relation
[
'foreignType'
])
?
$relation
[
'foreignType'
]
:
$relation
[
'type'
];
}
else
{
if
(
isset
(
$relation
[
'foreignType'
]))
{
$newRelation
[
'type'
]
=
$relation
[
'foreignType'
];
}
else
{
$newRelation
[
'type'
]
=
$relation
[
'type'
]
===
Doctrine_Relation
::
ONE
?
Doctrine_Relation
::
MANY
:
Doctrine_Relation
::
ONE
;
}
if
(
isset
(
$this
->
relations
[
$relation
[
'class'
]])
&&
is_array
(
$this
->
relations
[
$relation
[
'class'
]])
)
{
foreach
(
$this
->
relations
[
$relation
[
'class'
]]
as
$otherRelation
)
{
// skip fully defined m2m relationships
if
(
isset
(
$otherRelation
[
'refClass'
])
&&
$otherRelation
[
'refClass'
]
==
$className
)
{
continue
(
2
);
}
}
}
if
(
!
isset
(
$this
->
relations
[
$relation
[
'class'
]][
$newRelation
[
'alias'
]]))
{
$this
->
relations
[
$relation
[
'class'
]][
$newRelation
[
'alias'
]]
=
$newRelation
;
}
}
}
}
}
\ No newline at end of file
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