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
a8b38b58
Commit
a8b38b58
authored
Oct 15, 2007
by
wernerm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated the cli compiler to allocate more memory. It was also finally tested on Win32.
parent
3b8efd07
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
145 additions
and
79 deletions
+145
-79
cli_compiler.php
sandbox/cli_compiler.php
+145
-79
No files found.
sandbox/cli_compiler.php
View file @
a8b38b58
#!/usr/bin/php
#!/usr/bin/env php
<?php
chdir(dirname(__FILE__));
?>
Welcome to the interactive Doctrine Compiler 0.0.2 (Beta).
Welcome to the interactive Doctrine Compiler 0.0.1 (Beta).
To see the available command-line options, run:
<?php
echo
$argv
[
0
];
?>
--help
WARNING: You're on your own - this script modifies your
filesystem and has not been tested on Windows (yet).
<?php
<?php
if
(
in_array
(
$argv
[
1
],
array
(
'--help'
,
'-help'
,
'-h'
,
'-?'
)))
{
if
(
in_array
(
$argv
[
1
],
array
(
'--help'
,
'-help'
,
'-h'
,
'-?'
)))
{
?>
?>
...
@@ -26,21 +30,6 @@ While the program is running:
...
@@ -26,21 +30,6 @@ While the program is running:
exit
;
exit
;
}
}
if
(
$argc
>
1
)
{
$doctrinePath
=
$argv
[
1
];
}
$drivers
=
array
(
'Db2'
,
'Firebird'
,
'Informix'
,
'Mssql'
,
'Mysql'
,
'Oracle'
,
'Pgsql'
,
'Sqlite'
);
function
addIncludePath
(
$path
)
{
function
addIncludePath
(
$path
)
{
set_include_path
(
set_include_path
(
$path
.
PATH_SEPARATOR
.
get_include_path
()
$path
.
PATH_SEPARATOR
.
get_include_path
()
...
@@ -110,20 +99,30 @@ function ask(
...
@@ -110,20 +99,30 @@ function ask(
}
}
}
}
// Enable error reporting
// Enable error reporting
if
((
$answer
=
ask
(
"Would you like to turn on error reporting?"
,
'n'
))
==
'y'
)
{
if
((
$answer
=
ask
(
"Would you like to turn on error reporting?"
,
'n'
))
==
'y'
)
{
error_reporting
(
E_ALL
);
error_reporting
(
E_ALL
);
$showErrors
=
true
;
}
else
{
}
else
{
error_reporting
(
0
);
error_reporting
(
0
);
$showErrors
=
false
;
}
}
autoQuit
(
$answer
);
autoQuit
(
$answer
);
// Process library path command line argument
if
(
$argc
>
1
)
{
$doctrinePath
=
$argv
[
1
];
}
else
{
$doctrinePath
=
dirname
(
__FILE__
);
}
// Get Doctrine's library path
// Get Doctrine's library path
$usablePath
=
false
;
$usablePath
=
false
;
while
(
!
$usablePath
)
{
while
(
!
$usablePath
)
{
if
(
!
isset
(
$doctrinePath
))
{
$doctrinePath
=
dirname
(
__FILE__
);
}
$path
=
ask
(
"Please enter the path to Doctrine's lib directory:"
,
$doctrinePath
,
array
(
$doctrinePath
),
false
);
$path
=
ask
(
"Please enter the path to Doctrine's lib directory:"
,
$doctrinePath
,
array
(
$doctrinePath
),
false
);
autoQuit
(
$path
);
autoQuit
(
$path
);
try
{
try
{
...
@@ -139,10 +138,58 @@ while (!$usablePath) {
...
@@ -139,10 +138,58 @@ while (!$usablePath) {
}
}
}
}
// Process target filename command line argument
if
(
$argc
>
2
)
{
$targetFile
=
$argv
[
2
];
}
else
{
$targetFile
=
$path
.
DIRECTORY_SEPARATOR
.
'Doctrine.compiled.php'
;
}
clearstatcache
();
$usableFilename
=
false
;
while
(
!
$usableFilename
)
{
$target
=
ask
(
"Please enter the target filename for the 'compiled' Doctrine file that will be created:"
,
$targetFile
,
array
(
$targetFile
),
false
);
autoQuit
(
$target
);
if
(
file_exists
(
$target
))
{
if
(
is_writable
(
$target
)
&&
(
!
is_dir
(
$target
)))
{
$usableFilename
=
true
;
}
else
{
$msg
=
"The target filename '
$target
' cannot be used (it is not writable, or it is a directory)."
;
}
}
else
{
if
(
is_writable
(
dirname
(
$target
)))
{
$usableFilename
=
true
;
}
else
{
$msg
=
"The directory in which the target file will be created is not writable."
;
}
}
if
(
!
$usableFilename
)
{
showMessage
(
$msg
);
if
((
$answer
=
ask
(
"Would you like to specify a different target filename?"
))
!=
'y'
)
{
quit
();
}
}
}
// Define the default drivers - unfortunately, this is hard-coded for now
$drivers
=
array
(
'Db2'
,
'Firebird'
,
'Informix'
,
'Mssql'
,
'Mysql'
,
'Oracle'
,
'Pgsql'
,
'Sqlite'
);
$includeDrivers
=
array
();
$includeDrivers
=
array
();
$excludeDrivers
=
array
();
$excludeDrivers
=
array
();
// Determine driver support
// Determine driver support
foreach
(
$drivers
as
$driver
)
{
foreach
(
$drivers
as
$driver
)
{
if
((
$answer
=
ask
(
"Would you like to enable support for
$driver
?"
))
==
'y'
)
{
if
((
$answer
=
ask
(
"Would you like to enable support for
$driver
?"
))
==
'y'
)
{
$includeDrivers
[]
=
$driver
;
$includeDrivers
[]
=
$driver
;
...
@@ -153,19 +200,22 @@ foreach ($drivers as $driver) {
...
@@ -153,19 +200,22 @@ foreach ($drivers as $driver) {
}
}
// Verify driver support
// Verify driver support
if
(
!
count
(
$includeDrivers
))
{
if
(
!
count
(
$includeDrivers
))
{
showMessage
(
"You have not selected any drivers.
Norm
ally this is not a good idea, unless you know what you're doing."
);
showMessage
(
"You have not selected any drivers.
Usu
ally this is not a good idea, unless you know what you're doing."
);
if
((
$answer
=
ask
(
"Are you sure you want to compile without any drivers?"
))
!=
'y'
)
{
if
((
$answer
=
ask
(
"Are you sure you want to compile without any drivers?"
))
!=
'y'
)
{
quit
();
quit
();
}
}
autoQuit
(
$answer
);
autoQuit
(
$answer
);
}
}
// 'Compile' Doctrine...
// Try to prevent errors related to memory allocation
showMessage
(
"Trying to set the PHP memory limit to 18MB..."
);
ini_set
(
'memory_limit'
,
'18M'
);
$requiredMemory
=
'32M'
;
if
(
ini_get
(
'memory_limit'
)
!=
'18M'
)
{
showMessage
(
"Trying to set the PHP memory limit to
$requiredMemory
..."
);
showMessage
(
"WARNING: The program could not set the PHP memory limit to 18MB. The compilation might fail."
);
ini_set
(
'memory_limit'
,
$requiredMemory
);
if
(
ini_get
(
'memory_limit'
)
!=
$requiredMemory
)
{
showMessage
(
"WARNING: The program could not set the PHP memory limit to
$requiredMemory
. The compilation might fail."
);
if
((
$answer
=
ask
(
"Do you still want to continue?"
))
!=
'y'
)
{
if
((
$answer
=
ask
(
"Do you still want to continue?"
))
!=
'y'
)
{
quit
;
quit
;
}
}
...
@@ -173,25 +223,28 @@ if (ini_get('memory_limit') != '18M') {
...
@@ -173,25 +223,28 @@ if (ini_get('memory_limit') != '18M') {
showMessage
(
"PHP memory limit adjusted successfully."
);
showMessage
(
"PHP memory limit adjusted successfully."
);
}
}
// Build / 'Compile' Doctrine...
$target
=
'./Doctrine.compiled.php'
;
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$path
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
try
{
foreach
(
$it
as
$file
)
{
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$path
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
foreach
(
$it
as
$file
)
{
$e
=
explode
(
'.'
,
$file
->
getFileName
());
$e
=
explode
(
'.'
,
$file
->
getFileName
());
// we don't want to require versioning files
// We don't want to require versioning files, or cli files
if
(
end
(
$e
)
===
'php'
&&
strpos
(
$file
->
getFileName
(),
'.inc'
)
===
false
)
{
if
(
end
(
$e
)
===
'php'
&&
strpos
(
$file
->
getFileName
(),
'.inc'
)
===
false
&&
strpos
(
$file
->
getFileName
(),
'cli'
)
!==
0
)
{
require_once
$file
->
getPathName
();
require_once
$file
->
getPathName
();
}
}
}
}
$classes
=
array_merge
(
get_declared_classes
(),
get_declared_interfaces
());
$classes
=
array_merge
(
get_declared_classes
(),
get_declared_interfaces
());
$ret
=
array
();
$ret
=
array
();
foreach
(
$classes
as
$class
)
{
foreach
(
$classes
as
$class
)
{
$e
=
explode
(
'_'
,
$class
);
$e
=
explode
(
'_'
,
$class
);
if
(
$e
[
0
]
!==
'Doctrine'
)
{
if
(
$e
[
0
]
!==
'Doctrine'
)
{
...
@@ -199,6 +252,7 @@ foreach ($classes as $class) {
...
@@ -199,6 +252,7 @@ foreach ($classes as $class) {
}
}
// Skip excluded drivers
// Skip excluded drivers
$skipClass
=
false
;
$skipClass
=
false
;
foreach
(
$excludeDrivers
as
$excludeDriver
)
{
foreach
(
$excludeDrivers
as
$excludeDriver
)
{
if
(
in_array
(
$excludeDriver
,
$e
))
{
if
(
in_array
(
$excludeDriver
,
$e
))
{
...
@@ -222,31 +276,43 @@ foreach ($classes as $class) {
...
@@ -222,31 +276,43 @@ foreach ($classes as $class) {
$end
=
$refl
->
getEndLine
();
$end
=
$refl
->
getEndLine
();
$ret
=
array_merge
(
$ret
,
array_slice
(
$lines
,
$start
,
(
$end
-
$start
)));
$ret
=
array_merge
(
$ret
,
array_slice
(
$lines
,
$start
,
(
$end
-
$start
)));
}
}
if
(
$target
==
null
)
{
// first write the 'compiled' data to a text file, so
$target
=
$path
.
DIRECTORY_SEPARATOR
.
'Doctrine.compiled.php'
;
// that we can use php_strip_whitespace (which only works on files)
}
// first write the 'compiled' data to a text file, so
$fp
=
@
fopen
(
$target
,
'w'
);
// that we can use php_strip_whitespace (which only works on files)
$fp
=
@
fopen
(
$target
,
'w'
);
if
(
$fp
===
false
)
{
if
(
$fp
===
false
)
{
throw
new
Exception
(
"Couldn't write compiled data. Failed to open
$target
"
);
throw
new
Exception
(
"Couldn't write compiled data. Failed to open
$target
"
);
}
}
fwrite
(
$fp
,
"<?php "
.
implode
(
''
,
$ret
));
fwrite
(
$fp
,
"<?php "
.
implode
(
''
,
$ret
));
fclose
(
$fp
);
fclose
(
$fp
);
$stripped
=
php_strip_whitespace
(
$target
);
$stripped
=
php_strip_whitespace
(
$target
);
$fp
=
@
fopen
(
$target
,
'w'
);
$fp
=
@
fopen
(
$target
,
'w'
);
if
(
$fp
===
false
)
{
if
(
$fp
===
false
)
{
throw
new
Exception
(
"Couldn't write compiled data. Failed to open
$file
"
);
throw
new
Exception
(
"Couldn't write compiled data. Failed to open
$file
"
);
}
fwrite
(
$fp
,
$stripped
);
fclose
(
$fp
);
}
catch
(
Exception
$e
)
{
if
(
!
$showErrors
)
{
if
((
$answer
=
ask
(
"Sorry, an error occurred during the build. Would you like to see the error?"
))
==
'y'
)
{
showMessage
(
"
\n
$e
"
);
}
else
{
quit
();
}
}
showMessage
(
"
\n
Build Aborted."
);
exit
;
}
}
fwrite
(
$fp
,
$stripped
);
fclose
(
$fp
);
// Say bye...
// Say bye...
showMessage
(
"
\n
Compilation Finished."
);
showMessage
(
"
\n
Compilation Finished."
);
showMessage
(
"Thank you for using the interactive Doctrine Compiler. Have fun following the Doctrine :)
\n
"
);
showMessage
(
"Thank you for using the interactive Doctrine Compiler. Have fun following the Doctrine :)
\n
"
);
...
...
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