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
f54687fd
Commit
f54687fd
authored
Oct 15, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes to original compiler code to allow the exporting of certain drivers.
parent
4213e49d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
329 deletions
+41
-329
Doctrine.php
lib/Doctrine.php
+2
-2
Compiler.php
lib/Doctrine/Compiler.php
+35
-3
Facade.php
lib/Doctrine/Facade.php
+2
-2
Task.php
lib/Doctrine/Task.php
+2
-2
cli_compiler.php
sandbox/cli_compiler.php
+0
-320
No files found.
lib/Doctrine.php
View file @
f54687fd
...
...
@@ -533,9 +533,9 @@ final class Doctrine
* @throws Doctrine_Exception
* @return void
*/
public
static
function
compile
(
$target
=
null
)
public
static
function
compile
(
$target
=
null
,
$includedDrivers
=
array
()
)
{
return
Doctrine_Facade
::
compile
(
$target
);
return
Doctrine_Facade
::
compile
(
$target
,
$includedDrivers
);
}
/**
...
...
lib/Doctrine/Compiler.php
View file @
f54687fd
...
...
@@ -40,8 +40,28 @@ class Doctrine_Compiler
* @throws Doctrine_Compiler_Exception if something went wrong during the compile operation
* @return void
*/
public
static
function
compile
(
$target
=
null
)
public
static
function
compile
(
$target
=
null
,
$includedDrivers
=
array
()
)
{
if
(
!
is_array
(
$includedDrivers
))
{
$includedDrivers
=
array
(
$includedDrivers
);
}
$excludedDrivers
=
array
();
// If we have an array of specified drivers then lets determine which drivers we should exclude
if
(
!
empty
(
$includedDrivers
))
{
$drivers
=
array
(
'db2'
,
'firebird'
,
'informix'
,
'mssql'
,
'mysql'
,
'oracle'
,
'pgsql'
,
'sqlite'
);
$excludedDrivers
=
array_diff
(
$drivers
,
$includedDrivers
);
}
$path
=
Doctrine
::
getPath
();
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$path
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
...
...
@@ -64,11 +84,21 @@ class Doctrine_Compiler
if
(
$e
[
0
]
!==
'Doctrine'
)
{
continue
;
}
// Exclude drivers
if
(
!
empty
(
$excludedDrivers
))
{
foreach
(
$excludedDrivers
as
$excludedDriver
)
{
$excludedDriver
=
ucfirst
(
$excludedDriver
);
if
(
in_array
(
$excludedDriver
,
$e
))
{
continue
(
2
);
}
}
}
$refl
=
new
ReflectionClass
(
$class
);
$file
=
$refl
->
getFileName
();
print
'Adding '
.
$file
.
PHP_EOL
;
$lines
=
file
(
$file
);
$start
=
$refl
->
getStartLine
()
-
1
;
...
...
@@ -88,6 +118,7 @@ class Doctrine_Compiler
if
(
$fp
===
false
)
{
throw
new
Doctrine_Compiler_Exception
(
"Couldn't write compiled data. Failed to open
$target
"
);
}
fwrite
(
$fp
,
"<?php "
.
implode
(
''
,
$ret
));
fclose
(
$fp
);
...
...
@@ -96,6 +127,7 @@ class Doctrine_Compiler
if
(
$fp
===
false
)
{
throw
new
Doctrine_Compiler_Exception
(
"Couldn't write compiled data. Failed to open
$file
"
);
}
fwrite
(
$fp
,
$stripped
);
fclose
(
$fp
);
}
...
...
lib/Doctrine/Facade.php
View file @
f54687fd
...
...
@@ -416,8 +416,8 @@ class Doctrine_Facade
* @param string $target
* @return void
*/
public
static
function
compile
(
$target
=
null
)
public
static
function
compile
(
$target
=
null
,
$includedDrivers
=
array
()
)
{
return
Doctrine_Compiler
::
compile
(
$target
);
return
Doctrine_Compiler
::
compile
(
$target
,
$includedDrivers
);
}
}
\ No newline at end of file
lib/Doctrine/Task.php
View file @
f54687fd
...
...
@@ -99,9 +99,9 @@ abstract class Doctrine_Task
*/
public
function
getArgument
(
$name
,
$default
=
null
)
{
if
(
isset
(
$this
->
arguments
[
$name
]))
{
if
(
isset
(
$this
->
arguments
[
$name
])
&&
$this
->
arguments
[
$name
]
)
{
return
$this
->
arguments
[
$name
];
}
else
if
(
$default
)
{
}
else
{
return
$default
;
}
}
...
...
sandbox/cli_compiler.php
deleted
100755 → 0
View file @
4213e49d
#!/usr/bin/env php
<?php
chdir(dirname(__FILE__));
?>
Welcome to the interactive Doctrine Compiler 0.0.2 (Beta).
To see the available command-line options, run:
<?php
echo
$argv
[
0
];
?>
--help
<?php
if
(
in_array
(
$argv
[
1
],
array
(
'--help'
,
'-help'
,
'-h'
,
'-?'
)))
{
?>
Usage:
<?php
echo
$argv
[
0
];
?>
[path]
[path] is the path to Doctrine's lib directory. This
is normally the directory containing the core
Doctrine class, 'Doctrine.php'.
While the program is running:
Default responses to questions are capitalized. Just
hit enter to provide a question's default response.
You can quit the program at any time by pressing 'q'.
<?php
exit
;
}
function
addIncludePath
(
$path
)
{
set_include_path
(
$path
.
PATH_SEPARATOR
.
get_include_path
()
);
}
function
showMessage
(
$message
)
{
echo
"
\n
$message
\n
"
;
}
function
quit
(
$message
=
'Program Aborted.'
)
{
if
(
$message
)
{
showMessage
(
$message
);
}
exit
;
}
function
autoQuit
(
$answer
)
{
if
(
trim
(
strtolower
(
$answer
))
==
'q'
)
{
quit
();
}
}
function
ask
(
$question
,
$defaultOption
=
'y'
,
$displayOptions
=
array
(
'yes'
,
'no'
,
'quit'
),
$autoValidate
=
true
)
{
$prompt
=
"
\n
$question
"
;
if
(
$displayOptions
)
{
$optionCount
=
count
(
$displayOptions
);
if
(
$defaultOption
)
{
for
(
$i
=
0
;
$i
<
$optionCount
;
$i
++
)
{
if
(
$displayOptions
[
$i
][
0
]
==
$defaultOption
)
{
$displayOptions
[
$i
]
=
ucfirst
(
$displayOptions
[
$i
]);
break
;
}
}
}
if
(
$autoValidate
)
{
for
(
$i
=
0
;
$i
<
$optionCount
;
$i
++
)
{
$validation
[]
=
strtolower
(
$displayOptions
[
$i
][
0
]);
}
}
$prompt
.=
"
\n
["
.
implode
(
'/'
,
$displayOptions
)
.
"] "
;
}
$done
=
false
;
while
(
!
$done
)
{
echo
$prompt
;
$input
=
trim
(
fgets
(
STDIN
));
if
(
!
$input
&&
$defaultOption
)
{
$input
=
$defaultOption
;
}
if
(
isset
(
$validation
))
{
if
(
$input
)
{
$input
=
strtolower
(
$input
[
0
]);
}
if
(
array_search
(
$input
,
$validation
)
!==
false
)
{
return
$input
;
}
else
{
echo
"
\n
"
.
'The answer "'
.
$input
.
'" is invalid. It must be one of "'
.
implode
(
'", "'
,
$validation
)
.
'".'
.
"
\n
"
;
}
}
else
{
return
$input
;
}
}
}
// Enable error reporting
if
((
$answer
=
ask
(
"Would you like to turn on error reporting?"
,
'n'
))
==
'y'
)
{
error_reporting
(
E_ALL
);
$showErrors
=
true
;
}
else
{
error_reporting
(
0
);
$showErrors
=
false
;
}
autoQuit
(
$answer
);
// Process library path command line argument
if
(
$argc
>
1
)
{
$doctrinePath
=
$argv
[
1
];
}
else
{
$doctrinePath
=
dirname
(
__FILE__
);
}
// Get Doctrine's library path
$usablePath
=
false
;
while
(
!
$usablePath
)
{
$path
=
ask
(
"Please enter the path to Doctrine's lib directory:"
,
$doctrinePath
,
array
(
$doctrinePath
),
false
);
autoQuit
(
$path
);
try
{
addIncludePath
(
$path
);
include_once
'Doctrine.php'
;
spl_autoload_register
(
array
(
'Doctrine'
,
'autoload'
));
$usablePath
=
true
;
}
catch
(
Exception
$e
)
{
showMessage
(
"The path '
$path
' does not seem to contain the expected Doctrine class ('Doctrine.php')."
);
if
((
$answer
=
ask
(
"Would you like to specify another path?"
))
!=
'y'
)
{
quit
();
}
}
}
// 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
();
$excludeDrivers
=
array
();
// Determine driver support
foreach
(
$drivers
as
$driver
)
{
if
((
$answer
=
ask
(
"Would you like to enable support for
$driver
?"
))
==
'y'
)
{
$includeDrivers
[]
=
$driver
;
}
else
{
$excludeDrivers
[]
=
$driver
;
}
autoQuit
(
$answer
);
}
// Verify driver support
if
(
!
count
(
$includeDrivers
))
{
showMessage
(
"You have not selected any drivers. Usually 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'
)
{
quit
();
}
autoQuit
(
$answer
);
}
// Try to prevent errors related to memory allocation
$requiredMemory
=
'32M'
;
showMessage
(
"Trying to set the PHP memory limit to
$requiredMemory
..."
);
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'
)
{
quit
;
}
}
else
{
showMessage
(
"PHP memory limit adjusted successfully."
);
}
// Build / 'Compile' Doctrine...
try
{
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$path
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
foreach
(
$it
as
$file
)
{
$e
=
explode
(
'.'
,
$file
->
getFileName
());
// We don't want to require versioning files, or cli files
if
(
end
(
$e
)
===
'php'
&&
strpos
(
$file
->
getFileName
(),
'.inc'
)
===
false
&&
strpos
(
$file
->
getFileName
(),
'cli'
)
!==
0
)
{
require_once
$file
->
getPathName
();
}
}
$classes
=
array_merge
(
get_declared_classes
(),
get_declared_interfaces
());
$ret
=
array
();
foreach
(
$classes
as
$class
)
{
$e
=
explode
(
'_'
,
$class
);
if
(
$e
[
0
]
!==
'Doctrine'
)
{
continue
;
}
// Skip excluded drivers
$skipClass
=
false
;
foreach
(
$excludeDrivers
as
$excludeDriver
)
{
if
(
in_array
(
$excludeDriver
,
$e
))
{
$skipClass
=
true
;
break
;
}
}
if
(
$skipClass
)
{
echo
"
\n
Excluding ->
$class
"
;
continue
;
}
$refl
=
new
ReflectionClass
(
$class
);
$file
=
$refl
->
getFileName
();
echo
"
\n
Including ->
$file
"
;
$lines
=
file
(
$file
);
$start
=
$refl
->
getStartLine
()
-
1
;
$end
=
$refl
->
getEndLine
();
$ret
=
array_merge
(
$ret
,
array_slice
(
$lines
,
$start
,
(
$end
-
$start
)));
}
// first write the 'compiled' data to a text file, so
// that we can use php_strip_whitespace (which only works on files)
$fp
=
@
fopen
(
$target
,
'w'
);
if
(
$fp
===
false
)
{
throw
new
Exception
(
"Couldn't write compiled data. Failed to open
$target
"
);
}
fwrite
(
$fp
,
"<?php "
.
implode
(
''
,
$ret
));
fclose
(
$fp
);
$stripped
=
php_strip_whitespace
(
$target
);
$fp
=
@
fopen
(
$target
,
'w'
);
if
(
$fp
===
false
)
{
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
;
}
// Say bye...
showMessage
(
"
\n
Compilation Finished."
);
showMessage
(
"Thank you for using the interactive Doctrine Compiler. Have fun following the Doctrine :)
\n
"
);
?>
\ 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