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
db10d4a0
Commit
db10d4a0
authored
Oct 26, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Formatting/standards changes.
parent
4428b517
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
332 additions
and
311 deletions
+332
-311
Doctrine.php
lib/Doctrine.php
+3
-2
Cli.php
lib/Doctrine/Cli.php
+45
-31
AnsiColorFormatter.php
lib/Doctrine/Cli/AnsiColorFormatter.php
+97
-104
Formatter.php
lib/Doctrine/Cli/Formatter.php
+61
-58
Data.php
lib/Doctrine/Data.php
+20
-20
Import.php
lib/Doctrine/Data/Import.php
+1
-1
Builder.php
lib/Doctrine/Import/Builder.php
+39
-39
Schema.php
lib/Doctrine/Import/Schema.php
+29
-18
Migration.php
lib/Doctrine/Migration.php
+37
-38
GenerateMigrationsModels.php
lib/Doctrine/Task/GenerateMigrationsModels.php
+0
-0
No files found.
lib/Doctrine.php
View file @
db10d4a0
...
@@ -686,12 +686,13 @@ final class Doctrine
...
@@ -686,12 +686,13 @@ final class Doctrine
*
*
* @param string $yamlPath Path to your yaml schema files
* @param string $yamlPath Path to your yaml schema files
* @param string $directory Directory to generate your models in
* @param string $directory Directory to generate your models in
* @param array $options Array of options to pass to the schema importer
* @return void
* @return void
*/
*/
public
static
function
generateModelsFromYaml
(
$yamlPath
,
$directory
)
public
static
function
generateModelsFromYaml
(
$yamlPath
,
$directory
,
$options
=
array
()
)
{
{
$import
=
new
Doctrine_Import_Schema
();
$import
=
new
Doctrine_Import_Schema
();
$import
->
generateBaseClasses
(
true
);
$import
->
setOption
(
'generateBaseClasses'
,
true
);
return
$import
->
importSchema
(
$yamlPath
,
'yml'
,
$directory
);
return
$import
->
importSchema
(
$yamlPath
,
'yml'
,
$directory
);
}
}
...
...
lib/Doctrine/Cli.php
View file @
db10d4a0
...
@@ -32,12 +32,12 @@
...
@@ -32,12 +32,12 @@
*/
*/
class
Doctrine_Cli
class
Doctrine_Cli
{
{
protected
$tasks
=
array
(),
protected
$
_
tasks
=
array
(),
$taskInstance
=
null
,
$
_
taskInstance
=
null
,
$formatter
=
null
,
$
_
formatter
=
null
,
$scriptName
=
null
,
$
_
scriptName
=
null
,
$message
=
null
,
$
_
message
=
null
,
$config
=
array
();
$
_
config
=
array
();
/**
/**
* __construct
* __construct
...
@@ -47,8 +47,8 @@ class Doctrine_Cli
...
@@ -47,8 +47,8 @@ class Doctrine_Cli
*/
*/
public
function
__construct
(
$config
=
array
())
public
function
__construct
(
$config
=
array
())
{
{
$this
->
config
=
$config
;
$this
->
_
config
=
$config
;
$this
->
formatter
=
new
Doctrine_Cli_AnsiColorFormatter
();
$this
->
_
formatter
=
new
Doctrine_Cli_AnsiColorFormatter
();
$this
->
loadTasks
();
$this
->
loadTasks
();
}
}
...
@@ -61,7 +61,7 @@ class Doctrine_Cli
...
@@ -61,7 +61,7 @@ class Doctrine_Cli
*/
*/
public
function
notify
(
$notification
=
null
,
$style
=
'HEADER'
)
public
function
notify
(
$notification
=
null
,
$style
=
'HEADER'
)
{
{
echo
$this
->
formatter
->
format
(
$this
->
taskInstance
->
getTaskName
(),
'INFO'
)
.
' - '
.
$this
->
formatter
->
format
(
$notification
,
$style
)
.
"
\n
"
;
echo
$this
->
_formatter
->
format
(
$this
->
_taskInstance
->
getTaskName
(),
'INFO'
)
.
' - '
.
$this
->
_
formatter
->
format
(
$notification
,
$style
)
.
"
\n
"
;
}
}
/**
/**
...
@@ -72,7 +72,7 @@ class Doctrine_Cli
...
@@ -72,7 +72,7 @@ class Doctrine_Cli
*/
*/
public
function
notifyException
(
$exception
)
public
function
notifyException
(
$exception
)
{
{
echo
$this
->
formatter
->
format
(
$exception
->
getMessage
(),
'ERROR'
)
.
"
\n
"
;
echo
$this
->
_
formatter
->
format
(
$exception
->
getMessage
(),
'ERROR'
)
.
"
\n
"
;
}
}
/**
/**
...
@@ -90,7 +90,15 @@ class Doctrine_Cli
...
@@ -90,7 +90,15 @@ class Doctrine_Cli
$this
->
notifyException
(
$exception
);
$this
->
notifyException
(
$exception
);
}
}
}
}
/**
* _getTaskClassFromArgs
*
* Get the task class from an array of cli arguments
*
* @param string $args
* @return void
*/
protected
function
_getTaskClassFromArgs
(
$args
)
protected
function
_getTaskClassFromArgs
(
$args
)
{
{
$taskName
=
str_replace
(
'-'
,
'_'
,
$args
[
1
]);
$taskName
=
str_replace
(
'-'
,
'_'
,
$args
[
1
]);
...
@@ -98,10 +106,16 @@ class Doctrine_Cli
...
@@ -98,10 +106,16 @@ class Doctrine_Cli
return
$taskClass
;
return
$taskClass
;
}
}
/**
* _run
*
* @param string $args
* @return void
*/
protected
function
_run
(
$args
)
protected
function
_run
(
$args
)
{
{
$this
->
scriptName
=
$args
[
0
];
$this
->
_
scriptName
=
$args
[
0
];
$arg1
=
isset
(
$args
[
1
])
?
$args
[
1
]
:
null
;
$arg1
=
isset
(
$args
[
1
])
?
$args
[
1
]
:
null
;
...
@@ -124,17 +138,17 @@ class Doctrine_Cli
...
@@ -124,17 +138,17 @@ class Doctrine_Cli
unset
(
$args
[
0
]);
unset
(
$args
[
0
]);
unset
(
$args
[
1
]);
unset
(
$args
[
1
]);
$this
->
taskInstance
=
new
$taskClass
(
$this
);
$this
->
_
taskInstance
=
new
$taskClass
(
$this
);
$args
=
$this
->
prepareArgs
(
$args
);
$args
=
$this
->
prepareArgs
(
$args
);
$this
->
taskInstance
->
setArguments
(
$args
);
$this
->
_
taskInstance
->
setArguments
(
$args
);
try
{
try
{
if
(
$this
->
taskInstance
->
validate
())
{
if
(
$this
->
_
taskInstance
->
validate
())
{
$this
->
taskInstance
->
execute
();
$this
->
_
taskInstance
->
execute
();
}
else
{
}
else
{
echo
$this
->
formatter
->
format
(
'Requires arguments missing!!'
,
'ERROR'
)
.
"
\n\n
"
;
echo
$this
->
_
formatter
->
format
(
'Requires arguments missing!!'
,
'ERROR'
)
.
"
\n\n
"
;
echo
$this
->
printTasks
(
$arg1
,
true
);
echo
$this
->
printTasks
(
$arg1
,
true
);
}
}
}
catch
(
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
...
@@ -150,7 +164,7 @@ class Doctrine_Cli
...
@@ -150,7 +164,7 @@ class Doctrine_Cli
*/
*/
protected
function
prepareArgs
(
$args
)
protected
function
prepareArgs
(
$args
)
{
{
$taskInstance
=
$this
->
taskInstance
;
$taskInstance
=
$this
->
_
taskInstance
;
$args
=
array_values
(
$args
);
$args
=
array_values
(
$args
);
...
@@ -168,8 +182,8 @@ class Doctrine_Cli
...
@@ -168,8 +182,8 @@ class Doctrine_Cli
}
}
// If we have a config array then lets try and fill some of the arguments with the config values
// If we have a config array then lets try and fill some of the arguments with the config values
if
(
is_array
(
$this
->
config
)
&&
!
empty
(
$this
->
config
))
{
if
(
is_array
(
$this
->
_config
)
&&
!
empty
(
$this
->
_
config
))
{
foreach
(
$this
->
config
as
$key
=>
$value
)
{
foreach
(
$this
->
_
config
as
$key
=>
$value
)
{
if
(
array_key_exists
(
$key
,
$prepared
))
{
if
(
array_key_exists
(
$key
,
$prepared
))
{
$prepared
[
$key
]
=
$value
;
$prepared
[
$key
]
=
$value
;
}
}
...
@@ -202,7 +216,7 @@ class Doctrine_Cli
...
@@ -202,7 +216,7 @@ class Doctrine_Cli
$tasks
=
$this
->
getLoadedTasks
();
$tasks
=
$this
->
getLoadedTasks
();
echo
$this
->
formatter
->
format
(
"Doctrine Command Line Interface"
,
'HEADER'
)
.
"
\n\n
"
;
echo
$this
->
_
formatter
->
format
(
"Doctrine Command Line Interface"
,
'HEADER'
)
.
"
\n\n
"
;
foreach
(
$tasks
as
$taskName
)
foreach
(
$tasks
as
$taskName
)
{
{
...
@@ -214,9 +228,9 @@ class Doctrine_Cli
...
@@ -214,9 +228,9 @@ class Doctrine_Cli
$taskInstance
=
new
$className
();
$taskInstance
=
new
$className
();
$taskInstance
->
taskName
=
str_replace
(
'_'
,
'-'
,
Doctrine
::
tableize
(
$taskName
));
$taskInstance
->
taskName
=
str_replace
(
'_'
,
'-'
,
Doctrine
::
tableize
(
$taskName
));
$syntax
=
$this
->
scriptName
.
' '
.
$taskInstance
->
getTaskName
();
$syntax
=
$this
->
_
scriptName
.
' '
.
$taskInstance
->
getTaskName
();
echo
$this
->
formatter
->
format
(
$syntax
,
'INFO'
);
echo
$this
->
_
formatter
->
format
(
$syntax
,
'INFO'
);
if
(
$full
)
{
if
(
$full
)
{
echo
" - "
.
$taskInstance
->
getDescription
()
.
"
\n
"
;
echo
" - "
.
$taskInstance
->
getDescription
()
.
"
\n
"
;
...
@@ -227,10 +241,10 @@ class Doctrine_Cli
...
@@ -227,10 +241,10 @@ class Doctrine_Cli
if
(
!
empty
(
$requiredArguments
))
{
if
(
!
empty
(
$requiredArguments
))
{
foreach
(
$requiredArguments
as
$name
=>
$description
)
{
foreach
(
$requiredArguments
as
$name
=>
$description
)
{
$args
.=
$this
->
formatter
->
format
(
$name
,
"ERROR"
);
$args
.=
$this
->
_
formatter
->
format
(
$name
,
"ERROR"
);
if
(
isset
(
$this
->
config
[
$name
]))
{
if
(
isset
(
$this
->
_
config
[
$name
]))
{
$args
.=
" - "
.
$this
->
formatter
->
format
(
$this
->
config
[
$name
],
'COMMENT'
);
$args
.=
" - "
.
$this
->
_formatter
->
format
(
$this
->
_
config
[
$name
],
'COMMENT'
);
}
else
{
}
else
{
$args
.=
" - "
.
$description
;
$args
.=
" - "
.
$description
;
}
}
...
@@ -248,7 +262,7 @@ class Doctrine_Cli
...
@@ -248,7 +262,7 @@ class Doctrine_Cli
}
}
if
(
$args
)
{
if
(
$args
)
{
echo
"
\n
"
.
$this
->
formatter
->
format
(
'Arguments:'
,
'HEADER'
)
.
"
\n
"
.
$args
;
echo
"
\n
"
.
$this
->
_
formatter
->
format
(
'Arguments:'
,
'HEADER'
)
.
"
\n
"
.
$args
;
}
}
}
}
...
@@ -295,9 +309,9 @@ class Doctrine_Cli
...
@@ -295,9 +309,9 @@ class Doctrine_Cli
}
}
}
}
$this
->
tasks
=
array_merge
(
$this
->
tasks
,
$tasks
);
$this
->
_tasks
=
array_merge
(
$this
->
_
tasks
,
$tasks
);
return
$this
->
tasks
;
return
$this
->
_
tasks
;
}
}
public
function
getLoadedTasks
()
public
function
getLoadedTasks
()
...
@@ -318,6 +332,6 @@ class Doctrine_Cli
...
@@ -318,6 +332,6 @@ class Doctrine_Cli
}
}
}
}
return
array_merge
(
$this
->
tasks
,
$tasks
);
return
array_merge
(
$this
->
_
tasks
,
$tasks
);
}
}
}
}
lib/Doctrine/Cli/AnsiColorFormatter.php
View file @
db10d4a0
...
@@ -37,126 +37,119 @@
...
@@ -37,126 +37,119 @@
*/
*/
class
Doctrine_Cli_AnsiColorFormatter
extends
Doctrine_Cli_Formatter
class
Doctrine_Cli_AnsiColorFormatter
extends
Doctrine_Cli_Formatter
{
{
protected
protected
$
styles
=
array
(
$_
styles
=
array
(
'HEADER'
=>
array
(
'fg'
=>
'black'
,
'bold'
=>
true
),
'HEADER'
=>
array
(
'fg'
=>
'black'
,
'bold'
=>
true
),
'ERROR'
=>
array
(
'bg'
=>
'red'
,
'fg'
=>
'white'
,
'bold'
=>
true
),
'ERROR'
=>
array
(
'bg'
=>
'red'
,
'fg'
=>
'white'
,
'bold'
=>
true
),
'INFO'
=>
array
(
'fg'
=>
'green'
,
'bold'
=>
true
),
'INFO'
=>
array
(
'fg'
=>
'green'
,
'bold'
=>
true
),
'COMMENT'
=>
array
(
'fg'
=>
'yellow'
),
'COMMENT'
=>
array
(
'fg'
=>
'yellow'
),
),
),
$
options
=
array
(
'bold'
=>
1
,
'underscore'
=>
4
,
'blink'
=>
5
,
'reverse'
=>
7
,
'conceal'
=>
8
),
$_
options
=
array
(
'bold'
=>
1
,
'underscore'
=>
4
,
'blink'
=>
5
,
'reverse'
=>
7
,
'conceal'
=>
8
),
$
foreground
=
array
(
'black'
=>
30
,
'red'
=>
31
,
'green'
=>
32
,
'yellow'
=>
33
,
'blue'
=>
34
,
'magenta'
=>
35
,
'cyan'
=>
36
,
'white'
=>
37
),
$_
foreground
=
array
(
'black'
=>
30
,
'red'
=>
31
,
'green'
=>
32
,
'yellow'
=>
33
,
'blue'
=>
34
,
'magenta'
=>
35
,
'cyan'
=>
36
,
'white'
=>
37
),
$
background
=
array
(
'black'
=>
40
,
'red'
=>
41
,
'green'
=>
42
,
'yellow'
=>
43
,
'blue'
=>
44
,
'magenta'
=>
45
,
'cyan'
=>
46
,
'white'
=>
47
);
$_
background
=
array
(
'black'
=>
40
,
'red'
=>
41
,
'green'
=>
42
,
'yellow'
=>
43
,
'blue'
=>
44
,
'magenta'
=>
45
,
'cyan'
=>
46
,
'white'
=>
47
);
/**
/**
* Sets a new style.
* Sets a new style.
*
*
* @param string The style name
* @param string The style name
* @param array An array of options
* @param array An array of options
*/
*/
public
function
setStyle
(
$name
,
$options
=
array
())
public
function
setStyle
(
$name
,
$options
=
array
())
{
$this
->
styles
[
$name
]
=
$options
;
}
/**
* Formats a text according to the given style or parameters.
*
* @param string The test to style
* @param mixed An array of options or a style name
*
* @return string The styled text
*/
public
function
format
(
$text
=
''
,
$parameters
=
array
(),
$stream
=
STDOUT
)
{
if
(
!
$this
->
supportsColors
(
$stream
))
{
{
return
$text
;
$this
->
_styles
[
$name
]
=
$options
;
}
}
if
(
!
is_array
(
$parameters
)
&&
'NONE'
==
$parameters
)
/**
* Formats a text according to the given style or parameters.
*
* @param string The test to style
* @param mixed An array of options or a style name
*
* @return string The styled text
*/
public
function
format
(
$text
=
''
,
$parameters
=
array
(),
$stream
=
STDOUT
)
{
{
return
$text
;
if
(
!
$this
->
supportsColors
(
$stream
))
{
}
return
$text
;
}
if
(
!
is_array
(
$parameters
)
&&
isset
(
$this
->
styles
[
$parameters
]))
if
(
!
is_array
(
$parameters
)
&&
'NONE'
==
$parameters
)
{
{
return
$text
;
$parameters
=
$this
->
styles
[
$parameters
];
}
}
$codes
=
array
();
if
(
!
is_array
(
$parameters
)
&&
isset
(
$this
->
_styles
[
$parameters
]))
{
if
(
isset
(
$parameters
[
'fg'
]))
$parameters
=
$this
->
_styles
[
$parameters
];
{
}
$codes
[]
=
$this
->
foreground
[
$parameters
[
'fg'
]];
}
$codes
=
array
();
if
(
isset
(
$parameters
[
'bg'
]))
if
(
isset
(
$parameters
[
'fg'
]))
{
{
$codes
[]
=
$this
->
_foreground
[
$parameters
[
'fg'
]];
$codes
[]
=
$this
->
background
[
$parameters
[
'bg'
]];
}
if
(
isset
(
$parameters
[
'bg'
]))
{
$codes
[]
=
$this
->
_background
[
$parameters
[
'bg'
]];
}
foreach
(
$this
->
_options
as
$option
=>
$value
)
{
if
(
isset
(
$parameters
[
$option
])
&&
$parameters
[
$option
])
{
$codes
[]
=
$value
;
}
}
return
"
\033
["
.
implode
(
';'
,
$codes
)
.
'm'
.
$text
.
"
\033
[0m"
;
}
}
foreach
(
$this
->
options
as
$option
=>
$value
)
/**
* Formats a message within a section.
*
* @param string The section name
* @param string The text message
* @param integer The maximum size allowed for a line (65 by default)
*/
public
function
formatSection
(
$section
,
$text
,
$size
=
null
)
{
{
if
(
isset
(
$parameters
[
$option
])
&&
$parameters
[
$option
])
$width
=
9
+
strlen
(
$this
->
format
(
''
,
'INFO'
));
{
$codes
[]
=
$value
;
return
sprintf
(
">> %-${width}s %s"
,
$this
->
format
(
$section
,
'INFO'
),
$this
->
excerpt
(
$text
,
$size
));
}
}
}
return
"
\033
["
.
implode
(
';'
,
$codes
)
.
'm'
.
$text
.
"
\033
[0m"
;
/**
}
* Truncates a line.
*
* @param string The text
* @param integer The maximum size of the returned string (65 by default)
*
* @return string The truncated string
*/
public
function
excerpt
(
$text
,
$size
=
null
)
{
if
(
!
$size
)
{
$size
=
$this
->
size
;
}
/**
if
(
strlen
(
$text
)
<
$size
)
{
* Formats a message within a section.
return
$text
;
*
}
* @param string The section name
* @param string The text message
* @param integer The maximum size allowed for a line (65 by default)
*/
public
function
formatSection
(
$section
,
$text
,
$size
=
null
)
{
$width
=
9
+
strlen
(
$this
->
format
(
''
,
'INFO'
));
return
sprintf
(
">> %-${width}s %s"
,
$this
->
format
(
$section
,
'INFO'
),
$this
->
excerpt
(
$text
,
$size
));
$subsize
=
floor
((
$size
-
3
)
/
2
);
}
/**
return
substr
(
$text
,
0
,
$subsize
)
.
$this
->
format
(
'...'
,
'INFO'
)
.
substr
(
$text
,
-
$subsize
);
* Truncates a line.
*
* @param string The text
* @param integer The maximum size of the returned string (65 by default)
*
* @return string The truncated string
*/
public
function
excerpt
(
$text
,
$size
=
null
)
{
if
(
!
$size
)
{
$size
=
$this
->
size
;
}
}
if
(
strlen
(
$text
)
<
$size
)
/**
* Returns true if the stream supports colorization.
*
* Colorization is disabled if not supported by the stream:
*
* - windows
* - non tty consoles
*
* @param mixed A stream
*
* @return Boolean true if the stream supports colorization, false otherwise
*/
public
function
supportsColors
(
$stream
)
{
{
return
$text
;
return
DIRECTORY_SEPARATOR
!=
'\\'
&&
function_exists
(
'posix_isatty'
)
&&
@
posix_isatty
(
$stream
)
;
}
}
$subsize
=
floor
((
$size
-
3
)
/
2
);
return
substr
(
$text
,
0
,
$subsize
)
.
$this
->
format
(
'...'
,
'INFO'
)
.
substr
(
$text
,
-
$subsize
);
}
/**
* Returns true if the stream supports colorization.
*
* Colorization is disabled if not supported by the stream:
*
* - windows
* - non tty consoles
*
* @param mixed A stream
*
* @return Boolean true if the stream supports colorization, false otherwise
*/
public
function
supportsColors
(
$stream
)
{
return
DIRECTORY_SEPARATOR
!=
'\\'
&&
function_exists
(
'posix_isatty'
)
&&
@
posix_isatty
(
$stream
);
}
}
}
\ No newline at end of file
lib/Doctrine/Cli/Formatter.php
View file @
db10d4a0
...
@@ -37,72 +37,75 @@
...
@@ -37,72 +37,75 @@
*/
*/
class
Doctrine_Cli_Formatter
class
Doctrine_Cli_Formatter
{
{
protected
protected
$_size
=
65
;
$size
=
65
;
function
__construct
(
$maxLineSize
=
65
)
/**
{
* __construct
$this
->
size
=
$maxLineSize
;
*
}
* @param string $maxLineSize
* @return void
/**
*/
* Formats a text according to the given parameters.
function
__construct
(
$maxLineSize
=
65
)
*
{
* @param string The test to style
$this
->
_size
=
$maxLineSize
;
* @param mixed An array of parameters
}
* @param stream A stream (default to STDOUT)
*
* @return string The formatted text
*/
public
function
format
(
$text
=
''
,
$parameters
=
array
(),
$stream
=
STDOUT
)
{
return
$text
;
}
/**
* Formats a message within a section.
*
* @param string The section name
* @param string The text message
* @param integer The maximum size allowed for a line (65 by default)
*/
public
function
formatSection
(
$section
,
$text
,
$size
=
null
)
{
return
sprintf
(
">> %-$9s %s"
,
$section
,
$this
->
excerpt
(
$text
,
$size
));
}
/**
/**
* Truncates a line.
* Formats a text according to the given parameters.
*
*
* @param string The text
* @param string The test to style
* @param integer The maximum size of the returned string (65 by default)
* @param mixed An array of parameters
*
* @param stream A stream (default to STDOUT)
* @return string The truncated string
*
*/
* @return string The formatted text
public
function
excerpt
(
$text
,
$size
=
null
)
*/
{
public
function
format
(
$text
=
''
,
$parameters
=
array
(),
$stream
=
STDOUT
)
if
(
!
$size
)
{
{
$size
=
$this
->
size
;
return
$text
;
}
}
if
(
strlen
(
$text
)
<
$size
)
/**
* Formats a message within a section.
*
* @param string The section name
* @param string The text message
* @param integer The maximum size allowed for a line (65 by default)
*/
public
function
formatSection
(
$section
,
$text
,
$size
=
null
)
{
{
return
$text
;
return
sprintf
(
">> %-$9s %s"
,
$section
,
$this
->
excerpt
(
$text
,
$size
))
;
}
}
$subsize
=
floor
((
$size
-
3
)
/
2
);
/**
* Truncates a line.
*
* @param string The text
* @param integer The maximum size of the returned string (65 by default)
*
* @return string The truncated string
*/
public
function
excerpt
(
$text
,
$size
=
null
)
{
if
(
!
$size
)
{
$size
=
$this
->
_size
;
}
if
(
strlen
(
$text
)
<
$size
)
{
return
$text
;
}
$subsize
=
floor
((
$size
-
3
)
/
2
);
return
substr
(
$text
,
0
,
$subsize
)
.
'...'
.
substr
(
$text
,
-
$subsize
);
return
substr
(
$text
,
0
,
$subsize
)
.
'...'
.
substr
(
$text
,
-
$subsize
);
}
}
/**
/**
* Sets the maximum line size.
* Sets the maximum line size.
*
*
* @param integer The maximum line size for a message
* @param integer The maximum line size for a message
*/
*/
public
function
setMaxLineSize
(
$size
)
public
function
setMaxLineSize
(
$size
)
{
{
$this
->
size
=
$size
;
$this
->
_
size
=
$size
;
}
}
}
}
\ No newline at end of file
lib/Doctrine/Data.php
View file @
db10d4a0
...
@@ -42,7 +42,7 @@ class Doctrine_Data
...
@@ -42,7 +42,7 @@ class Doctrine_Data
*
*
* @var string
* @var string
*/
*/
p
ublic
$
formats
=
array
(
'csv'
,
'yml'
,
'xml'
);
p
rotected
$_
formats
=
array
(
'csv'
,
'yml'
,
'xml'
);
/**
/**
* format
* format
...
@@ -51,7 +51,7 @@ class Doctrine_Data
...
@@ -51,7 +51,7 @@ class Doctrine_Data
*
*
* @var string
* @var string
*/
*/
p
ublic
$
format
=
'yml'
;
p
rotected
$_
format
=
'yml'
;
/**
/**
* directory
* directory
...
@@ -60,7 +60,7 @@ class Doctrine_Data
...
@@ -60,7 +60,7 @@ class Doctrine_Data
*
*
* @var string
* @var string
*/
*/
p
ublic
$
directory
=
null
;
p
rotected
$_
directory
=
null
;
/**
/**
* models
* models
...
@@ -69,16 +69,16 @@ class Doctrine_Data
...
@@ -69,16 +69,16 @@ class Doctrine_Data
*
*
* @var string
* @var string
*/
*/
p
ublic
$
models
=
array
();
p
rotected
$_
models
=
array
();
/**
/**
* exportIndividualFiles
*
_
exportIndividualFiles
*
*
* whether or not to export data to individual files instead of 1
* whether or not to export data to individual files instead of 1
*
*
* @var string
* @var string
*/
*/
p
ublic
$
exportIndividualFiles
=
false
;
p
rotected
$_
exportIndividualFiles
=
false
;
/**
/**
* setFormat
* setFormat
...
@@ -90,7 +90,7 @@ class Doctrine_Data
...
@@ -90,7 +90,7 @@ class Doctrine_Data
*/
*/
public
function
setFormat
(
$format
)
public
function
setFormat
(
$format
)
{
{
$this
->
format
=
$format
;
$this
->
_
format
=
$format
;
}
}
/**
/**
...
@@ -102,7 +102,7 @@ class Doctrine_Data
...
@@ -102,7 +102,7 @@ class Doctrine_Data
*/
*/
public
function
getFormat
()
public
function
getFormat
()
{
{
return
$this
->
format
;
return
$this
->
_
format
;
}
}
/**
/**
...
@@ -114,7 +114,7 @@ class Doctrine_Data
...
@@ -114,7 +114,7 @@ class Doctrine_Data
*/
*/
public
function
getFormats
()
public
function
getFormats
()
{
{
return
$this
->
formats
;
return
$this
->
_
formats
;
}
}
/**
/**
...
@@ -126,7 +126,7 @@ class Doctrine_Data
...
@@ -126,7 +126,7 @@ class Doctrine_Data
*/
*/
public
function
setDirectory
(
$directory
)
public
function
setDirectory
(
$directory
)
{
{
$this
->
directory
=
$directory
;
$this
->
_
directory
=
$directory
;
}
}
/**
/**
...
@@ -138,7 +138,7 @@ class Doctrine_Data
...
@@ -138,7 +138,7 @@ class Doctrine_Data
*/
*/
public
function
getDirectory
()
public
function
getDirectory
()
{
{
return
$this
->
directory
;
return
$this
->
_
directory
;
}
}
/**
/**
...
@@ -151,7 +151,7 @@ class Doctrine_Data
...
@@ -151,7 +151,7 @@ class Doctrine_Data
*/
*/
public
function
setModels
(
$models
)
public
function
setModels
(
$models
)
{
{
$this
->
models
=
$models
;
$this
->
_
models
=
$models
;
}
}
/**
/**
...
@@ -163,23 +163,23 @@ class Doctrine_Data
...
@@ -163,23 +163,23 @@ class Doctrine_Data
*/
*/
public
function
getModels
()
public
function
getModels
()
{
{
return
$this
->
models
;
return
$this
->
_
models
;
}
}
/**
/**
* exportIndividualFiles
*
_
exportIndividualFiles
*
*
* Set/Get whether or not to export individual files
* Set/Get whether or not to export individual files
*
*
* @return bool $exportIndividualFiles
* @return bool $
_
exportIndividualFiles
*/
*/
public
function
exportIndividualFiles
(
$bool
=
null
)
public
function
exportIndividualFiles
(
$bool
=
null
)
{
{
if
(
$bool
!==
null
)
{
if
(
$bool
!==
null
)
{
$this
->
exportIndividualFiles
=
$bool
;
$this
->
_
exportIndividualFiles
=
$bool
;
}
}
return
$this
->
exportIndividualFiles
;
return
$this
->
_
exportIndividualFiles
;
}
}
/**
/**
...
@@ -190,15 +190,15 @@ class Doctrine_Data
...
@@ -190,15 +190,15 @@ class Doctrine_Data
* @param string $directory
* @param string $directory
* @param string $format
* @param string $format
* @param string $models
* @param string $models
* @param string $exportIndividualFiles
* @param string $
_
exportIndividualFiles
* @return void
* @return void
*/
*/
public
function
exportData
(
$directory
,
$format
=
'yml'
,
$models
=
array
(),
$exportIndividualFiles
=
false
)
public
function
exportData
(
$directory
,
$format
=
'yml'
,
$models
=
array
(),
$
_
exportIndividualFiles
=
false
)
{
{
$export
=
new
Doctrine_Data_Export
(
$directory
);
$export
=
new
Doctrine_Data_Export
(
$directory
);
$export
->
setFormat
(
$format
);
$export
->
setFormat
(
$format
);
$export
->
setModels
(
$models
);
$export
->
setModels
(
$models
);
$export
->
exportIndividualFiles
(
$exportIndividualFiles
);
$export
->
exportIndividualFiles
(
$
_
exportIndividualFiles
);
return
$export
->
doExport
();
return
$export
->
doExport
();
}
}
...
...
lib/Doctrine/Data/Import.php
View file @
db10d4a0
...
@@ -52,7 +52,7 @@ class Doctrine_Data_Import extends Doctrine_Data
...
@@ -52,7 +52,7 @@ class Doctrine_Data_Import extends Doctrine_Data
*/
*/
public
function
doImport
()
public
function
doImport
()
{
{
$directory
=
$this
->
directory
;
$directory
=
$this
->
getDirectory
()
;
$array
=
array
();
$array
=
array
();
...
...
lib/Doctrine/Import/Builder.php
View file @
db10d4a0
...
@@ -43,23 +43,23 @@ class Doctrine_Import_Builder
...
@@ -43,23 +43,23 @@ class Doctrine_Import_Builder
*
*
* the path where imported files are being generated
* the path where imported files are being generated
*
*
* @var string $path
* @var string $
_
path
*/
*/
pr
ivate
$
path
=
''
;
pr
otected
$_
path
=
''
;
/**
/**
* packagesPrefix
* packagesPrefix
*
*
* @var string
* @var string
*/
*/
pr
ivate
$
packagesPrefix
=
'Package'
;
pr
otected
$_
packagesPrefix
=
'Package'
;
/**
/**
* packagesPath
* packagesPath
*
*
* @var string
* @var string
*/
*/
pr
ivate
$
packagesPath
=
''
;
pr
otected
$_
packagesPath
=
''
;
/**
/**
* suffix
* suffix
...
@@ -68,7 +68,7 @@ class Doctrine_Import_Builder
...
@@ -68,7 +68,7 @@ class Doctrine_Import_Builder
*
*
* @var string $suffix
* @var string $suffix
*/
*/
pr
ivate
$
suffix
=
'.class.php'
;
pr
otected
$_
suffix
=
'.class.php'
;
/**
/**
* generateBaseClasses
* generateBaseClasses
...
@@ -77,14 +77,14 @@ class Doctrine_Import_Builder
...
@@ -77,14 +77,14 @@ class Doctrine_Import_Builder
*
*
* @var string $suffix
* @var string $suffix
*/
*/
pr
ivate
$
generateBaseClasses
=
true
;
pr
otected
$_
generateBaseClasses
=
true
;
/**
/**
* generateTableClasses
* generateTableClasses
*
*
* @var string
* @var string
*/
*/
pr
ivate
$
generateTableClasses
=
true
;
pr
otected
$_
generateTableClasses
=
true
;
/**
/**
* baseClassesDirectory
* baseClassesDirectory
...
@@ -93,23 +93,23 @@ class Doctrine_Import_Builder
...
@@ -93,23 +93,23 @@ class Doctrine_Import_Builder
*
*
* @var string $suffix
* @var string $suffix
*/
*/
pr
ivate
$
baseClassesDirectory
=
'generated'
;
pr
otected
$_
baseClassesDirectory
=
'generated'
;
/**
/**
* baseClassName
* baseClassName
*
*
* @var string
* @var string
*/
*/
pr
ivate
$
baseClassName
=
'Doctrine_Record'
;
pr
otected
$_
baseClassName
=
'Doctrine_Record'
;
/**
/**
* tpl
* tpl
*
*
* Class template used for writing classes
* Class template used for writing classes
*
*
* @var $tpl
* @var $
_
tpl
*/
*/
pr
ivate
static
$
tpl
;
pr
otected
static
$_
tpl
;
/**
/**
* __construct
* __construct
...
@@ -131,11 +131,11 @@ class Doctrine_Import_Builder
...
@@ -131,11 +131,11 @@ class Doctrine_Import_Builder
{
{
Doctrine
::
makeDirectories
(
$path
);
Doctrine
::
makeDirectories
(
$path
);
if
(
!
$this
->
packagesPath
)
{
if
(
!
$this
->
_
packagesPath
)
{
$this
->
packagesPath
=
$path
.
DIRECTORY_SEPARATOR
.
'packages'
;
$this
->
_
packagesPath
=
$path
.
DIRECTORY_SEPARATOR
.
'packages'
;
}
}
$this
->
path
=
$path
;
$this
->
_
path
=
$path
;
}
}
/**
/**
...
@@ -146,7 +146,7 @@ class Doctrine_Import_Builder
...
@@ -146,7 +146,7 @@ class Doctrine_Import_Builder
*/
*/
public
function
setPackagesPrefix
(
$packagesPrefix
)
public
function
setPackagesPrefix
(
$packagesPrefix
)
{
{
$this
->
packagesPrefix
=
$packagesPrefix
;
$this
->
_
packagesPrefix
=
$packagesPrefix
;
}
}
/**
/**
...
@@ -157,7 +157,7 @@ class Doctrine_Import_Builder
...
@@ -157,7 +157,7 @@ class Doctrine_Import_Builder
*/
*/
public
function
setPackagesPath
(
$packagesPath
)
public
function
setPackagesPath
(
$packagesPath
)
{
{
$this
->
packagesPath
=
$packagesPath
;
$this
->
_
packagesPath
=
$packagesPath
;
}
}
/**
/**
...
@@ -171,10 +171,10 @@ class Doctrine_Import_Builder
...
@@ -171,10 +171,10 @@ class Doctrine_Import_Builder
public
function
generateBaseClasses
(
$bool
=
null
)
public
function
generateBaseClasses
(
$bool
=
null
)
{
{
if
(
$bool
!==
null
)
{
if
(
$bool
!==
null
)
{
$this
->
generateBaseClasses
=
$bool
;
$this
->
_
generateBaseClasses
=
$bool
;
}
}
return
$this
->
generateBaseClasses
;
return
$this
->
_
generateBaseClasses
;
}
}
/**
/**
...
@@ -188,10 +188,10 @@ class Doctrine_Import_Builder
...
@@ -188,10 +188,10 @@ class Doctrine_Import_Builder
public
function
generateTableClasses
(
$bool
=
null
)
public
function
generateTableClasses
(
$bool
=
null
)
{
{
if
(
$bool
!==
null
)
{
if
(
$bool
!==
null
)
{
$this
->
generateTableClasses
=
$bool
;
$this
->
_
generateTableClasses
=
$bool
;
}
}
return
$this
->
generateTableClasses
;
return
$this
->
_
generateTableClasses
;
}
}
/**
/**
...
@@ -201,7 +201,7 @@ class Doctrine_Import_Builder
...
@@ -201,7 +201,7 @@ class Doctrine_Import_Builder
*/
*/
public
function
setBaseClassesDirectory
(
$baseClassesDirectory
)
public
function
setBaseClassesDirectory
(
$baseClassesDirectory
)
{
{
$this
->
baseClassesDirectory
;
$this
->
_
baseClassesDirectory
;
}
}
/**
/**
...
@@ -211,7 +211,7 @@ class Doctrine_Import_Builder
...
@@ -211,7 +211,7 @@ class Doctrine_Import_Builder
*/
*/
public
function
setBaseClassName
(
$className
)
public
function
setBaseClassName
(
$className
)
{
{
$this
->
baseClassName
=
$className
;
$this
->
_
baseClassName
=
$className
;
}
}
/**
/**
...
@@ -222,7 +222,7 @@ class Doctrine_Import_Builder
...
@@ -222,7 +222,7 @@ class Doctrine_Import_Builder
*/
*/
public
function
setSuffix
(
$suffix
)
public
function
setSuffix
(
$suffix
)
{
{
$this
->
suffix
=
$suffix
;
$this
->
_
suffix
=
$suffix
;
}
}
/**
/**
...
@@ -232,7 +232,7 @@ class Doctrine_Import_Builder
...
@@ -232,7 +232,7 @@ class Doctrine_Import_Builder
*/
*/
public
function
getTargetPath
()
public
function
getTargetPath
()
{
{
return
$this
->
path
;
return
$this
->
_
path
;
}
}
/**
/**
...
@@ -244,11 +244,11 @@ class Doctrine_Import_Builder
...
@@ -244,11 +244,11 @@ class Doctrine_Import_Builder
*/
*/
public
function
loadTemplate
()
public
function
loadTemplate
()
{
{
if
(
isset
(
self
::
$tpl
))
{
if
(
isset
(
self
::
$
_
tpl
))
{
return
;
return
;
}
}
self
::
$tpl
=<<<
END
self
::
$
_
tpl
=<<<
END
/**
/**
* This class has been auto-generated by the Doctrine ORM Framework
* This class has been auto-generated by the Doctrine ORM Framework
*/
*/
...
@@ -651,7 +651,7 @@ END;
...
@@ -651,7 +651,7 @@ END;
$abstract
=
isset
(
$options
[
'abstract'
])
&&
$options
[
'abstract'
]
===
true
?
'abstract '
:
null
;
$abstract
=
isset
(
$options
[
'abstract'
])
&&
$options
[
'abstract'
]
===
true
?
'abstract '
:
null
;
$className
=
$options
[
'className'
];
$className
=
$options
[
'className'
];
$extends
=
isset
(
$options
[
'inheritance'
][
'extends'
])
?
$options
[
'inheritance'
][
'extends'
]
:
$this
->
baseClassName
;
$extends
=
isset
(
$options
[
'inheritance'
][
'extends'
])
?
$options
[
'inheritance'
][
'extends'
]
:
$this
->
_
baseClassName
;
if
(
!
(
isset
(
$options
[
'no_definition'
])
&&
$options
[
'no_definition'
]
===
true
))
{
if
(
!
(
isset
(
$options
[
'no_definition'
])
&&
$options
[
'no_definition'
]
===
true
))
{
$definition
=
$this
->
buildTableDefinition
(
$options
,
$columns
,
$relations
,
$indexes
,
$attributes
,
$templates
,
$actAs
);
$definition
=
$this
->
buildTableDefinition
(
$options
,
$columns
,
$relations
,
$indexes
,
$attributes
,
$templates
,
$actAs
);
...
@@ -663,7 +663,7 @@ END;
...
@@ -663,7 +663,7 @@ END;
$accessors
=
(
isset
(
$options
[
'generate_accessors'
])
&&
$options
[
'generate_accessors'
]
===
true
)
?
$this
->
buildAccessors
(
$options
,
$columns
)
:
null
;
$accessors
=
(
isset
(
$options
[
'generate_accessors'
])
&&
$options
[
'generate_accessors'
]
===
true
)
?
$this
->
buildAccessors
(
$options
,
$columns
)
:
null
;
$content
=
sprintf
(
self
::
$tpl
,
$abstract
,
$content
=
sprintf
(
self
::
$
_
tpl
,
$abstract
,
$className
,
$className
,
$extends
,
$extends
,
$definition
,
$definition
,
...
@@ -708,7 +708,7 @@ END;
...
@@ -708,7 +708,7 @@ END;
// If we have a package then we need to make this extend the package definition and not the base definition
// 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
// The package definition will then extends the base definition
$topLevel
[
'inheritance'
][
'extends'
]
=
(
isset
(
$topLevel
[
'package'
])
&&
$topLevel
[
'package'
])
?
$this
->
packagesPrefix
.
$topLevel
[
'className'
]
:
'Base'
.
$topLevel
[
'className'
];
$topLevel
[
'inheritance'
][
'extends'
]
=
(
isset
(
$topLevel
[
'package'
])
&&
$topLevel
[
'package'
])
?
$this
->
_
packagesPrefix
.
$topLevel
[
'className'
]
:
'Base'
.
$topLevel
[
'className'
];
$topLevel
[
'no_definition'
]
=
true
;
$topLevel
[
'no_definition'
]
=
true
;
$topLevel
[
'generate_once'
]
=
true
;
$topLevel
[
'generate_once'
]
=
true
;
$topLevel
[
'is_main_class'
]
=
true
;
$topLevel
[
'is_main_class'
]
=
true
;
...
@@ -754,7 +754,7 @@ END;
...
@@ -754,7 +754,7 @@ END;
$className
=
$className
.
'Table'
;
$className
=
$className
.
'Table'
;
$content
=
'<?php'
.
PHP_EOL
;
$content
=
'<?php'
.
PHP_EOL
;
$content
.=
sprintf
(
self
::
$tpl
,
false
,
$content
.=
sprintf
(
self
::
$
_
tpl
,
false
,
$className
,
$className
,
isset
(
$options
[
'extends'
])
?
$options
[
'extends'
]
:
'Doctrine_Table'
,
isset
(
$options
[
'extends'
])
?
$options
[
'extends'
]
:
'Doctrine_Table'
,
null
,
null
,
...
@@ -764,7 +764,7 @@ END;
...
@@ -764,7 +764,7 @@ END;
Doctrine
::
makeDirectories
(
$path
);
Doctrine
::
makeDirectories
(
$path
);
$writePath
=
$path
.
DIRECTORY_SEPARATOR
.
$className
.
$this
->
suffix
;
$writePath
=
$path
.
DIRECTORY_SEPARATOR
.
$className
.
$this
->
_
suffix
;
if
(
!
file_exists
(
$writePath
))
{
if
(
!
file_exists
(
$writePath
))
{
file_put_contents
(
$writePath
,
$content
);
file_put_contents
(
$writePath
,
$content
);
...
@@ -787,20 +787,20 @@ END;
...
@@ -787,20 +787,20 @@ END;
{
{
$definition
=
$this
->
buildDefinition
(
$options
,
$columns
,
$relations
,
$indexes
,
$attributes
,
$templates
,
$actAs
);
$definition
=
$this
->
buildDefinition
(
$options
,
$columns
,
$relations
,
$indexes
,
$attributes
,
$templates
,
$actAs
);
$fileName
=
$options
[
'className'
]
.
$this
->
suffix
;
$fileName
=
$options
[
'className'
]
.
$this
->
_
suffix
;
$packagesPath
=
$this
->
packagesPath
?
$this
->
packagesPath
:
$this
->
path
;
$packagesPath
=
$this
->
_packagesPath
?
$this
->
_packagesPath
:
$this
->
_
path
;
// If this is a main class that either extends from Base or Package class
// If this is a main class that either extends from Base or Package class
if
(
isset
(
$options
[
'is_main_class'
])
&&
$options
[
'is_main_class'
])
{
if
(
isset
(
$options
[
'is_main_class'
])
&&
$options
[
'is_main_class'
])
{
// If is package then we need to put it in a package subfolder
// If is package then we need to put it in a package subfolder
if
(
isset
(
$options
[
'is_package'
])
&&
$options
[
'is_package'
])
{
if
(
isset
(
$options
[
'is_package'
])
&&
$options
[
'is_package'
])
{
$writePath
=
$this
->
path
.
DIRECTORY_SEPARATOR
.
$options
[
'package_name'
];
$writePath
=
$this
->
_
path
.
DIRECTORY_SEPARATOR
.
$options
[
'package_name'
];
$this
->
writeTableDefinition
(
$options
[
'className'
],
$writePath
,
array
(
'extends'
=>
$options
[
'inheritance'
][
'extends'
]
.
'Table'
));
$this
->
writeTableDefinition
(
$options
[
'className'
],
$writePath
,
array
(
'extends'
=>
$options
[
'inheritance'
][
'extends'
]
.
'Table'
));
// Otherwise lets just put it in the root of the path
// Otherwise lets just put it in the root of the path
}
else
{
}
else
{
$writePath
=
$this
->
path
;
$writePath
=
$this
->
_
path
;
$this
->
writeTableDefinition
(
$options
[
'className'
],
$writePath
);
$this
->
writeTableDefinition
(
$options
[
'className'
],
$writePath
);
}
}
...
@@ -819,10 +819,10 @@ END;
...
@@ -819,10 +819,10 @@ END;
if
(
isset
(
$options
[
'is_base_class'
])
&&
$options
[
'is_base_class'
])
{
if
(
isset
(
$options
[
'is_base_class'
])
&&
$options
[
'is_base_class'
])
{
// If it is a part of a package then we need to put it in a package subfolder
// If it is a part of a package then we need to put it in a package subfolder
if
(
isset
(
$options
[
'is_package'
])
&&
$options
[
'is_package'
])
{
if
(
isset
(
$options
[
'is_package'
])
&&
$options
[
'is_package'
])
{
$writePath
=
$this
->
path
.
DIRECTORY_SEPARATOR
.
$options
[
'package_name'
]
.
DIRECTORY_SEPARATOR
.
$this
->
baseClassesDirectory
;
$writePath
=
$this
->
_path
.
DIRECTORY_SEPARATOR
.
$options
[
'package_name'
]
.
DIRECTORY_SEPARATOR
.
$this
->
_
baseClassesDirectory
;
// Otherwise lets just put it in the root generated folder
// Otherwise lets just put it in the root generated folder
}
else
{
}
else
{
$writePath
=
$this
->
path
.
DIRECTORY_SEPARATOR
.
$this
->
baseClassesDirectory
;
$writePath
=
$this
->
_path
.
DIRECTORY_SEPARATOR
.
$this
->
_
baseClassesDirectory
;
}
}
}
}
...
@@ -831,9 +831,9 @@ END;
...
@@ -831,9 +831,9 @@ END;
$writePath
.=
DIRECTORY_SEPARATOR
.
$fileName
;
$writePath
.=
DIRECTORY_SEPARATOR
.
$fileName
;
}
else
{
}
else
{
Doctrine
::
makeDirectories
(
$this
->
path
);
Doctrine
::
makeDirectories
(
$this
->
_
path
);
$writePath
=
$this
->
path
.
DIRECTORY_SEPARATOR
.
$fileName
;
$writePath
=
$this
->
_
path
.
DIRECTORY_SEPARATOR
.
$fileName
;
}
}
$code
=
"<?php"
.
PHP_EOL
;
$code
=
"<?php"
.
PHP_EOL
;
...
...
lib/Doctrine/Import/Schema.php
View file @
db10d4a0
...
@@ -39,14 +39,14 @@
...
@@ -39,14 +39,14 @@
*/
*/
class
Doctrine_Import_Schema
class
Doctrine_Import_Schema
{
{
protected
$relations
=
array
();
protected
$
_
relations
=
array
();
protected
$options
=
array
(
'packagesPrefix'
=>
'Package'
,
protected
$
_
options
=
array
(
'packagesPrefix'
=>
'Package'
,
'packagesPath'
=>
''
,
'packagesPath'
=>
''
,
'generateBaseClasses'
=>
true
,
'generateBaseClasses'
=>
true
,
'generateTableClasses'
=>
true
,
'generateTableClasses'
=>
true
,
'baseClassesDirectory'
=>
'generated'
,
'baseClassesDirectory'
=>
'generated'
,
'baseClassName'
=>
'Doctrine_Record'
,
'baseClassName'
=>
'Doctrine_Record'
,
'suffix'
=>
'.class.php'
);
'suffix'
=>
'.class.php'
);
/**
/**
* getOption
* getOption
...
@@ -56,8 +56,8 @@ class Doctrine_Import_Schema
...
@@ -56,8 +56,8 @@ class Doctrine_Import_Schema
*/
*/
public
function
getOption
(
$name
)
public
function
getOption
(
$name
)
{
{
if
(
isset
(
$this
->
options
[
$name
]))
{
if
(
isset
(
$this
->
_
options
[
$name
]))
{
return
$this
->
options
[
$name
];
return
$this
->
_
options
[
$name
];
}
}
}
}
...
@@ -70,10 +70,21 @@ class Doctrine_Import_Schema
...
@@ -70,10 +70,21 @@ class Doctrine_Import_Schema
*/
*/
public
function
setOption
(
$name
,
$value
)
public
function
setOption
(
$name
,
$value
)
{
{
if
(
isset
(
$this
->
options
[
$name
]))
{
if
(
isset
(
$this
->
_
options
[
$name
]))
{
$this
->
options
[
$name
]
=
$value
;
$this
->
_
options
[
$name
]
=
$value
;
}
}
}
}
/**
* setOptions
*
* @param string $options
* @return void
*/
public
function
setOptions
(
$options
)
{
$this
->
_options
=
$options
;
}
/**
/**
* buildSchema
* buildSchema
...
@@ -106,7 +117,7 @@ class Doctrine_Import_Schema
...
@@ -106,7 +117,7 @@ class Doctrine_Import_Schema
$this
->
buildRelationships
(
$array
);
$this
->
buildRelationships
(
$array
);
return
array
(
'schema'
=>
$array
,
'relations'
=>
$this
->
relations
);
return
array
(
'schema'
=>
$array
,
'relations'
=>
$this
->
_
relations
);
}
}
/**
/**
...
@@ -199,7 +210,7 @@ class Doctrine_Import_Schema
...
@@ -199,7 +210,7 @@ class Doctrine_Import_Schema
*/
*/
public
function
getRelations
(
$properties
)
public
function
getRelations
(
$properties
)
{
{
return
isset
(
$this
->
relations
[
$properties
[
'className'
]])
?
$this
->
relations
[
$properties
[
'className'
]]
:
array
();
return
isset
(
$this
->
_relations
[
$properties
[
'className'
]])
?
$this
->
_
relations
[
$properties
[
'className'
]]
:
array
();
}
}
/**
/**
...
@@ -385,7 +396,7 @@ class Doctrine_Import_Schema
...
@@ -385,7 +396,7 @@ class Doctrine_Import_Schema
$relation
[
'foreignType'
]
=
$relation
[
'foreignType'
]
===
'one'
?
Doctrine_Relation
::
ONE
:
Doctrine_Relation
::
MANY
;
$relation
[
'foreignType'
]
=
$relation
[
'foreignType'
]
===
'one'
?
Doctrine_Relation
::
ONE
:
Doctrine_Relation
::
MANY
;
}
}
$this
->
relations
[
$className
][
$alias
]
=
$relation
;
$this
->
_
relations
[
$className
][
$alias
]
=
$relation
;
}
}
}
}
...
@@ -402,7 +413,7 @@ class Doctrine_Import_Schema
...
@@ -402,7 +413,7 @@ class Doctrine_Import_Schema
*/
*/
protected
function
fixRelationships
()
protected
function
fixRelationships
()
{
{
foreach
(
$this
->
relations
as
$className
=>
$relations
)
{
foreach
(
$this
->
_
relations
as
$className
=>
$relations
)
{
foreach
(
$relations
AS
$alias
=>
$relation
)
{
foreach
(
$relations
AS
$alias
=>
$relation
)
{
$newRelation
=
array
();
$newRelation
=
array
();
$newRelation
[
'foreign'
]
=
$relation
[
'local'
];
$newRelation
[
'foreign'
]
=
$relation
[
'local'
];
...
@@ -421,8 +432,8 @@ class Doctrine_Import_Schema
...
@@ -421,8 +432,8 @@ class Doctrine_Import_Schema
}
}
}
}
if
(
!
isset
(
$this
->
relations
[
$relation
[
'class'
]][
$newRelation
[
'alias'
]]))
{
if
(
!
isset
(
$this
->
_
relations
[
$relation
[
'class'
]][
$newRelation
[
'alias'
]]))
{
$this
->
relations
[
$relation
[
'class'
]][
$newRelation
[
'alias'
]]
=
$newRelation
;
$this
->
_
relations
[
$relation
[
'class'
]][
$newRelation
[
'alias'
]]
=
$newRelation
;
}
}
}
}
}
}
...
...
lib/Doctrine/Migration.php
View file @
db10d4a0
...
@@ -34,24 +34,23 @@
...
@@ -34,24 +34,23 @@
*/
*/
class
Doctrine_Migration
class
Doctrine_Migration
{
{
protected
$changes
=
array
(
'created_tables'
=>
array
(),
protected
$_changes
=
array
(
'created_tables'
=>
array
(),
'renamed_tables'
=>
array
(),
'renamed_tables'
=>
array
(),
'created_constraints'
=>
array
(),
'created_constraints'
=>
array
(),
'dropped_fks'
=>
array
(),
'dropped_fks'
=>
array
(),
'created_fks'
=>
array
(),
'created_fks'
=>
array
(),
'dropped_constraints'
=>
array
(),
'dropped_constraints'
=>
array
(),
'removed_indexes'
=>
array
(),
'removed_indexes'
=>
array
(),
'dropped_tables'
=>
array
(),
'dropped_tables'
=>
array
(),
'added_columns'
=>
array
(),
'added_columns'
=>
array
(),
'renamed_columns'
=>
array
(),
'renamed_columns'
=>
array
(),
'changed_columns'
=>
array
(),
'changed_columns'
=>
array
(),
'removed_columns'
=>
array
(),
'removed_columns'
=>
array
(),
'added_indexes'
=>
array
(),
'added_indexes'
=>
array
()),
),
$_migrationTableName
=
'migration_version'
,
$migrationTableName
=
'migration_version'
,
$_migrationClassesDirectory
=
array
(),
$migrationClassesDirectory
=
array
(),
$_migrationClasses
=
array
(),
$migrationClasses
=
array
(),
$_loadedMigrations
=
array
();
$loadedMigrations
=
array
();
/**
/**
* construct
* construct
...
@@ -65,7 +64,7 @@ class Doctrine_Migration
...
@@ -65,7 +64,7 @@ class Doctrine_Migration
public
function
__construct
(
$directory
=
null
)
public
function
__construct
(
$directory
=
null
)
{
{
if
(
$directory
!=
null
)
{
if
(
$directory
!=
null
)
{
$this
->
migrationClassesDirectory
=
$directory
;
$this
->
_
migrationClassesDirectory
=
$directory
;
$this
->
loadMigrationClasses
();
$this
->
loadMigrationClasses
();
...
@@ -85,7 +84,7 @@ class Doctrine_Migration
...
@@ -85,7 +84,7 @@ class Doctrine_Migration
$conn
=
Doctrine_Manager
::
connection
();
$conn
=
Doctrine_Manager
::
connection
();
try
{
try
{
$conn
->
export
->
createTable
(
$this
->
migrationTableName
,
array
(
'version'
=>
array
(
'type'
=>
'integer'
,
'size'
=>
11
)));
$conn
->
export
->
createTable
(
$this
->
_
migrationTableName
,
array
(
'version'
=>
array
(
'type'
=>
'integer'
,
'size'
=>
11
)));
return
true
;
return
true
;
}
catch
(
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
...
@@ -102,28 +101,28 @@ class Doctrine_Migration
...
@@ -102,28 +101,28 @@ class Doctrine_Migration
*/
*/
protected
function
loadMigrationClasses
()
protected
function
loadMigrationClasses
()
{
{
if
(
$this
->
migrationClasses
)
{
if
(
$this
->
_
migrationClasses
)
{
return
$this
->
migrationClasses
;
return
$this
->
_
migrationClasses
;
}
}
$classes
=
get_declared_classes
();
$classes
=
get_declared_classes
();
if
(
$this
->
migrationClassesDirectory
!==
null
)
{
if
(
$this
->
_
migrationClassesDirectory
!==
null
)
{
foreach
((
array
)
$this
->
migrationClassesDirectory
as
$dir
)
{
foreach
((
array
)
$this
->
_
migrationClassesDirectory
as
$dir
)
{
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$dir
),
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$dir
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
RecursiveIteratorIterator
::
LEAVES_ONLY
);
foreach
(
$it
as
$file
)
{
foreach
(
$it
as
$file
)
{
$e
=
explode
(
'.'
,
$file
->
getFileName
());
$e
=
explode
(
'.'
,
$file
->
getFileName
());
if
(
end
(
$e
)
===
'php'
&&
strpos
(
$file
->
getFileName
(),
'.inc'
)
===
false
)
{
if
(
end
(
$e
)
===
'php'
&&
strpos
(
$file
->
getFileName
(),
'.inc'
)
===
false
)
{
if
(
!
in_array
(
$file
->
getFileName
(),
$this
->
loadedMigrations
))
{
if
(
!
in_array
(
$file
->
getFileName
(),
$this
->
_
loadedMigrations
))
{
require_once
(
$file
->
getPathName
());
require_once
(
$file
->
getPathName
());
$requiredClass
=
array_diff
(
get_declared_classes
(),
$classes
);
$requiredClass
=
array_diff
(
get_declared_classes
(),
$classes
);
$requiredClass
=
end
(
$requiredClass
);
$requiredClass
=
end
(
$requiredClass
);
if
(
$requiredClass
)
{
if
(
$requiredClass
)
{
$this
->
loadedMigrations
[
$requiredClass
]
=
$file
->
getFileName
();
$this
->
_
loadedMigrations
[
$requiredClass
]
=
$file
->
getFileName
();
}
}
}
}
}
}
...
@@ -133,7 +132,7 @@ class Doctrine_Migration
...
@@ -133,7 +132,7 @@ class Doctrine_Migration
$parent
=
new
ReflectionClass
(
'Doctrine_Migration'
);
$parent
=
new
ReflectionClass
(
'Doctrine_Migration'
);
foreach
(
$this
->
loadedMigrations
as
$name
=>
$fileName
)
{
foreach
(
$this
->
_
loadedMigrations
as
$name
=>
$fileName
)
{
$class
=
new
ReflectionClass
(
$name
);
$class
=
new
ReflectionClass
(
$name
);
while
(
$class
->
isSubclassOf
(
$parent
))
{
while
(
$class
->
isSubclassOf
(
$parent
))
{
...
@@ -151,10 +150,10 @@ class Doctrine_Migration
...
@@ -151,10 +150,10 @@ class Doctrine_Migration
$e
=
explode
(
'_'
,
$fileName
);
$e
=
explode
(
'_'
,
$fileName
);
$classMigrationNum
=
(
int
)
$e
[
0
];
$classMigrationNum
=
(
int
)
$e
[
0
];
$this
->
migrationClasses
[
$classMigrationNum
]
=
array
(
'className'
=>
$name
,
'fileName'
=>
$fileName
);
$this
->
_
migrationClasses
[
$classMigrationNum
]
=
array
(
'className'
=>
$name
,
'fileName'
=>
$fileName
);
}
}
return
$this
->
migrationClasses
;
return
$this
->
_
migrationClasses
;
}
}
/**
/**
...
@@ -164,7 +163,7 @@ class Doctrine_Migration
...
@@ -164,7 +163,7 @@ class Doctrine_Migration
*/
*/
public
function
getMigrationClasses
()
public
function
getMigrationClasses
()
{
{
return
$this
->
migrationClasses
;
return
$this
->
_
migrationClasses
;
}
}
/**
/**
...
@@ -180,9 +179,9 @@ class Doctrine_Migration
...
@@ -180,9 +179,9 @@ class Doctrine_Migration
$conn
=
Doctrine_Manager
::
connection
();
$conn
=
Doctrine_Manager
::
connection
();
if
(
$this
->
hasMigrated
())
{
if
(
$this
->
hasMigrated
())
{
$conn
->
exec
(
"UPDATE "
.
$this
->
migrationTableName
.
" SET version =
$number
"
);
$conn
->
exec
(
"UPDATE "
.
$this
->
_
migrationTableName
.
" SET version =
$number
"
);
}
else
{
}
else
{
$conn
->
exec
(
"INSERT INTO "
.
$this
->
migrationTableName
.
" (version) VALUES (
$number
)"
);
$conn
->
exec
(
"INSERT INTO "
.
$this
->
_
migrationTableName
.
" (version) VALUES (
$number
)"
);
}
}
}
}
...
@@ -197,7 +196,7 @@ class Doctrine_Migration
...
@@ -197,7 +196,7 @@ class Doctrine_Migration
{
{
$conn
=
Doctrine_Manager
::
connection
();
$conn
=
Doctrine_Manager
::
connection
();
$result
=
$conn
->
fetchColumn
(
"SELECT version FROM "
.
$this
->
migrationTableName
);
$result
=
$conn
->
fetchColumn
(
"SELECT version FROM "
.
$this
->
_
migrationTableName
);
return
isset
(
$result
[
0
])
?
$result
[
0
]
:
0
;
return
isset
(
$result
[
0
])
?
$result
[
0
]
:
0
;
}
}
...
@@ -213,7 +212,7 @@ class Doctrine_Migration
...
@@ -213,7 +212,7 @@ class Doctrine_Migration
{
{
$conn
=
Doctrine_Manager
::
connection
();
$conn
=
Doctrine_Manager
::
connection
();
$result
=
$conn
->
fetchColumn
(
"SELECT version FROM "
.
$this
->
migrationTableName
);
$result
=
$conn
->
fetchColumn
(
"SELECT version FROM "
.
$this
->
_
migrationTableName
);
return
isset
(
$result
[
0
])
?
true
:
false
;
return
isset
(
$result
[
0
])
?
true
:
false
;
}
}
...
@@ -230,7 +229,7 @@ class Doctrine_Migration
...
@@ -230,7 +229,7 @@ class Doctrine_Migration
$this
->
loadMigrationClasses
();
$this
->
loadMigrationClasses
();
$versions
=
array
();
$versions
=
array
();
foreach
(
array_keys
(
$this
->
migrationClasses
)
as
$classMigrationNum
)
{
foreach
(
array_keys
(
$this
->
_
migrationClasses
)
as
$classMigrationNum
)
{
$versions
[
$classMigrationNum
]
=
$classMigrationNum
;
$versions
[
$classMigrationNum
]
=
$classMigrationNum
;
}
}
...
@@ -259,7 +258,7 @@ class Doctrine_Migration
...
@@ -259,7 +258,7 @@ class Doctrine_Migration
*/
*/
protected
function
getMigrationClass
(
$num
)
protected
function
getMigrationClass
(
$num
)
{
{
foreach
(
$this
->
migrationClasses
as
$classMigrationNum
=>
$info
)
{
foreach
(
$this
->
_
migrationClasses
as
$classMigrationNum
=>
$info
)
{
$className
=
$info
[
'className'
];
$className
=
$info
[
'className'
];
if
(
$classMigrationNum
==
$num
)
{
if
(
$classMigrationNum
==
$num
)
{
...
@@ -299,7 +298,7 @@ class Doctrine_Migration
...
@@ -299,7 +298,7 @@ class Doctrine_Migration
if
(
method_exists
(
$this
,
$direction
))
{
if
(
method_exists
(
$this
,
$direction
))
{
$this
->
$direction
();
$this
->
$direction
();
foreach
(
$this
->
changes
as
$type
=>
$changes
)
{
foreach
(
$this
->
_
changes
as
$type
=>
$changes
)
{
$process
=
new
Doctrine_Migration_Process
();
$process
=
new
Doctrine_Migration_Process
();
$funcName
=
'process'
.
Doctrine
::
classify
(
$type
);
$funcName
=
'process'
.
Doctrine
::
classify
(
$type
);
...
@@ -359,7 +358,7 @@ class Doctrine_Migration
...
@@ -359,7 +358,7 @@ class Doctrine_Migration
*/
*/
protected
function
addChange
(
$type
,
array
$change
=
array
())
protected
function
addChange
(
$type
,
array
$change
=
array
())
{
{
$this
->
changes
[
$type
][]
=
$change
;
$this
->
_
changes
[
$type
][]
=
$change
;
}
}
/**
/**
...
...
lib/Doctrine/Task/GenerateMigration
Models
→
lib/Doctrine/Task/GenerateMigration
sModels.php
View file @
db10d4a0
File moved
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